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
- Navigate to Dashboard → Trading Bots
- Click on your bot
- Go to Settings → Risk Management
Configuration Options
| Setting | Description | Recommended |
|---|---|---|
| Max Daily Loss % | Maximum loss per day | 2-5% |
| Max Weekly Loss % | Maximum loss per week | 5-10% |
| Max Drawdown % | Maximum peak-to-trough decline | 10-20% |
| Max Consecutive Losses | Pause after X losses in a row | 3-5 |
| Pause on Breach | Auto-pause when limit hit | ✓ Enabled |
| Notify on Breach | Send 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:
- At midnight UTC, daily P&L resets to $0
- Each trade updates daily P&L
- 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:
- Resets every Monday at midnight UTC
- Accumulates across all trading days
- 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:
- Counter starts at 0
- Each losing trade: counter + 1
- Each winning trade: counter resets to 0
- 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:
- Bot immediately stops executing new trades
- Open positions are NOT automatically closed
- Bot status changes to "Paused - Risk Breach"
- 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:
- Navigate to bot dashboard
- Review the breach reason
- Assess current positions
- Click Resume Bot
- 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:
| Setting | Conservative | Moderate | Aggressive |
|---|---|---|---|
| Daily Loss | 1-2% | 2-3% | 3-5% |
| Weekly Loss | 3-5% | 5-7% | 7-10% |
| Drawdown | 5-10% | 10-15% | 15-25% |
| Consecutive | 3 | 4-5 | 5-7 |
2. Match Risk to Strategy
| Strategy Type | Daily Loss | Drawdown | Consecutive |
|---|---|---|---|
| Scalping | 1-2% | 5% | 5-7 |
| Day Trading | 2-3% | 10% | 4-5 |
| Swing Trading | 3-5% | 15% | 3-4 |
| Trend Following | 5%+ | 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:
- Analyze what caused the breach
- Was it normal market volatility?
- Was it a strategy flaw?
- 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
| Level | Trigger | Action |
|---|---|---|
| Info | 50% of limit used | Dashboard notification |
| Warning | 75% of limit used | Email + Telegram |
| Critical | 100% (breach) | All channels + auto-pause |
Configuring Alerts
- Go to Settings → Notifications
- Connect notification channels (Email, Telegram)
- Enable "Risk Alerts"
- 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
- Order Types - Use stops and brackets
- Monitoring - Track performance
- Alerts & Notifications - Configure alerts
- Backtesting - Test risk settings