Magic Trend code in Pi

Hello

Can somebody help me get tradescript/pi code equivalent of the following amibroker afl?
Many thanks.

SetBarsRequired(sbrAll,sbrAll);
SetFormulaName( “Magic Trend Indicator” );

P = Param(“Period”,20,2,25,1);
m = Param(“Multiplier”,2,0.1,5,0.1);

A = ATR§;

for(i=0;i<P;i++)
{
S[i] = C[i]-m*(A[i]);
T[i] = 1;
}

for(i=P;i<BarCount;i++)
{
if(C[i] > S[i-1])
{
if(T[i-1]==1)
{
S[i] = Max(C[i] - mA[i],S[i-1]);
T[i] = 1;
}
else
{
S[i] = C[i] - m
A[i];
T[i] = 1;
}

}
else
{
	if(T[i-1]==-1)
	{
		S[i] = Min(C[i] + m*A[i],S[i-1]);
		T[i] = -1;
	}
	else
	{
		S[i] = C[i] + m*A[i];
		T[i] = -1;
	}
}

}

Buy = Cover = C>S;
Short = Sell = C<S;

Plot(S,“STOP”,IIf(C>S,colorBlue,colorRed),styleDots|styleStaircase|styleThick );

Buy = ExRem(Buy,Sell OR Short);
Sell = ExRem(Sell,Buy);
Short = ExRem(Short,Cover OR Buy);
Cover = ExRem(Cover,Short);

BuyPrice = ValueWhen(Buy,C,1);
SellPrice = ValueWhen(Sell,C,1);
ShortPrice = ValueWhen(Short,C,1);
CoverPrice = ValueWhen(Cover,C,1);

if (SelectedValue(Buy)==1) Say("BUY above "+int(S));
if (SelectedValue(Sell)==1) Say("Sell below "+int(S));

Offset = -12;

PlotShapes(BuyshapeUpArrow,colorBlue,0,S,Offset);
PlotShapes(Short
shapeDownArrow,colorRed,0,S,Offset);
PlotShapes(CovershapeHollowUpArrow,colorBlue,0,S,Offset);
PlotShapes(Sell
shapeHollowDownArrow,colorRed,0,S,Offset);

SetChartOptions(0,chartShowArrows|chartShowDates);
//_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
PlotOHLC(O,H,L,C,“Close”,colorDefault,styleCandle);

//Magfied Market Price
FS=Param(“Font Size”,30,11,70,1);
GfxSelectFont(“Times New Roman”, 20, 700, True );
GfxSetBkMode( colorBlack );
GfxSetTextColor( ParamColor(“Color”,colorBlue) );
Hor=Param(“Horizontal Position”,800,1,1200,1);
Ver=Param(“Vertical Position”,12,1,830,1);
GfxTextOut("Brk: "+int(S), 350 , 10 );

YC=TimeFrameGetPrice(“C”,inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
GfxSelectFont(“Times New Roman”, 14, 700, True );
GfxSetBkMode( colorBlue );
// GfxSetTextColor(ParamColor(“Color”,colorBlue) );
// GfxTextOut(""+DD+" ("+xx+"%)", Hor , Ver+45 );
GfxSetTextColor( ParamColor(“Color”,colorBlue) );
GfxTextOut(date(), Hor+150, Ver+15 );
GfxTextOut("CMP: "+int©, 350 , 40 );

_SECTION_END();