Freqtrade Tail-Risk Circuit Breaker: Preventing Algorithmic Revenge Trading
Freqtrade is great for backtesting indicators, but when consecutive regime changes hit crypto markets, retail bots repeatedly re-enter losing positions until margin call. Here is how institutional quant desks implement hard peak-to-trough equity circuit breakers.
1. Peak-to-Trough Drawdown Circuit Breaker Math
Let Peak Equity be E_max = max_{t}(E_t). Current Drawdown is DD_t = (E_max - E_t) / E_max. If DD_t >= DD_threshold (e.g. 15%), the risk daemon triggers an emergency halt: cancels all open orders, closes active positions at market, and forces a mandatory 24-hour algorithmic cooling-off period.
Python: Zero-Dependency Equity Drawdown Circuit Breaker Daemon
class EquityCircuitBreaker:
def __init__(self, max_allowed_drawdown_pct: float = 0.15, floor_equity: float = 57.88):
self.max_dd = max_allowed_drawdown_pct
self.floor_equity = floor_equity
self.peak_equity = 0.0
def evaluate(self, current_equity: float):
if current_equity > self.peak_equity:
self.peak_equity = current_equity
current_dd = (self.peak_equity - current_equity) / self.peak_equity
# Absolute dollar circuit breaker
if current_equity <= self.floor_equity:
return {"action": "EMERGENCY_HALT", "reason": f"Floor breached: ${current_equity} <= ${self.floor_equity}"}
# Drawdown circuit breaker
if current_dd >= self.max_dd:
return {"action": "COOLING_OFF_HALT", "reason": f"Max DD hit: {current_dd*100:.1f}%"}
return {"action": "CONTINUE", "dd_pct": current_dd}
Frequently Asked Questions
Can Freqtrade recover automatically after a circuit breaker trip?
No, and it shouldn't. An institutional circuit breaker requires manual human sign-off and root cause analysis before strategy execution can be resumed. Automated restarts after severe drawdowns invariably compound losses.
Deploy Institutional-Grade Capital Protection on Binance Futures
AegisQuant runs locally on your VPS with automated exchange-level hard stops, ATR risk-capped sizing, and peak-to-trough equity circuit breakers.
- Exchange-Native Hard Stop Sync: Auto-heals missing stops on Binance matching engine
- Equity Drawdown Circuit Breaker: Mandatory cooling-off halts on consecutive drawdowns
- Zero SaaS Dependencies: 100% Python, self-hosted, your keys stay on your server