After breaking down and testing smalls snippets of the following code, I think the "extremes" function is the cause of the error. I performed the following to diagnose this:
1. Set Max Bars Back to 10.
2. Applying the indicator, it doesn't obey the setting and appears to randomly starts at any point.
2. By replacing 'barCount ' with 1, the code respect the Max Bars Back setting.
Code: Select all
vars:
lowPivot ( 0 ),
highPivot ( 0 ),
barCount ( 0 ),
highBar ( 0 ),
lowBar ( 0 );
if currentBar = 1 then begin
LowPivot = L[0];
HighPivot = H[0];
barCount = 1;
end
else begin
barCount = barCount + 1;
if L[0] < lowPivot and C[0] >= lowPivot then begin
lowPivot = L[0];
end;
if (H[0] > highPivot and C[0] <= highPivot) then begin
highPivot = H[0];
end;
if (C[0] > O[0] and C[0] > highPivot) then begin
highPivot = H[0];
value1 = extremes(low, barCount, -1, lowPivot, lowBar);
barCount = 1;
end;
if (C[0] < O[0] and C[0] < lowPivot) then begin
lowPivot = L[0];
value2 = extremes(high, barCount, 1, highPivot, highBar);
barCount = 1;
end;
end;
plot1[0](highPivot, "highPivot");
plot2[0](lowPivot, "lowPivot");
Any help on this?
Thanks.