Download MetaTrader 5

No documentation for "cannot refresh history [4073]"? How to properly handle this error? - page 3

To add comments, please log in or register
6xfngb5dgfe6d
54
6xfngb5dgfe6d  
So using your code, it would look like this: 
int OnInit()
{
   //init logic

   EventSetMillisecondTimer(1); //right before return
   return INIT_SUCCEEDED;
}

//recursion until initialised
void OnTimer()
{
   if(InitSymbolsHistory(symbols,PERIOD_M15,PERIOD_H4)) //check data is loaded
   {
      EventKillTimer();
      OnTick();
   }
   else
      EventSetTimer(1);
}

void OnTick()
{
   //Logic here
}

nicholishen
1537
nicholishen  
6xfngb5dgfe6d:

There's many ways to do it, but this is how I would do it...

#include <multi_symbol_timeframe.mqh>
string symbols[]={"EURUSD","USDJPY","EURJPY"};
void OnTick()
{
//---
   if(!InitSymbolsHistory(symbols,PERIOD_M1,PERIOD_D1))
   {
      EventSetTimer(1);
      return;
   }
   else
      EventKillTimer();
}
//+------------------------------------------------------------------+
void OnTimer()
{
   OnTick();
}
 
Alain Verleyen
Moderator
35127
Alain Verleyen  
6xfngb5dgfe6d:
Ok, let's make an attempt to make this complete, so someone else can also reuse it. This is how I see the step 2:


Beside nicholishen remarks, I would not recommend this kind of approach. There is something fundamentally wrong in your reasoning, you can NOT avoid errors once for all, you have to check for error each time an error is possible. Of course that doesn't mean the above approach is wrong or will not work for your needs. But the best practice is to check for errors, always. 

123
To add comments, please log in or register