You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Why I have the "total+1":
Step 1, we drop the indicator on the chart, at this point "prev_calculated" is zero and total is most likely greater than 100 (assuming rates total returned so). So the indicator starts checking the candles from candle 1 (i = 1), and continues to do so until i is greater than "total + 1". At this stage, "total + 1" does not cause any harm of running out of range because total is set to "rates_total - 8".
Step 2, a new candle has just been opened (candle zero), and "prev_calculated" is not zero, i.e. it is 1 candle less than rates_total, therefore, total = 1.
The for loop starts again from i=1, but it can only proceed / go through if i < total, but since total is == 1, I added "total+1" so that the for loop can go through. I added the "total+1" after considering it has no effects to step 1 as described above.
I just realised a mistake from my side (refer to intention of the indicator / code in the introduction). I intended the for loop to count (or look back) from candle 1 all the way to the back (rates_total -8), i.e. 1,2,3,4...,(n-8). At this point stopping at ((n-8)+1) is not a concern (total+1). If i is the reference point and i starts at 1, then i+1 = 2, but i-1 = 0, and candle zero is incomplete. The if conditions in the for loop are currently looking backwards with reference to i, i.e. i-1, i-2. I would expect an array out of range at this stage but I didn't get any. Thanks for the clue, I will debug and update progress if any. Otherwise if my explanation above is somewhat wrong, your correction(s) are welcome.
Thank you, I will do so.
I finally managed to get the look back logic correct, I had a fundamental misunderstanding of indexing arrays set to series and those that are not.
Below, a link I found very useful in explaining rates_total and prev_caluclated.
https://www.mql5.com/en/forum/6301#comment_163327
And below is the code in case someone might find it useful in the future, not the accuracy of the arrows but the logic. If not, admin or moderator can close / delete this thread. Thank you all for your assistance.