Can someone help? I guess I'm missing something pretty basic here because this doesn't work.
Also, is it possible to plot the MA on the chart within the same efs. i.e. combine a price study with a non-price study
// Show the distance from the trend (a moving average of price)
// as a percent above or below the trend and add a MA of the percent
var nLength = null;
var vMA = null;
var vPCT = null; // distance from trend as a percent
var nSmooth = null;
var vDFT= null; // the MA of vPCT
function preMain()
{
setStudyTitle("Distance from Trend");
setCursorLabelName("DFT",0);
setDefaultBarFgColor(Color.navy,0);
addBand(0, PS_SOLID, 1, Color.black);
addBand(-3, PS_SOLID, 1, Color.lime);
addBand(3, PS_SOLID, 1, Color.magenta);
var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(50);
var fp1 = new FunctionParameter("nSmooth", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(10);
}
function main(nLength, nSmooth)
{
var vMA = sma(nLength,"close")
var vPCT = (close()/vMA-1)*100
var vDFT = new MAStudy(nSmooth, 0, vPCT, MAStudy.Simple);
return new array(vPCT(0), vDFT(0).getvalue(MAStudy.MA) ) ;
}
Also, is it possible to plot the MA on the chart within the same efs. i.e. combine a price study with a non-price study
// Show the distance from the trend (a moving average of price)
// as a percent above or below the trend and add a MA of the percent
var nLength = null;
var vMA = null;
var vPCT = null; // distance from trend as a percent
var nSmooth = null;
var vDFT= null; // the MA of vPCT
function preMain()
{
setStudyTitle("Distance from Trend");
setCursorLabelName("DFT",0);
setDefaultBarFgColor(Color.navy,0);
addBand(0, PS_SOLID, 1, Color.black);
addBand(-3, PS_SOLID, 1, Color.lime);
addBand(3, PS_SOLID, 1, Color.magenta);
var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(50);
var fp1 = new FunctionParameter("nSmooth", FunctionParameter.NUMBER);
fp1.setName("Length");
fp1.setLowerLimit(1);
fp1.setDefault(10);
}
function main(nLength, nSmooth)
{
var vMA = sma(nLength,"close")
var vPCT = (close()/vMA-1)*100
var vDFT = new MAStudy(nSmooth, 0, vPCT, MAStudy.Simple);
return new array(vPCT(0), vDFT(0).getvalue(MAStudy.MA) ) ;
}
Comment