AFL to Pi Code - RSI Divergence

Hi,

I have an AFL, but can some 1 please convert the same into Pi Compatabile Language so i can use as a scanner to Filter stocks on any time frame

GraphXSpace=7;
//n=Param("% Reverse ",12,0,100,1);
n=Optimize(“ZIG”,9,5,50,1);
per=Optimize(“rsi”,28,5,50,1);
Buy=Sell=0;
Var = Zig(RSI(per), n);
t= Trough(RSI(per), n, 1);
p= Peak(RSI(per), n, 1);
x[0] =Var[0];
price[0] = C[0];
j=0;

// bearish divergence
for ( i=0; i<BarCount; i++)
{
if(Var[i] == p[i])
{

j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] <x[j-1] && price[j-1]< price[j])
Sell[i] =1;
}
}

// bullish divergence
for ( i=0; i<BarCount; i++)
{
if(Var[i] == t[i])
{
j++;
x[j] =Var[i];
price[j] =C[i];
if(x[j] >x[j-1] && price[j]<price[j-1])
Buy[i] =1;
}
}
Short=Sell;
Cover=Buy;

Plot(Var, “”, 39);
PlotShapes ( IIf(Sell, shapeSmallCircle, shapeNone), colorRed, 0 , Var,0);
PlotShapes( IIf(Buy, shapeSmallCircle, shapeNone), colorBrightGreen, 0, Var,0);

Title =“RSI Divergence” ;
_SECTION_END();

_SECTION_BEGIN(“TEMA”);
P = ParamField(“Price field”,-1);
Periods = Param(“Periods”, 15, 2, 200, 1, 10 );
Plot( TEMA( P, Periods ), _DEFAULT_NAME(), ParamColor( “Color”, colorCycle ), ParamStyle(“Style”) );
_SECTION_END();

Divergence is bit more tricky. Guess it can’t be done in tradescript. Don’t loose hope though! Somebody else may have better answer:)

Why dont you try using Pi-bridge -