I don't understand where this error is coming from:
" missing ; before statement :
If (Strategy.isShort() == true ) { "
The error is in line 50.
" missing ; before statement :
If (Strategy.isShort() == true ) { "
The error is in line 50.
PHP Code:
// 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 vSIG= null; // the MA of vPCT
var bInit = false;
var vP0=null;
var vP1=null;
var vS0=null;
var vS1=null;
var bc=0;
function preMain()
{
setStudyTitle("Distance from Trend");
setCursorLabelName("DFT",0);
setDefaultBarFgColor(Color.blue,0);
setDefaultBarFgColor(Color.red,1);
addBand(0, PS_DOT, 1, Color.black);
addBand(-2, PS_SOLID, 1, Color.lime);
addBand(2, PS_SOLID, 1, Color.magenta);
var fp1 = new FunctionParameter("nLength", FunctionParameter.NUMBER);
fp1.setName("MA2 Length");
fp1.setLowerLimit(1);
fp1.setDefault(5);
var fp2 = new FunctionParameter("nSmooth", FunctionParameter.NUMBER);
fp2.setName("Smoothing");
fp2.setLowerLimit(1);
fp2.setDefault(2);
var fp3 = new FunctionParameter("nBars", FunctionParameter.NUMBER);
fp3.setName("Bars");
fp3.setLowerLimit(1);
fp3.setDefault(1);
}
function main(nLength, nSmooth, nBars) {
if (bInit==false) {
vPCT = osc(1,nLength, false);
vSIG = ema(nSmooth,vPCT);
bInit=true;
}
vP0=vPCT.getValue(0);
vP1=vPCT.getValue(-1);
vS0=vSIG.getValue(0);
vS1=vSIG.getValue(-1);
If (Strategy.isShort() == true ) {
If (bc=nBars) {
Strategy.doCover("Exit", Strategy.CLOSE, Strategy.THISBAR);
bc=0;
} else bc += 1;
} else
if(vP1>vS1 && vP0<=vS0) {
setBarBgColor(Color.green);
Strategy.doShort("Enter", Strategy.CLOSE, Strategy.THISBAR);
bc=1;
}
return new Array (vPCT.getValue(0), vSIG.getValue(0));
}
Comment