// Downloaded From https://www.WiseStockTrader.com
// Jose Silva's code ported on 28th April 2010 8:36 pm by xyte@inditraders

pds = Param("EMA Periods", 21, 1, 2520, 1);
Period= ParamList("Use as Input","Open|High|Low|Close|Volume",1);


if(Period=="Open"){x=Open;}
if(Period=="High"){x=High;}
if(Period=="Low"){x=Low;}
if(Period=="Close"){x=Close;}
if(Period=="Volume"){x=Volume;}

//Indicator
EMAx=EMA(x,pds);

//Slope
EMAprev=Ref(EMAx,-1);
y=Min(EMAx,EMAprev)/Max(EMAx,EMAprev);
EMAratio=(IIf(EMAx>EMAprev,2-y,y)-1)*100;
EMAper=IIf(EMAratio < 0, atan2(EMAratio,1)-360, atan2(EMAratio,1))*10/9; //This is where the problem lies
Signalx=EMA(EMAper,pds);

//Plots
Plot(Signalx, "Signal", colorGreen, styleLine|styleThick);
Plot(EMAper, "EMAper", colorRed, styleLine|styleThick);