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

 
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
}

 
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();
}
 
 
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. 

 
6xfngb5dgfe6d:

So to summarize this up:

To avoid error 4073 and also achieve immediate logic execution after initialization, one should use this code:

Is this the best practice?

Hi, this is an old post but I've seen this random issue (error 4073 at OnInit).  You made a good point, and Carl Schreiber stated it clear to a general scope.  I liked both so I just wanted to share that I've faced the need to do more sort of "initialization stuff" on top of whatever I had at OnInit.  To avoid this, I just use a global variable, say "initPending".  Then as Carl Schreiber proposed, inside OnTick, I take care of the pending initialization stuff.

bool initPending = true;

int OnInit()
{
   //init logic
   initPending = true; // this is optional, just to make the point as TRUE is already pre-initialized 
   return INIT_SUCCEEDED;
}

void OnTimer()
{
  //optional or whatever you need here other than the pending initialization discussed here
}

void OnTick()
{
   if (initPending)
   {
      initPending = false;
      // whatever extra initialization required, even calling a routine from an INCLUDE
   }
   //Logic here
}
 

Too bad that when INIT_FAILDED is returned by OnInit,  MT4 does not retry to call OnInit after waiting a few seconds until OnInit returns INIT_SUCESSFULL