Announcement

Collapse
No announcement yet.

syntax error

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • syntax error

    I don't understand where this error is coming from:
    " 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 
    vSIGnull;    // 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(0PS_DOT1Color.black);
        
    addBand(-2PS_SOLID1Color.lime);
        
    addBand(2PS_SOLID1Color.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(nLengthnSmoothnBars) {
    if (
    bInit==false) {
        
    vPCT osc(1,nLengthfalse);
        
    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.CLOSEStrategy.THISBAR);
                
    bc=0;
            } else 
    bc += 1;
        } else 
            if(
    vP1>vS1 && vP0<=vS0) {
                
    setBarBgColor(Color.green);
                
    Strategy.doShort("Enter"Strategy.CLOSEStrategy.THISBAR);
                
    bc=1;
            }
            
        return new Array (
    vPCT.getValue(0), vSIG.getValue(0));
        

    Last edited by pj909; 09-06-2008, 09:36 AM.

  • #2
    Re: syntax error

    pj909
    The error is caused by the upper case I in If which should be if
    Keep in mind that JavaScript is a case sensitive language
    Alex


    Originally posted by pj909
    I don't understand where this error is coming from:
    " 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 
    vSIGnull;    // 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(0PS_DOT1Color.black);
        
    addBand(-2PS_SOLID1Color.lime);
        
    addBand(2PS_SOLID1Color.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(nLengthnSmoothnBars) {
    if (
    bInit==false) {
        
    vPCT osc(1,nLengthfalse);
        
    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.CLOSEStrategy.THISBAR);
                
    bc=0;
            } else 
    bc += 1;
        } else 
            if(
    vP1>vS1 && vP0<=vS0) {
                
    setBarBgColor(Color.green);
                
    Strategy.doShort("Enter"Strategy.CLOSEStrategy.THISBAR);
                
    bc=1;
            }
            
        return new Array (
    vPCT.getValue(0), vSIG.getValue(0));
        

    Comment

    Working...
    X