Skip to content
__________________
V.1.0.0 // SECURE CONNECTION
Return_to_vault
[CONSTRUCT: 2026-01-20]

Daily Drawdown Protection

TradingRisk ManagementPython

Daily Drawdown Protection

A circuit breaker for your trading account. Once you hit a daily loss threshold (default 2%), this class flips a flag and refuses to let you trade until midnight UTC resets the counter. No override, no "just one more trade." The whole point is that it takes the decision out of your hands when you're in the red and thinking emotionally.

When to Use

  • Any automated or semi-automated trading system that needs hard risk limits
  • Enforcing daily drawdown discipline when manual willpower isn't enough
  • Position sizing pipelines where you need a kill switch before order submission

The Code

from datetime import datetime

class DailyRiskMonitor:
    """
    Halt trading if losses exceed threshold (default 2%).
    Resets at midnight UTC.
    """
    def __init__(self, starting_equity: float, limit_percent: float = 2.0):
        self.starting_equity = starting_equity
        self.limit = limit_percent
        self.last_reset = datetime.now().date()
        self.is_halted = False

    def check_drawdown(self, current_equity: float) -> bool:
        # Reset at midnight
        if datetime.now().date() > self.last_reset:
            self.starting_equity = current_equity
            self.last_reset = datetime.now().date()
            self.is_halted = False

        drawdown = (self.starting_equity - current_equity) / self.starting_equity * 100
        
        if drawdown >= self.limit:
            self.is_halted = True
            
        return not self.is_halted  # True = safe to trade

Notes

The 2% default is conservative. Adjust the threshold to match your risk tolerance, but don't set it above 5% unless you enjoy pain. The midnight UTC reset means your trading day aligns with the forex session calendar, not your local timezone.

Share

"End of transmission."

[CLOSE_CONSTRUCT]