After evaluating the code, found that the TradeStation not that easy to convert to Amibroker. Cause CoefficientR() function is private to TradeStation. Not many programmer able to do it. so the R is automatic calculated.
For easy way, here the Metastock Version, but you need to manually key in the R value.
For easy way, here the Metastock Version, but you need to manually key in the R value.
PHP:
Length = Param("30 day historical volatility", 30, 3);
r=Param("Correlation coefficient of these securities",0.5,0,100);
Vf=Param("Volatility factor",1.5, 0,5);
Ticker2= ParamStr("2nd Ticker to Compare", "D05");
p1= C;
p2= Foreign(Ticker2, "Close");
hv1=StDev(Log(p1/Ref(p1, -1)), Length);
hv2=StDev(Log(p2/Ref(p2, -1)), Length);
newday=ROC(DayOfWeek(),1) !=0;
yp1=ValueWhen(newday, Ref(p1,-1));
yp2=ValueWhen(newday, Ref(p2,-1));
sprd= (p1/yp1) - (p2/yp2);
vb=vf*(hv1 + hv2) * sqrt(1/252) * (1-r);
Plot(sprd, "Spread", colorAqua, styleNoLabel);
Plot(vb, "UpperVB", colorRed);
Plot(-vb, "LowerVB", colorLime);
PlotGrid(0,colorGrey50);
Sorry my Net went down so couldn't reply. Thank you so much for the help.
The above code as you said is from the Metastock version , it is still wonderful for me as I will now be able to backtest in the real trading time. I will read the article and then manually backtest things.
Much Thanks to your humble replies. :clapping:
Regards.