Docs Download
Home / Docs / What is Emergency Close in the decision engine?

What is Emergency Close in the decision engine?

Emergency Close is a critical safety feature in MagicTradeBot’s Intelligent Decision-Making Engine that automatically closes trades during extreme market movements to protect your capital. It acts like a “panic button” when market conditions suddenly turn against your positions.


🧠 How It Works

  1. Activation

    • Controlled via the EmergencyClose flag in decision_engine.yaml:
EmergencyClose: false   # Set to true to enable automatic emergency trade closure
  • When enabled, all trades flagged for emergency closure are automatically closed when the market triggers the emergency conditions.

  • Emergency Threshold

    • Defined in market_watch.yaml using AverageMovementEmergencyClose:
AverageMovementEmergencyClose: 0.6  # % opposite movement to trigger emergency close
  • Example:

    • Crash scenario: Average movement of tracked symbols drops 0.6% downward, marking all long trades with emergency_close = true
    • Pump scenario: Average movement spikes upward by 0.6%, marking all short trades with emergency_close = true
  • Minimum Hold Time

    • To avoid prematurely closing recently opened trades, EmergencyCloseMinHoldTime ensures trades are only closed if they have been open longer than a defined duration:
EmergencyCloseMinHoldTime: 20  # minutes
  • Trades younger than this threshold are ignored, preventing unnecessary exits from short-lived volatility immediately after entry.

  • Execution Flow

    • Trade is flagged with emergency_close = true when the threshold is met
    • Decision engine checks the trade age
    • If age > EmergencyCloseMinHoldTime, the trade is closed immediately
    • If age < EmergencyCloseMinHoldTime, the trade remains open until the minimum time is reached

🔑 Key Points

  • Purpose: Protects your account from rapid market crashes or pumps
  • Scope: Can close longs during crashes or shorts during pumps
  • Safety Mechanism: Minimum hold time prevents premature exits on recent trades
  • Automation: No manual intervention needed; the engine handles emergency closures 24/7

In short, Emergency Close is a proactive risk-management tool that ensures your positions are automatically exited during sharp market reversals, locking in profits or limiting losses without requiring constant monitoring.

Ready to trade? Download MagicTradeBot free and test in paper mode before going live.