for(int i = 1; i < limit; i++){// [1 … Bars-1] if(indicator(i) == 0) // [1 … Bars-1] ⋮ } int indicator(int bar){ // [1 … Bars-1] This line -> double oscilator_p = (Close[bar + 1] ...Code...; // [2 … Bars] <== Close[Bars] does not exist
Do your lookbacks correctly.
Can you elaborate on why Close[bar] does not exist? (note that bar is the function input, not Bars containing the amount of available bars on the chart)
EDIT
The issue only happens on the tester, when I load it on the chart, it has no issues, at least that I notice, not sure if my error is on the OnCalculate() function?
Fernando Jose Velasco Borea: can you elaborate on why
Close[bar] does not exist? (note that bar is the function input, not Bars containing the amount of available bars on the chart)
Close[bar] exists. Your line reads Close[bar+1] which fails when bar equals Bars-1.
William Roeder:
Close[bar] exists. Your line reads Close[bar+1] which fails when bar equals Bars-1.
Oh!! So the fail is for example when Bars is 999 and it tries to access index 1000? If so, the solution would be in the for loop to do i < limit - 1?
Close[bar] exists. Your line reads Close[bar+1] which fails when bar equals Bars-1.
Fernando Jose Velasco Borea:
Oh!! So the fail is for example when Bars is 999 and it tries to access index 1000? If so, the solution would be in the for loop to do i < limit - 1?
Oh!! So the fail is for example when Bars is 999 and it tries to access index 1000? If so, the solution would be in the for loop to do i < limit - 1?
When Bars is 999 there is no index 999 either
The index is from [0] to [998]
Keith Watford:
You're right, let me rephrase, so the issue is for example when Bars equals to 1000 and the loop tries to access bar with index 1000, which doesn't exist as the last index is 999?
When Bars is 999 there is no index 999 either
The index is from [0] to [998]
Fernando Jose Velasco Borea:
You're right, let me rephrase, so the issue is for example when Bars equals to 1000 and the loop tries to access bar with index 1000, which doesn't exist as the last index is 999?
You're right, let me rephrase, so the issue is for example when Bars equals to 1000 and the loop tries to access bar with index 1000, which doesn't exist as the last index is 999?
Correct.

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
Hello!
I have the following indicator:
I want it to be based just upon the previous candle to avoid repainting, therefore I started the for loop at 1 instead of 0. But when I add it to the strategy tester to check it, I get the Array out of Range error on the line marked as "This line ->" in the Close access of the previous bar (bar + 1, or the value of i in the for loop + 1 as that's the input for the signals function), I tried starting the for loop at 0 but I keep getting the same issue... could someone help me out to figure what's wrong?