Risk Management

TradeStaq includes a comprehensive risk management system that automatically monitors and enforces trading limits. This guide explains how to configure and use risk controls to protect your capital.

Overview

The risk management system provides:

  • Daily/Weekly Loss Limits - Maximum loss per period
  • Maximum Drawdown - Peak-to-trough limit
  • Consecutive Loss Limits - Pause after losing streaks
  • Auto-Pause - Automatic bot stopping on breach
  • Notifications - Alerts when limits are approached or breached

Risk Configuration

Accessing Risk Settings

  1. Navigate to Dashboard → Trading Bots
  2. Click on your bot
  3. Go to Settings → Risk Management

Configuration Options

SettingDescriptionRecommended
Max Daily Loss %Maximum loss per day2-5%
Max Weekly Loss %Maximum loss per week5-10%
Max Drawdown %Maximum peak-to-trough decline10-20%
Max Consecutive LossesPause after X losses in a row3-5
Pause on BreachAuto-pause when limit hit✓ Enabled
Notify on BreachSend alerts on limit hit✓ Enabled

Example Configuration

{
    "maxDailyLossPercent": 3,
    "maxWeeklyLossPercent": 7,
    "maxDrawdownPercent": 15,
    "maxConsecutiveLosses": 4,
    "pauseOnBreach": true,
    "notifyOnBreach": true
}

Understanding Risk Limits

Daily Loss Limit

Tracks profit/loss from midnight UTC each day.

How it works:

  1. At midnight UTC, daily P&L resets to $0
  2. Each trade updates daily P&L
  3. When daily loss % exceeds limit, action taken

Example:

  • Starting balance: $10,000
  • Max daily loss: 3%
  • Trigger: When daily losses reach $300
Day starts:    Daily P&L = $0
Trade 1:       -$100  → Daily P&L = -$100 (1%)
Trade 2:       -$150  → Daily P&L = -$250 (2.5%)
Trade 3:       -$75   → Daily P&L = -$325 (3.25%) ⚠️ BREACHED

Weekly Loss Limit

Tracks profit/loss from Monday midnight UTC.

How it works:

  1. Resets every Monday at midnight UTC
  2. Accumulates across all trading days
  3. Independent of daily limit

Example:

  • Starting balance: $10,000
  • Max weekly loss: 7%
  • Trigger: When weekly losses reach $700

Maximum Drawdown

Measures decline from your highest equity point.

How it works:

┌────────────────────────────────────────────────────────────┐
│    DRAWDOWN VISUALIZATION                                   │
│                                                             │
│    $12,000 ──────────────────────────────────────────────  │
│              ╱╲     Peak Equity ($12,000)                  │
│             ╱  ╲                                           │
│            ╱    ╲                                          │
│    $11,000      ╲────────────────────────────────────────  │
│                  ╲                                         │
│                   ╲                                        │
│    $10,200 ────────╲─────────────────────────────────────  │
│                     ╲  Current Equity ($10,200)           │
│                      ╲                                     │
│                       Drawdown = $1,800 (15%)              │
└────────────────────────────────────────────────────────────┘

Calculation:

Drawdown = (Peak Equity - Current Equity) / Peak Equity × 100

Example:
Peak Equity = $12,000
Current Equity = $10,200
Drawdown = ($12,000 - $10,200) / $12,000 = 15%

Consecutive Losses

Counts losses in a row without a winning trade.

How it works:

  1. Counter starts at 0
  2. Each losing trade: counter + 1
  3. Each winning trade: counter resets to 0
  4. When counter reaches limit, action taken

Example:

  • Max consecutive losses: 4
  • Trade history: Win, Loss, Loss, Loss, Loss → BREACHED

Risk Actions

Auto-Pause

When a limit is breached with pauseOnBreach: true:

  1. Bot immediately stops executing new trades
  2. Open positions are NOT automatically closed
  3. Bot status changes to "Paused - Risk Breach"
  4. Manual intervention required to resume

Notifications

When notifyOnBreach: true:

  • Email notification sent (if configured)
  • Telegram alert sent (if configured)
  • Dashboard notification appears
  • Details include which limit was breached

Manual Resume

To resume a paused bot:

  1. Navigate to bot dashboard
  2. Review the breach reason
  3. Assess current positions
  4. Click Resume Bot
  5. Optionally adjust risk settings first

Risk State Tracking

The system maintains a real-time risk state:

interface RiskState {
    // Daily tracking
    dailyPnL: number;
    dailyStartBalance: number;
    lastResetDate: string;

    // Weekly tracking
    weeklyPnL: number;
    weeklyStartBalance: number;
    lastWeekResetDate: string;

    // Drawdown tracking
    currentDrawdown: number;
    currentDrawdownPercent: number;
    peakEquity: number;

    // Streak tracking
    consecutiveLosses: number;
    consecutiveWins: number;
    lastTradeWin: boolean;

    // Pause state
    isPaused: boolean;
    pauseReason?: string;
    pausedAt?: Date;
}

Viewing Risk State

Access via bot dashboard or API:

GET /api/tradedroid/bots/{botId}/risk

Response:

{
    "success": true,
    "data": {
        "dailyPnL": -125.50,
        "dailyPnLPercent": -1.26,
        "weeklyPnL": -312.00,
        "weeklyPnLPercent": -3.12,
        "drawdownPercent": 4.5,
        "consecutiveLosses": 2,
        "isPaused": false,
        "limits": {
            "dailyLimitUsed": 42,
            "weeklyLimitUsed": 44,
            "drawdownLimitUsed": 30,
            "consecutiveLimitUsed": 50
        }
    }
}

Best Practices

1. Start Conservative

For new bots or strategies:

SettingConservativeModerateAggressive
Daily Loss1-2%2-3%3-5%
Weekly Loss3-5%5-7%7-10%
Drawdown5-10%10-15%15-25%
Consecutive34-55-7

2. Match Risk to Strategy

Strategy TypeDaily LossDrawdownConsecutive
Scalping1-2%5%5-7
Day Trading2-3%10%4-5
Swing Trading3-5%15%3-4
Trend Following5%+20%+3-4

3. Always Enable Auto-Pause

Critical for:

  • Protecting against strategy bugs
  • Limiting damage in adverse markets
  • Preventing emotional overtrading

4. Set Realistic Limits

Too tight limits cause:

  • Frequent bot pauses
  • Missed opportunities
  • Frustration

Too loose limits cause:

  • Excessive losses
  • Account damage
  • Emotional trading

5. Review and Adjust

After each breach:

  1. Analyze what caused the breach
  2. Was it normal market volatility?
  3. Was it a strategy flaw?
  4. Adjust limits or strategy accordingly

Position-Level Risk Management

In addition to bot-level limits, use position-level controls:

Stop Loss on Every Trade

// Always set stop loss
td.trade.longBracket({
    size: td.config.positionSize,
    stopLoss: entryPrice * (1 - stopLossPercent / 100),
    takeProfit: entryPrice * (1 + takeProfitPercent / 100),
});

Position Sizing Based on Risk

// Risk-based position sizing
const riskAmount = accountBalance * (riskPerTradePercent / 100);
const stopLossDistance = entryPrice - stopLossPrice;
const positionSize = riskAmount / stopLossDistance;

td.trade.long({ size: positionSize });

Maximum Position Size

Configure in bot settings:

{
    "maxPositionSize": 1.0,       // Max BTC per position
    "maxPositionPercent": 25      // Max 25% of balance per position
}

Risk Alerts

Alert Levels

LevelTriggerAction
Info50% of limit usedDashboard notification
Warning75% of limit usedEmail + Telegram
Critical100% (breach)All channels + auto-pause

Configuring Alerts

  1. Go to Settings → Notifications
  2. Connect notification channels (Email, Telegram)
  3. Enable "Risk Alerts"
  4. Set alert thresholds

Alert Message Example

⚠️ RISK ALERT - MyBTCBot

Daily Loss Limit Breached!
━━━━━━━━━━━━━━━━━━━━━━━━
Daily P&L: -$312.50 (-3.12%)
Limit: 3%
Status: Bot Paused

Current Positions:
• BTC/USDT Long: 0.1 BTC @ $50,000

Action Required: Review and resume bot.

Risk Metrics Dashboard

The bot dashboard shows real-time risk metrics:

┌─────────────────────────────────────────────────────────────┐
│                    RISK METRICS                              │
├─────────────────────────────────────────────────────────────┤
│                                                              │
│  Daily Loss        ████████░░░░░░░░░░░░  42% of 3% limit    │
│  Weekly Loss       ████████░░░░░░░░░░░░  44% of 7% limit    │
│  Max Drawdown      ██████░░░░░░░░░░░░░░  30% of 15% limit   │
│  Consecutive       ██████████░░░░░░░░░░  50% (2 of 4)       │
│                                                              │
│  Status: ● Active                                            │
│  Peak Equity: $12,000                                        │
│  Current Equity: $11,460                                     │
│                                                              │
└─────────────────────────────────────────────────────────────┘

Troubleshooting

Bot Keeps Pausing Too Often

Causes:

  • Limits too tight for strategy
  • High volatility market
  • Strategy generating many small losses

Solutions:

  • Review and widen limits
  • Add filters to reduce trade frequency
  • Improve win rate or risk/reward

Drawdown Not Resetting

Note: Drawdown only resets when you make a new equity high. It's designed this way to track maximum decline from peak.

Risk State Shows Wrong Values

Solutions:

  • Force sync: Click "Sync" on bot dashboard
  • Check timezone (resets use UTC)
  • Contact support if persists

Want to Disable Risk Management

Warning: Not recommended, but possible:

Set all limits to undefined or very high values:

{
    "maxDailyLossPercent": undefined,
    "maxWeeklyLossPercent": undefined,
    "maxDrawdownPercent": undefined,
    "maxConsecutiveLosses": undefined,
    "pauseOnBreach": false
}

API Reference

Get Risk State

GET /api/tradedroid/bots/{botId}/risk

Update Risk Config

PATCH /api/tradedroid/bots/{botId}
Content-Type: application/json

{
    "riskConfig": {
        "maxDailyLossPercent": 3,
        "maxWeeklyLossPercent": 7,
        "pauseOnBreach": true
    }
}

Resume Paused Bot

POST /api/tradedroid/bots/{botId}/resume

Next Steps