copyrates: Invalid function parameter value

 

Hi,

I Have some code like this:

MqlRates rates[];

datetime  starttime = iTime("GBPUSD", PERIOD_M1, 0);

CopyRates("USDSAR", PERIOD_D1, starttime, 20, rates);

I get the following error

4051: Invalid function parameter value.

I've used the starttime from GBPUSD once and stored in a global variable, so that I don't have to call it repeatedly.

But if I use a different symbol, it is all good. So this error doesn't make sense. after trial and error it looks like starttime is the culprit.

How can it be valid on one symbol and not on the other ?

 
maindoor: But if I use a different symbol, it is all good. So this error doesn't make sense. after trial and error it looks like starttime is the culprit. How can it be valid on one symbol and not on the other
datetime  starttime = iTime("GBPUSD", PERIOD_M1, 0);

CopyRates("USDSAR", PERIOD_D1, starttime, 20, rates);
  1. You don't have GBPUSD history (thus starttime==0) or you don't have USDSAR history.
  2. OR perhaps starttime should be a D1 time
    datetime  starttime = iTime("GBPUSD", PERIOD_M1, 0);                             
    CopyRates("USDSAR", PERIOD_D1, DateOfDay(starttime), 20, rates);
    /////////////////////////////////////////////////////////////////////////////////
    #define HR2400 (PERIOD_D1 * 60)  // 86400 = 24 * 3600
    int      TimeOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                              return( when % HR2400 );            }
    datetime DateOfDay(datetime when=0){      if(when == 0)  when = TimeCurrent();
                                              return( when - TimeOfDay(when) );   }
    //datetime Tomorrow( datetime when=0){      if(when == 0)  when = TimeCurrent();
    //                                          return(DateOfDay(when) + HR2400);   }
    //datetime Yesterday(datetime when=0){      if(when == 0)  when = TimeCurrent();
    //   int iD1 = iBarShift(NULL, PERIOD_D1, DateOfDay(when) - 1);
    //                                       return( iTime(NULL, PERIOD_D1, iD1) ); }
    

 
WHRoeder:
  1. You don't have GBPUSD history (thus starttime==0) or you don't have USDSAR history.
  2. OR perhaps starttime should be a D1 time

I wanted the last 20 bars in PERIOD_D1 for the symbol USDSAR. instead of getting the starttime from GBPUSD

I used timecurrent(). Thought it was reasonable to expect that from the current-time retrieve the last 20 PERIOD_D1 bars. But no.

This is a snip from the Manual:

When requesting data by the start date and the number of required elements, only data whose date is less (earlier) or

equal to the date specified. It means, the open time of any bar, for which value is returned (volume, spread, value on

the indicator buffer, prices Open, High, Low, Close or open time Time) is always less or equal to the specified one.

Less than or equal to is the key. But doesn't work as in the Manual.

The problem with your second suggestion is if it is a D1 or H4 time, it will retrieve from the most recent bar stored locally in history.

Not the one latest in the server.

How do I get the latest from the server ? Other than specifying the start position as 0 -> wait till download finishes ->

call the function again with 0 to get the latest. It could atleast return ERR_HISTORY_WILL_UPDATED, that'll make sense.


Reason: