# Help with clear bar method

Hello I was given the following formula for the clear bar method for price movement and I am getting several different errors. I was wondering if someone could help me figure out how to make this formula work. See attached for full details.

Thanks

``````Vars: hH(H), lL(L), lH(H), hL(L), upsw(0), SwLine(0);

{Find Swing Direction}

if upsw=1 then begin

if H&gt;hH then hH=H; {update hH, hL}

if L&gt;hL then hL=L;

if H&lt;hL then begin {swing changes to down}

upsw=0;

lL=L;

lH=H;

end;

end;

if upsw=0 then begin

if L&lt;lL then lL=L; {update lL, lH}

if H&lt;lH then lH=H;

if L&gt;lH then begin {swing changes to up}

upsw=1;

hH=H;

hL=L;

end;

end;

if upsw=1 then plot1(hL, “SwLine”, cyan);

if upsw=0 then plot1(lH, “SwLine”, magenta);
``````

Your posted code is Easy Language code but it is not AFL (AmiBroker Formula Language). That's why you get lots of errors.

You have to translate it to AFL to make it to work in AmiBroker.

Well, clear method exists already in AFL. Look here

1 Like
``````LISTING 1

upsw = 0;
Hh = Lh = H[ 0 ];
Hl = Ll = L[ 0 ];

for( i = 0; i < BarCount; i++ )
{
Ch = H[ i ];
Cl = L[ i ];

if( upsw == 1 )
{
Hh = Max( Ch, Hh );
hL = Max( Cl, Hl );

if( Ch < Hl )
{
upsw = 0;
Ll = Cl;
Lh = Ch;
}
}

if( upsw == 0 )
{
Ll = Min( Cl, Ll );
Lh = Min( Ch, Lh );

if( Cl > Lh )
{
upsw = 1;
Hh = Ch;
Hl = Cl;
}
}

Hla[ i ] = Hl;
Lha[ i ] = Lh;
upswa[ i ] = upsw;
}

Plot( IIf( upswa == 1, Hla, Null ), "SwLine", ColorRGB( 64, 128, 128), styleThick );
Plot( IIf( upswa == 0, Lha, Null ), "SwLine", ColorRGB( 128, 64, 128), styleThick  );

Plot( C, "Price", IIf( upswa == 1,
ColorBlend( colorGreen, colorWhite ),
ColorBlend( colorRed, colorWhite )), styleBar);
``````

Helo,

I'm finding trouble to tweak this "clear method" AFL to use scan stocks. Where to insert Buy/Sell formula in this AFL? Anyone please look into this request.

Thanks,