int OnInit() { //--- indicator buffers mapping //SetIndexBuffer(0,High_recent); ArrayResize(High_recent, 0, Bars - 1); ArrayResize(High_recent, Bars - 1, Bars - 1); //--- return(INIT_SUCCEEDED); }
If you want to emulate an indicator buffer, then usually the size is changed in OnTick, and not once in OnInit.
You cannot use SetIndexBuffer in an EA. This is for indicator only. Therefore the size of your High_recent[] array is zero.
If you want to emulate an indicator buffer, then usually the size is changed in OnTick, and not once in OnInit.
You cannot use SetIndexBuffer in an EA. This is for indicator only. Therefore the size of your High_recent[] array is zero.
void CheckForOpen() { int b=Bars-1; for(int shift=0; shift<=b-ExtDepth; shift++) // looping backward { High_recent[shift] = iCustom(NULL,0,"Scott\\ZigZag_iCustom_for_EA",ExtDepth,ExtDeviation,ExtBackstep,0,shift); // error(array out of range) occurs ??? Print("High_recent[",shift,"]=",High_recent[shift]); } }
With each tick you try to copy the entire indicator buffer into your array again. It might work, but it will be quite slow.
In this topic I gave my example of emulating indicator buffers in an advisor. But this can be relatively difficult to understand (and to implement), because in that example I meant placing the indicator algorithm in a separate file. But perhaps you will find something useful for yourself there.
With each tick you try to copy the entire indicator buffer into your array again. It might work, but it will be quite slow.
In this topic I gave my example of emulating indicator buffers in an advisor. But this can be relatively difficult to understand (and to implement), because in that example I meant placing the indicator algorithm in a separate file. But perhaps you will find something useful for yourself there.
The topic you taught me is very useful. I will use the idea to implement indicator buffer like array into an EA with much saving calculation time. Thank you so much.
Also to consider - there are certain scenarios which will stop your code dead - such as divide by zero or array out of range.
Always worth coding a "if" check before attempting these operations and reacting accordingly if the situation is not as expected
Also to consider - there are certain scenarios which will stop your code dead - such as divide by zero or array out of range.
Always worth coding a "if" check before attempting these operations and reacting accordingly if the situation is not as expected

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am having a difficulty in solving "array out of range" error, which occurs constantly when I perform strategy tester with my EA under development.
I tried to figure out the cause and fix it by referring to MQL4 reference and other sources available in cyber network, but so far no progress for almost 2 weeks.
I hope anyone can direct me to the source that help me fix the issue or provide a straight answer to my problem.
The below is my EA under development and the highlighted in pink is where the error occurs.
Journal of the strategy tester;
The Indicator calling from EA is below. It shows ZigZag peak and valley points on a chart.
Options setting;
Max bars in chart is 250,000 and oldest date on 5 minutes chart is July 29,2020. So I believe that the period I used for strategy tester would not be an issue.
I would appreciate any help.
Regards,