New user struggling with something very simple.

 

Hi All,

I am currently trying to take baby steps in the world of MQL4. I am trying to load a very small amount of data into an array using:

 

do

      {

      count=CopyRates("GBPUSD",PERIOD_M15,0,10,test);

      printf(string(count) + " " + string(GetLastError()));

      Sleep(1000);

      }

   while (count!=10);

      for(int i=0; i<ArraySize(test); i++)

         printf(string(test[i].close));

If I do this using PERIOD_M15 I just get a loop of count = -1 and a 4073 error. If I use PERIOD_H4 it works fine. The M15 chart displays OK, so the data is clearly there. Why does this not work?

Thanks.

 
scoll01:

I am currently trying to take baby steps in the world of MQL4. I am trying to load a very small amount of data into an array using:

If I do this using PERIOD_M15 I just get a loop of count = -1 and a 4073 error. If I use PERIOD_H4 it works fine. The M15 chart displays OK, so the data is clearly there. Why does this not work?

Your code looks fine, and i run it on my mt4 without any problem.

Regardless, this simply highlights the need to always check the return values / errors before continuing... because some times the system just needs more time.

 
  1. Please edit your (original) post and use the CODE button (Alt-S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
              Messages Editor

  2. scoll01: count=CopyRates("GBPUSD",PERIOD_M15,0,10,test);
    On MT4: Unless the current chart is that specific pair/ TF referenced, you must handle 4066/4073 errors before accessing prices.
              Download history in MQL4 EA - Forex Calendar - MQL4 programming forum - Page 3 #26 № 4

    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 the first call.

 

Sorry. I have edited the original post to add the code.

I'll give that function a try, thanks.

Reason: