On the MQL5 side, you wrap your execution logic with a fast validation check. Because memory reads are incredibly cheap, the EA can safely poll this variable on every single OnTick() or right before building the MqlTradeRequest struct.
Code: Select all
//+------------------------------------------------------------------+
//| Function to check the Python kill switch |
//+------------------------------------------------------------------+
bool IsCircuitBreakerTripped()
{
string switch_name = "GLOBAL_KILL_SWITCH";
// Check if the variable exists and equals 1.0
if(GlobalVariableCheck(switch_name))
{
double is_halted = GlobalVariableGet(switch_name);
if(is_halted == 1.0)
{
return true; // Breaker is tripped, halt trading
}
}
// Variable doesn't exist or is set to 0.0, safe to trade
return false;
}
//+------------------------------------------------------------------+
//| Main Tick Function |
//+------------------------------------------------------------------+
void OnTick()
{
// 1. Hard execution gate
if(IsCircuitBreakerTripped())
{
// Optional: Add logic to manage/close existing open positions
// even while rejecting new entries.
Comment("TRADING HALTED: Python Circuit Breaker Active");
return;
}
Comment(""); // Clear halt message
// 2. Your standard signal generation and execution logic follows...
// ...
}