Hi this is half trend indicator
it stop working at Line 85,21
how to solve this error?
Might be a good idea to show which line that is.
At the very first iteration when "i = Bars - 1", then "i + 1" would give the value of "Bars" which is beyond the index of the array. You will then get "array out of range" error for "trend[i+1]".
You need to detect this initial condition and give it a seed value for "trend[i]" on the first iteration. The same problem will arise in all the places in your code where you reference "[i+1]", so you will need to detect this special case or condition.
Next time, please mention what error is given in the logs instead of just saying that it stopped working.
At the very first iteration when "i = Bars - 1", then "i + 1" would give the values of "Bars" which is beyond the index of the array. You will then get "array out of range" error for "trend[i+1]".
You need to detect this initial condition and give it a seed value for "trend[i]" on the first iteration. The same problem will arise in all the places in your code where you reference "[i+1]", so you will need to detect this special case or condition.
Next time, please mention what error is given in the logs instead of just saying that it stopped working.
It is an old indicator and doesn't use #property strict.
I may be wrong but if I remember correctly, I don't think that you get an array out of range error if #property strict is not used.
Thank you Keith for pointing that out. It has been quite long since I used the old non-strict code style, so I no longer remember what it reports.
Note to OP: Irrespective of the error reporting, it is still a case of the array index being out of the acceptable range, so you will need to change the code to adjust for the first iteration of the loop.
Hi this is half trend indicator
it stop working at Line 85,21
how to solve this error?
Try changing instances of Bars-1 to Bars-2
To keep the i+1 in series.
See How to do your lookbacks correctly #9 — #14 & #19.
That will not solve the problem, because the values of the buffers at the index [Bars-1] will then be undefined and throw the rest out of sync. They cannot just be ignored and have to be properly set.
The indicator simply calculates 1 less bar in history.
There is no restriction on a lesser number of bars to calculate.
The indicator works fine.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi this is half trend indicator
it stop working at Line 85,21
how to solve this error?
trend[i]=trend[i+1];