Think about it — when "i = 0", what do you think "i - 1" will give?
It will give the result "-1". Is there such an index in your array? Does "array[-1]" make sense when the lowest it can go is "array[0]"?
No, so it will give an "array out of range" error.
Think about it — when "i = 0", what do you think "i - 1" will give?
It will give the result "-1". Is there such an index in your array? Does "array[-1]" make sense when the lowest it can go is "array[0]"?
No, so it will give an "array out of range" error.
OMG !!!! I figured it out. Thank you so much Fernando, just shows what a fresh set of eyes can do. All I simply did was amend my if statement to make it so 'i' < 1 (see below). Been looking at this for days and so 'chuffed' it is now working. Thank you again. (I'm making the assumption it is correct because it has started showing me my engulfing patterns)
for(int i = prev_calculated-1; i < rates_total-1; i++) { if(i < 1 || i > rates_total-1) continue; if(inp_IsHiLoEngulfing) {

- 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 have been trying to rectify an issue I've had for a while now and could really do with some help please. I am trying to create an indicator that shows the Bearish/Bullish Engulfing patterns (trying to build up my skills). I first created a similar FindHammerPattern() function which worked really well but my 'FindHiLoEngulfingPattern()' function keeps getting the "array out of range" error. I have tried to investigate the problem (See Print() statements) but am really confused as to what it could be. I think the issue has to do with the parameters used by the OnCalculate() function were the same number as my GetHammerPattern() function. However, in the FindHiLoEngulfingPattern() function because I am trying to retrieve TWO candles worth of data it is causing problems. I would just like to know how I could retrieve two (or more) candles worth of data. Ideally correcting my code or pointing me in the right direction would be greatly appreciated. Many thanks in advance.