Array Out Of Range
-
I have started getting Array Out Of Range errors.
The EA starts & runs for a while and then simply stops.
To fix a bug you need to replicate I haven't yet managed to find a series of events to replicate it.
The error always points to the same area of "core" fxdreema code:-
datetime new_value = time[0];
This code appears under the heading:- // "Once per bar" model
Judging by the last message before the error occurs I believe it is happening immediately on the start of a new bar.
Any thoughts please ?
-
A common error. No one can tell from your limited information
-
Yup, that's the issue, there doesn't appear to be a smoking gun. I've added a raft of logging messages to try and gain more insight when it happens again.
-
@Mantadiver
Sometimes it may be related to the customized indicators you used -
Today I investigated this error a little bit more. One user sent me his history data and I was able to get the error myself. At the end, I don't know how to fix the problem, but this is what I understood.
Each candle has OHLC, Volume and also Time. "Once per bar" works by reading the Time from the candle, remembering that time and then when the time changes (when a new candle is added), it can pass again and remember the new time. Do this over and over and the block passes once per bar.
To get the time I used a function called CopyTime. This function would read the data from just one candle, and then it would put the result in a dynamic array, which initially has size of 0. When the data is put into the array, its size would automatically change to 1. Then, that single value from the array would be read, which usually happens without problems. But when the function fails, the array doesn't change, its size remains 0 and that's why later it shows "array out of range".
While the error says "array out of range", the problem comes from the inability to read that candle. And in the tests I did today, CopyTime wasn't able to read any candle.
First I did a fix, so that when CopyTime fails, it won't even try to read the value from the array, it would just do nothing and "Once per bar" won't pass. Muted error, the EA just tried to do what it can.
Then I tested iTime, which seems to be able to get the time from the previous candle somehow. However, then I realized that if lower timeframe is selected in "Once per bar", then iTime (and also CopyTime) could fail.
So the whole situation happens because something in the history data is not right. But I don't really know how to fix the problem with these functions. I can mute the error so it won't appear, or print another more descriptive error.
-
Possible solution would be to try to download the history data again. The data files are located in history/%TheNameOfYourBroker%. But if you are testing, also delete the files from tester/history - the .fxt files there are the generated ticks.
Or maybe use another broker for the tests. Different files are downloaded from each broker.
-
Would it be possible to not use an array but use a simple integer instead ? When I build indicators I check for once per bar by populating an integer ThisBarStartTime = Time[0];
The BIG issue here is that when an EA is running live an array out of range error stops it dead in its tracks and no further actions can be taken. There is no way to create an alert, push, sms or Telegram meassage to the user because it has simply stopped working. Therefore it ends up with orphaned trades unless they can be identified and managed by reapplying the EA to the chart.
Instead of allow an array our of range error to occur, would it be possible to allow the code to continue and do further checks, i.e. look at the timeframe and check some other flag to see whether it has already been actioned yet on this bar. Then allow it to continue and maybe flag an alert to say there was an issue but at least the ea continues to run . . . . ?
Thanks for looking into it. Appreciated.