The Autonomous Account Risk Circuit Breaker & Tilt Guardrail Engine (RiskCircuitBreakerService) provides automated, capital-preserving protection against emotional trading, revenge trading (“tilt”), unexpected intraday portfolio volatility, and margin compression.
Unlike passive alerts, the risk circuit breaker actively locks order execution within order entry views (such as TradeOptionWidget) when user-defined safety boundaries are breached, and enforces a mandatory cooling-off period before trading may resume.
RiskCircuitBreakerConfig)peakPortfolioEquity), triggering a trip if current equity falls below the threshold (e.g. 5%–30%).enableTiltSafeguards)rapidCancelWindowMinutes, default 5m). If cancellations or replacements reach maxRapidCancels (default 4), execution is halted with trigger type rapid_cancels to break emotional thrashing.baselineTradeSize) across the last 10 executions. If a trader experiences consecutive losses (currentConsecutiveLosses > 0) and attempts to submit an order exceeding revengeSizingMultiplier (default 2.5x) times baseline, the order is blocked with trigger type revenge_sizing.PortfolioAlertService warns traders when rapid cancellations approach the limit (risk-tilt-rapid-cancels-near) or when loss streaks elevate revenge trading tilt risk (risk-tilt-revenge-trading-risk).TradeOptionWidget._placeOrder():
config.isExecutionBlocked.evaluateOrderSize() to block revenge-trading sizing spikes following losses.risk_guard_override / circuit_breaker_blocked).OptionOrderWidget and PositionOrderWidget trigger recordOrderCancelledOrReplaced() to detect rapid thrashing loops.PortfolioAlertService.evaluateAlerts():
circuit-breaker-tripped / cooling-off): Surfaces prominently when trading is locked or cooling off, displaying the exact cause and end time.circuit-breaker-near-limit): Alerts the user when daily losses cross 80% of their configured threshold.risk-tilt-rapid-cancels-near): Alerts the user when cancellations in the last 5 minutes are within 1 of tripping the cooling-off lock.risk-tilt-revenge-trading-risk): Alerts the user after consecutive losses to adhere to disciplined position sizing.RiskCircuitBreakerSettingsWidget)UserWidget) > Risk Circuit Breakers & Tilt Guardrails.RiskCircuitBreakerConfigclass RiskCircuitBreakerConfig {
final bool enabled;
final double? maxDailyLossAmount;
final double? maxDailyLossPercent;
final double? maxDrawdownPercent;
final int? maxConsecutiveLosses;
final double? minMarginBufferPercent;
final int coolingOffDurationMinutes;
final DateTime? coolingOffUntil;
final bool isTripped;
final String? tripReason;
final double? peakPortfolioEquity;
final int currentConsecutiveLosses;
final bool enableTiltSafeguards;
final int? maxRapidCancels;
final int rapidCancelWindowMinutes;
final double? revengeSizingMultiplier;
final double? baselineTradeSize;
final List<DateTime> recentCancelTimestamps;
final List<double> recentTradeSizes;
bool get isInCoolingOff => coolingOffUntil != null && DateTime.now().isBefore(coolingOffUntil!);
bool get isExecutionBlocked => enabled && (isTripped || isInCoolingOff);
int get activeRapidCancelCount => ...;
}
test/risk_circuit_breaker_test.dart covers serialization, threshold calculations, drawdown tracking, consecutive losses, rapid cancel loop detection, revenge sizing spike evaluation, and PortfolioAlertService alerts.test/risk_circuit_breaker_widget_test.dart verifies toggle switches, chip selectors, sliders, status cards, simulation buttons, and reset dialogs.