I am struggeling with this error: "tried to reference back more bars then allowed" and would like to avoid the case in my code. I have read evreything I could about this but sadly can't get a grip on it.
Strangely this exact same code will never give an error as an indicator but will do as a signal, unless I increasing the MaxBarsBack manually to over needed value. Sadly, one cannot set the MaxBarsBack in a signal. I just can't find a proper way to systematically avoid the problem ( = referencing back less bars than allowed).
Code: Select all
inputs: Strength( 20 ) ;
Vars: HSwing(False), LSwing(False), LastSwingHighBN(0), LastSwingLowBN(0), TLRef(0) ;
HSwing = PivotHighVSBar( 1, High, Strength, Strength, Strength + 1 ) <> -1 ;
LSwing = PivotLowVSBar( 1, Low, Strength, Strength, Strength + 1 ) <> -1 ;
if HSwing then
begin
LastSwingHighBN = BarNumber[Strength] ;
TLRef = TL_New_BN( LastSwingLowBN, Close[CurrentBar-LastSwingLowBN], LastSwingHighBN, Close[CurrentBar-LastSwingHighBN] ) ;
end;
if LSwing then
begin
LastSwingLowBN = BarNumber[Strength] ;
TLRef = TL_New_BN( LastSwingHighBN, Close[CurrentBar-LastSwingHighBN], LastSwingLowBN, Close[CurrentBar-LastSwingLowBN] ) ;
end;
Your help is most welcome. Thanks !