Error 4066 HELP

Tilted t.
16
Tilted t.  

Hi!.

I'm asking for help, because i'm not really understanding what should i do to avoid error 4066.

Basically, my goal is to store the value of iTime and iBars inside some variables right when the bot gets initialized.

The problem is that i cannot do initialize the variables in the OnInit() function, because it triggers this error and for other reasons.

So i tried to initialize them on the OnTick() function, but this triggers the error too.

And i even tried to wait until it stops giving the error, like so:

int err;
do
{
var1 = iTime(NULL, PERIOD_M1, 0);

var2 = iBars(NULL ,PERIOD_M1);

err = GetLastError();
} while(err == 4066);


With this approach the values stored inside the variables are TOTALLY WRONG.
I do not really know what to do.
Thanks for reading and thanks in advance for your help.

William Roeder
24287
William Roeder  
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20
    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open), thus updating history, and temporarily placing the symbol on Market Watch (if not already there), so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

  3. Your code is looping continuously. You must check and return so the history can be updated.
Tilted t.
16
Tilted t.  
William Roeder:
  1. Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. On MT4: Unless the current chart is that specific symbol(s)/TF(s) referenced, you must handle 4066/4073 errors before accessing candle/indicator values.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26.4 2019.05.20
    The function linked to, opens a hidden chart for the symbol/TF in question (if not already open), thus updating history, and temporarily placing the symbol on Market Watch (if not already there), so SymbolInfoDouble(symbol, SYMBOL_BID) or MarketInfo(symbol, MODE_BID) don't also return zero on the first call.

  3. Your code is looping continuously. You must check and return so the history can be updated.

Thank you very much for the reply and sorry for the error.

I have one last question, during the testing with the strategy tester, is it possibile to download history data from other markets. The function download_history() will loop infinitely because there is no history data(error 4073).

Is this a limitation of the strategy tester itself?

William Roeder
24287
William Roeder  
Tilted t.: The function download_history() will loop infinitely because there is no history data(error 4073).

Wrong. It will loop until history is downloaded. Then there will be no 4073

Tilted t.
16
Tilted t.  
William Roeder:

Wrong. It will loop until history is downloaded. Then there will be no 4073

That's strange, while in the strategy tester if i put the function download_history inside a while loop like this:
while(!download_history(NULL, PERIOD_M5));

It just loops infinitely (except when i put PERIOD_M1, but only because i set the strategy tester on PERIOD_M1).


I tried to backtest with downloaded tick data from tickstory, but the files that i put in tester/history will throw error 4074, except for the file that has the timeframe of the strategy tester settings.