After the “Account disabled” error occurs (this error on the weekends, when trade servers of exchanges are offline), it is necessary to manually log in to the trading account. To do that, go to “File” and select “Login to trade account”. But doing this manually is uncomfortable and tedious. It also manually keeps track of connection loss after the “Account disabled” error.
The “LoginToTradeAccount.mqh” library allows to automate the process of connecting to a trade server.
Example of Use
The EA checks the connection to the trade server (the TERMINAL_CONNECTED identifier) every 12 seconds in the OnTimer() function. If the connection state is “0”, the library is called:
//+------------------------------------------------------------------+ //|                                          TestAccountDisable.mq5 | //|                        Copyright 2016, MetaQuotes Software Corp. | //|                                            | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, MetaQuotes Software Corp." #property link      "" #property version  "1.00" #include <LoginToTradeAccount.mqh> //+------------------------------------------------------------------+ //| Expert initialization function                                  | //+------------------------------------------------------------------+ int OnInit()   { //--- create timer   EventSetTimer(12); u//---   return(INIT_SUCCEEDED);   } //+------------------------------------------------------------------+ //| Expert deinitialization function                                | //+------------------------------------------------------------------+ void OnDeinit(const int reason)   { //--- destroy timer   EventKillTimer();   } //+------------------------------------------------------------------+ //| Expert tick function                                            | //+------------------------------------------------------------------+ void OnTick()   { u//---   } //+------------------------------------------------------------------+ //| Timer function                                                  | //+------------------------------------------------------------------+ void OnTimer()   { u//---   static bool cleaner=false;   if(!cleaner)     {       long rezult=TerminalInfoInteger(TERMINAL_CONNECTED);       Comment("TERMINAL_CONNECTED: ",IntegerToString(rezult));       if(rezult==0)         LoginToTradeAccount();     }   else       Comment("");   cleaner=!cleaner;   } //+------------------------------------------------------------------+
The “TestAccountDisable.mq5” example file is attached at the end of description.
/ru/code/16049