if(Bars(_Symbol,_Period ) < min_bars_in_history) // if total bars is less than min_bars_in_history
{
Print("::init:: Not enough bars in history. Will download needed bars...");
Print(TerminalInfoInteger(TERMINAL_MAXBARS));
MqlRates rates[];
ArraySetAsSeries(rates,true);
// Try 5 times to allow for enough time to download all needed history
int try = 5;
while(try >0)
{
int copied=CopyRates(Symbol(),0,0,min_bars_in_history,rates);
Sleep(60000);
if(copied >= min_bars_in_history)
{
Print("::init:: Bars copied from history: ", copied);
break;
}
else
{
Print("::init:: Failed to get more than ", copied, " bars from history");
if(try>1) Print("::init:: Will try again");
}
try--;
}
int copied=CopyRates(Symbol(),0,0,min_bars_in_history,rates);
if(copied < min_bars_in_history)
{
Print("::init:: Definitely failed to download enough bars from history");
success = false;
}
}