Enable trade and disable from code

 

 Dear sirs,

  please look following and if can advice me :

  I shall want to stop and enable trade from code:

  extern bool trademode=true;

   if(trademode)    // option to enable trading through if statement
 {
 OrderSend...
 }
              // option to stop trading which shall be ?
  if(!IsStopped)
 return ??? 
  I want if enable stop to not trade anymore. Thank you.


  

 

I think you need a global variable (global within the MetaTrader that can be read from all EAs) and then a button that switches the variable on and off.

void SwitchTradingOn() {
  GlobalVariableSet("TradingOn",1);
}

void SwitchTradingOff() {
  GlobalVariableSet("TradingOn",0);
}

bool IsTradingAllowed() {
  return GlobalVariableGet("TradingOn")==1;
}


https://docs.mql4.com/globals/globalvariableset

GlobalVariableSet - Global Variables of the Terminal - MQL4 Reference
GlobalVariableSet - Global Variables of the Terminal - MQL4 Reference
  • docs.mql4.com
A global variable name should not exceed 63 characters. Characters not belonging to the current code page are not allowed (characters that cannot be converted from Unicode to ANSI are...
Reason: