Reset variables after enabling autotrade - page 2

 
Marko Tuta #: Hmm, ok. I supposed so. Do you know a way to solve this? 

The answer has already been given — "Instead detect when the state changes, either from enabled to disabled, or from disabled to enabled, and set your variables accordingly."

Here is an example I use with MQL5 Services, which checks for multiple conditions and a change in state ...

   // Check if trading is allowed
      bool IsTradingAllowed( void ) {
         // Declare and initialise variables
            static   bool  s_bAllTradeAllowed         = true;
                     bool  bAccountTradeAllowed       = AccountInfoInteger(  ACCOUNT_TRADE_ALLOWED  ),
                           bAutomatedTradeAllowed     = AccountInfoInteger(  ACCOUNT_TRADE_EXPERT   ),
                           bTerminalTradeAllowed      = TerminalInfoInteger( TERMINAL_TRADE_ALLOWED ),
                           bProgramTradeAllowed       = MQLInfoInteger(      MQL_TRADE_ALLOWED      ),
                           bAllTradeAllowed           = bAccountTradeAllowed   &&
                                                        bAutomatedTradeAllowed &&
                                                        bTerminalTradeAllowed  &&
                                                        bProgramTradeAllowed;

         // Verify if all trading has been re-enabled
            if( s_bAllTradeAllowed != bAllTradeAllowed ) {
               if( bAllTradeAllowed ) AlertNotify( i_sAttentionEnabled, i_eAlertTradingReenabled );
               s_bAllTradeAllowed = bAllTradeAllowed;
            };

         // Return current trading status
            return s_bAllTradeAllowed;
      };
 
Ok, I solved. I used the code mentioned above inside the ontick() section on a demo account and it's ok. When I disable EA the variable resets. Thank you for your help