Hi--I have a simple one: What code to add to go Long if it crosses the zero line + and go short if it crosses the zero line to make it a backtestable strategy. Thanks
==================================
var ma = null;
function preMain()
{
setStudyTitle("Z-Score");
setCursorLabelName("Z-Score", 0);
setDefaultBarFgColor(Color.red, 0);
addBand(0, PS_SOLID, 1, Color.lightgrey);
}
function main(Period) {
var StdDev = 0;
var SumSqr = 0;
var counter = 0;
if(Period == null)
Period = 20;
if(ma == null)
ma = new MAStudy(Period, 0, "Close", MAStudy.SIMPLE);
for(counter = - Period + 1; counter <= 0; counter++)
SumSqr += Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);
StdDev = Math.sqrt(SumSqr / Period);
return (close() - ma.getValue(MAStudy.MA)) / StdDev;
}
==================================
var ma = null;
function preMain()
{
setStudyTitle("Z-Score");
setCursorLabelName("Z-Score", 0);
setDefaultBarFgColor(Color.red, 0);
addBand(0, PS_SOLID, 1, Color.lightgrey);
}
function main(Period) {
var StdDev = 0;
var SumSqr = 0;
var counter = 0;
if(Period == null)
Period = 20;
if(ma == null)
ma = new MAStudy(Period, 0, "Close", MAStudy.SIMPLE);
for(counter = - Period + 1; counter <= 0; counter++)
SumSqr += Math.pow((close(counter) - ma.getValue(MAStudy.MA)),2);
StdDev = Math.sqrt(SumSqr / Period);
return (close() - ma.getValue(MAStudy.MA)) / StdDev;
}
Comment