I`ve seen this very late, but I know the answer:
When you try to import MqlRates (bars array) and not all of the elements are filled up with data, you'll get result= -1, but GetLastError() shows 0. All you need to do is to resize the array, so to avoid empty elements you pass to CustomRatesReplace(). For example you want to read 100 bars from a file, but the file reaches the end after 86 read bars. You need to resize the array first, lets say in some script will look like this:
MqlRates custRates[]; void OnStart() { ArrayResize(custRates,100); ZeroMemory(custRates); ResetLastError(); - - - - - - - - //Read data from file, but only n=86 elements are filled up - - - - - - - - ArrayResize(custRates, n); int result_imported_bars = CustomRatesReplace(myCustomSymbol,custRates[0].time,custRates[n-1].time,custRates); if (result_imported_bars < 0) { Print("No luck when importing bars, error: ",GetLastError()); return; } }
Importing ticks with CustomTicksReplace() is the same. You need to resize the MqlTick array, so to delete the empty elements first.
Alternatively, if you don`t want to resize the array, you can simply pass the number of elements to be imported. This way you can use statically defined array, where resize is not possible:
MqlRates custRates[100]; void OnStart() { int n=86; //number of elements filled up with data int result_imported_bars = CustomRatesReplace(myCustomSymbol,custRates[0].time,custRates[n-1].time,custRates,(uint)n); }

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Can anyone explain how CustomRatesReplace could return -1 and LastError set to 0?