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>hH then hH=H; {update hH, hL}
if L>hL then hL=L;
if H<hL then begin {swing changes to down}
upsw=0;
lL=L;
lH=H;
end;
end;
if upsw=0 then begin
if L<lL then lL=L; {update lL, lH}
if H<lH then lH=H;
if L>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);

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.