How can I separate the last pivot from the previous ones?

Hi all,

I am trying to find a pivot early by using shorter lookback periods for the latest candidate than the historically confirmed ones. Below code is a simplified version from empottasch's work, thanks eddy:).

rightstrength = Param( "Right Strength", 5, 1, 15, 1 );
leftstrength = Param( "Left Strength", 5, 1, 15, 1 );
rightnew = 2;

// defiine peaks and troughs
tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;
tr1 = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightnew ), rightnew ) > L;

Plot( C, "", IIf( C > O, colorRed, colorGreen), 64, Null, Null, 0, 1 );

PlotShapes( shapeSmallCircle * tr, colorRed);
PlotShapes( shapeSmallCircle * tr1, colorBlue);

It doesn't work. I don't know how to determine the last pivot. Any help is much appreciated.

Scott