error - simple CopyRates does not work

 

Client Terminal Build and Version (32 or 64 bit)

32 build 701

Problem description

CopyRates simple 2nd variation (by datetime,count) does not work

Sequence of action

Just a simple CopyRates

string sym="GBPUSD";

datetime checkt=D'2014.09.22 04:00:00';

MqlRates rates[2];

int cpy=CopyRates(sym,PERIOD_M1,checkt,2,rates);

result - cpy=-1 last error = 4029 

when I use same CopyClose or CopyTime with this variation (time,count) it's ok. 

Obtained result

error 4029 - array invalid

Expected result

copied 2

Additional details

...

 

Anyone has some insight as to why these lines don't return rates?

 

string sym="GBPUSD";

datetime checkt=D'2014.09.22 04:00:00';

MqlRates rates[2];

int cpy=CopyRates(sym,PERIOD_M1,checkt,2,rates);
 

also trying to bypass this by

   int barshiftm1=iBarShift(sym,PERIOD_M1,checkt); 
   int cpy=CopyRates(sym,PERIOD_M1,barshiftm1,2,rates);

 

gives rates of a different time - hope it relates to same issue

 
amir_avatar: Anyone has some insight as to why these lines don't return rates?
MqlRates rates[2];
Don't give it a size. The function doesn't copy to rates, it redirects accesses to rates to mt4's internal buffer.
 
WHRoeder:
amir_avatar: Anyone has some insight as to why these lines don't return rates?
Don't give it a size. The function doesn't copy to rates, it redirects accesses to rates to mt4's internal buffer.

Appreciate your intent, even though you haven't tried your suggestion.

Otherwise you would have seen it's not working either (and it can work with rates[2] no problem there, I tried both ways before I posted and [2] works for CopyClose and all other Copy..).

As finally I was able to get response from service desk, this issue is known and should be resolved on next build.
 

 

I reported the issue fast a year ago. The service desk answer was like that - do not use time in the parameter, use the bar index which works well.

But this is not the only problem with CopyRates. I sometimes got "access violation error". So finally I am not using this function, but rather ArrayCopyRates and ArrayCopy combo.

 
amir_avatar:

Client Terminal Build and Version (32 or 64 bit)

32 build 701

Problem description

CopyRates simple 2nd variation (by datetime,count) does not work

Sequence of action

Just a simple CopyRates

string sym="GBPUSD";

datetime checkt=D'2014.09.22 04:00:00';

MqlRates rates[2];

int cpy=CopyRates(sym,PERIOD_M1,checkt,2,rates);

result - cpy=-1 last error = 4029 

when I use same CopyClose or CopyTime with this variation (time,count) it's ok. 

Obtained result

error 4029 - array invalid

Expected result

copied 2

Additional details

...

Thank you for your message. Fixed. Please wait for updates.
 
DeepThought:

I reported the issue fast a year ago. The service desk answer was like that - do not use time in the parameter, use the bar index which works well.

But this is not the only problem with CopyRates. I sometimes got "access violation error". So finally I am not using this function, but rather ArrayCopyRates and ArrayCopy combo.

At least for ArrayCopyRates it's working now, only after I download the M1 rates manually for the symbol - which I found annoying. I maybe don't do it right.. 
I just go to the M1 chart and scroll it backwards. Isn't there an automatic way to download M1 from within MQL4? 

I don't mean using TickStory and all that.. I know there isn't and the rates are represented different than the MT5 but it's is just a huge drawback in MT4 making me think of go back to MT5 (which for me has a huge drawback in it's position management system.. )
 

Metatrader 5 last buid.

My custom indicator in OnCalculate function access rates from higher time frame.

It works good for symbols with long history,  but for futures series with short history CopyRates returns 0;

In the same time iBarShift( _Symbol, BIGGER_TIMEFRAME, time[shift] ) returns -1;

This must be some kind od fundamental error of Metatrader 5

Documentation on MQL5: Language Basics / Functions / Event Handling Functions
Documentation on MQL5: Language Basics / Functions / Event Handling Functions
  • www.mql5.com
The MQL5 language provides processing of some predefined events. Functions for handling these events must be defined in a MQL5 program; function name, return type, composition of parameters (if there are any) and their types must strictly conform to the description of the event handler function. The event handler of the client terminal...
 
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

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.

On MT5: Unless the chart is that specific pair/TF, you must Synchronize the terminal Data from the Server.
          Is it mystical?! It is! - Withdraw - Technical Indicators - MQL5 programming forum
          Timeseries and Indicators Access / Data Access - Reference on algorithmic/automated trading language for MetaTrader 5
          Synchronize Server Data with Terminal Data - Symbols - General - MQL5 programming forum
          SymbolInfoInteger doesn't work - Symbols - General - MQL5 programming forum 2019.09.03

 

You're a precious gem, William.

Thank you for this helpful list! :)

Reason: