Skip to main content
Risk controls ensure the trading system operates within safe parameters, preventing excessive losses and maintaining portfolio health through position sizing, exposure limits, and validation checks.

Risk Management Layers

1

Position Sizing

Calculate safe position sizes based on portfolio value and risk per trade
2

Exposure Limits

Enforce maximum position sizes and concentration limits per symbol
3

Cash Validation

Verify sufficient available cash before opening positions
4

Stop-Loss Requirements

Require stop-loss levels for all positions to limit downside
5

Cooldown Periods

Prevent rapid re-entry after closing losing positions

Position Sizing

Position sizing determines how much capital to allocate to each trade based on portfolio value and risk tolerance.

Risk-Based Sizing

Calculate position size based on risk per trade as a percentage of portfolio value.
Example:
  • Portfolio: $10,000
  • Risk per trade: 2% ($200)
  • Entry: $50,000
  • Stop-loss: $48,000
  • Price risk: $2,000 per BTC
  • Position size: 200/200 / 2,000 = 0.1 BTC
This ensures that if the stop-loss is hit, the maximum loss is exactly 2% of portfolio value, regardless of the distance to the stop.

Fixed Percentage Sizing

Allocate a fixed percentage of portfolio value to each position.
Example:
  • Portfolio: $10,000
  • Allocation: 10%
  • Entry: $50,000
  • Notional: $1,000
  • Position size: 1,000/1,000 / 50,000 = 0.02 BTC
Fixed percentage sizing can lead to large losses if stops are wide. Risk-based sizing is generally safer.

Kelly Criterion

Optimal position sizing based on historical win rate and average win/loss ratio.
Example:
  • Win rate: 60% (0.6)
  • Average win: $300
  • Average loss: $150
  • Win/loss ratio: 2.0
  • Kelly %: (0.6 × 2.0 - 0.4) / 2.0 = 40%
Kelly Criterion can suggest aggressive position sizes. Many traders use fractional Kelly (e.g., half Kelly) for more conservative sizing.

Exposure Limits

Exposure limits prevent over-concentration in any single asset or direction.

Per-Symbol Limits

Restrict maximum position size per symbol as a percentage of portfolio value.

Directional Limits

Limit total exposure in one direction (LONG or SHORT) across all positions.

Correlation Limits

Prevent over-concentration in correlated assets (e.g., multiple altcoins).
Correlation limits are not currently implemented but are recommended for production systems. Track asset correlations and limit total exposure to highly correlated instruments.

Cash Validation

Before opening a position, the system verifies sufficient available cash considering existing positions and margin requirements.
Location: src/server/features/simulator/accountState.ts Available Cash Calculation:
Where:
  • totalCash: Initial capital + realized P&L
  • totalUnrealizedPnl: Sum of unrealized P&L across all positions
  • totalMarginUsed: Sum of margin reserved for open positions
Margin Used (per position):
Example:
  • Initial capital: $10,000
  • Realized P&L: +$500
  • Unrealized P&L: +$200 (from open positions)
  • Margin used: $3,000 (3 positions with 3x leverage)
  • Available cash: 10,000+10,000 + 500 + 200−200 - 3,000 = $7,700
The system rejects orders that would exceed available cash to prevent over-leveraging and forced liquidations.

Stop-Loss Requirements

All positions should have a stop-loss level defined in the exit plan to limit downside risk.

Mandatory Stops

While the system doesn’t enforce mandatory stop-losses (to allow flexibility), best practices recommend requiring stops for all positions.

Risk-Reward Ratio

Calculate and validate risk-reward ratios before opening positions.
Example (LONG):
  • Entry: $50,000
  • Stop: 48,000(risk:48,000 (risk: 2,000)
  • Target: 56,000(reward:56,000 (reward: 6,000)
  • Risk-Reward: 6,000/6,000 / 2,000 = 3:1
A minimum risk-reward ratio of 2:1 or 3:1 is recommended to ensure winners outweigh losers over time.

Cooldown Periods

Cooldown periods prevent rapid re-entry into the same symbol after a stop-loss, reducing emotional trading and overtrading.

Setting Cooldowns

Cooldowns are stored in the exitPlan.cooldownUntil field when a position is closed via stop-loss.

Enforcing Cooldowns

Check cooldown status before opening new positions.
Cooldowns help prevent revenge trading and give time for market conditions to stabilize after a loss.

Session-Based Limits

Session-based limits prevent excessive activity within a single trading cycle.

Action Count Limits

Limit the number of actions (opens/closes) per symbol per session.
Location: src/server/features/trading/tradeExecutor.ts:110

Flip Prevention

Prevent flipping from LONG to SHORT (or vice versa) on the same symbol within a single session.
Flip prevention reduces whipsaw losses from rapidly reversing positions based on short-term price movements.

Risk Metrics

Track portfolio-level risk metrics to monitor overall health.

Maximum Drawdown

Track the largest peak-to-trough decline in portfolio value.
Example:
  • Peak: $12,000
  • Trough: $9,000
  • Drawdown: (12,000−12,000 - 9,000) / $12,000 = 25%

Current Drawdown

Calculate current drawdown from recent peak.
If current drawdown exceeds a threshold (e.g., 20%), consider reducing position sizes or pausing trading until conditions improve.

Sharpe Ratio

Measure risk-adjusted returns.
Interpretation:
  • Sharpe > 1.0: Good risk-adjusted returns
  • Sharpe > 2.0: Excellent risk-adjusted returns
  • Sharpe < 0: Losing money on a risk-adjusted basis

Best Practices

Risk Per Trade

Limit risk per trade to 1-2% of portfolio value. This ensures you can withstand multiple consecutive losses without significant drawdown.

Diversification

Don’t put all capital in one symbol. Spread risk across multiple uncorrelated assets.

Stop-Loss Always

Every position should have a predefined stop-loss. Never let losses run indefinitely.

Monitor Drawdown

Track current and maximum drawdown. Reduce position sizes during drawdown periods.

Next Steps

Position Management

Learn about position tracking and exit plans

Portfolio Analytics

Explore performance metrics and analytics