Hi mates, I'm having some troubles with barcount. I've searched into the forum and into the KB but I can't find a solution.
Generally speaking, the main scope of the script I'm writing is to evaluate some parameters for generating events and then sort those events in a way that the more recent are consecutively and in inverse order at the beginning of an "event array" (so the more recent events have lower index).
My idea is to let a function determine the events and return a (generally sparse) array then the main part of the script compresses and inverses the array to get the latter events at the beginning of the event array.
Seeing that the program I'm working on is quite chumbersome, I've recreated the issue by the following dummy script.
Here's the code:
function testFunction(tgtBarIndex) //dummy function - only for recreating the issue
{
ans = null;
for (i = 0; i < tgtBarIndex; i++)
{
ans[i] = i % 10;
}
return ans;
}
// main script
SetBarsRequired(sbrAll, sbrAll);
targetBarIndex = 2000;
values = testFunction(targetBarIndex);
multiplyPositions = IIf(values == 0, BarIndex(), Null);
compressedValues = SparseCompress(multiplyPositions, multiplyPositions);
reversedMultiplyPositions = Reverse(compressedValues);
p0_pos = reversedMultiplyPositions[0];
p0_val = C[p0_pos];
PlotOHLC(O, H, L, C, "", colorBlack, styleBar);
PlotShapes(IIf(BarIndex() == p0_pos, shapeCircle, shapeNone), colorBlue, 0, p0_val,0);
The problem is that when I run in debug mode (code check and profile, and also line by line debugging) everything is ok, but when I try to apply the script Amibroker responds with an indexing error.
Precisely the error is a reference to an inexistent 200th bar, despite the fact I've forced to use all the bars via the command
SetBarsRequired(sbrAll, sbrAll);
and the that the time series is long more than 2000 (BarCount >2000).
Here's the screenshots:
code check and profile returns no errors:
line by line debugging shows no errors:
Apply this script to the chart causes the BarCount error:
I'm using version 6.42.0, build date: Nov 27 2022 Pro 64bit
Can you replicate this issue? What I'm doing wrong here? why the difference between code check and application to the chart?