Need help to mark high and low pivot alternately

Dear Seniors,

Below is the AFL i copied from the forum,

t// Fractal Pivots
bi = BarIndex();
fvb = FirstVisibleValue( bi );
lvb = LastVisibleValue( bi );

rightstrength = Param( "Right Strength", 3, 2, 50, 1 );
leftstrength = Param( "Left Strength", 3, 2, 50, 1 );
fact = Param( "Chart Time Frame Factor", 1, 1, 10, 1 );

rightStrength = rightStrength * fact;
leftStrength = leftStrength * fact;

pk = H == HHV( H, leftstrength ) AND Ref( HHV( H, rightstrength ), rightstrength ) < H;
tr = L == LLV( L, leftstrength ) AND Ref( LLV( L, rightstrength ), rightstrength ) > L;

for( i = 0; i < 3; i++ )
{
    VarSet( "px" + i, ValueWhen( pk, bi, i ) );
    VarSet( "tx" + i, ValueWhen( tr, bi, i ) );
    VarSet( "ph" + i, ValueWhen( pk, H, i ) );
    VarSet( "tl" + i, ValueWhen( tr, L, i ) );
}

ll = tr AND tl1 < tl2;
hl = tr AND tl1 > tl2;
hh = pk AND ph1 > ph2;
lh = pk AND ph1 < ph2;
dt = pk AND ph1 == ph2;
db = tr AND tl1 == tl2;

GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 0, 255 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );

clr = ColorRGB( 10, 10, 10 );

for( i = lvb; i > fvb; i-- )
{
    // troughs
    if( ll[i] )
    {
        str = "SPL";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 0, 250 ), colorDefault, -30 );
    }

    if( hl[i] )
    {
        str = "SPL";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 0, 250 ), colorDefault, -30 );
    }

    if( db[i] )
    {
        str = "SPL";
        PlotTextSetFont( str, "Arial Black", 8, i, L[i], ColorRGB( 0, 0, 250 ), colorDefault, -30 );
    }

    //peaks
    if( hh[i] )
    {
        str = "SPH";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( lh[i] )
    {
        str = "SPH";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }

    if( dt[i] )
    {
        str = "SPH";
        PlotTextSetFont( str, "Arial Black", 8, i, H[i], ColorRGB( 250, 0, 0 ), colorDefault, 20 );
    }
}

Title = Name() +
        " | " + Now( 2 ) +
        " | " + "Pivot Timeframe Factor: " + fact;ype or paste code here

I need help to update the AFL so the marking will be like

  1. SPL and SPH should alternately marked...
  2. SPL is the lowest point in between two SPH
  3. SPH is the highest point between the two SPL

thanks in advance ..

I too tried using HHV and LLV. But those functions accept constant number left side and right side to identify higher or lower. I want two bar (not necessary to be consecutive) to be closed lower low from the reference bar to mark higher bar. Appreciate if any help.

Have you coded the SPH and SPL marking? Please tell me how to do that.