Announcement

Collapse
No announcement yet.

Syntax Error

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

  • Syntax Error

    I'm hung up on the following code:

    if (Strategy.isInTrade() == false) {

    if (close(-1) < low(-2) &&
    close(-2) < low(-3) &&
    close(-3) < low(-4) &&
    close() > high (-3)) {

    nNewTrade = 1; // New Trade Trigger
    nsignal = 1; // Buy Signal - Trade Type
    }
    The first line gets the syntax error message. I use this line at other places in the program ahead of this spot and it seems to be OK. Anybody know how to resolve this?

    PS The reply to the "max" post was resolved with the Math.max. Thanks.

  • #2
    pjwinner
    As far as I can see what you posted is correct (and does not return at my end a syntax error when inserted in a sample efs).
    The error may be after those lines and incoirrectly assigned by the syntax checker to the first line but without seeing the rest of the script it is difficult to tell.
    Having said that in the example you are missing a } bracket to close the first if statement.
    As an aside you can also write the first line as if(!Strategy.isInTrade()){
    Alex

    Comment


    • #3
      Syntax Error

      I'm a newbie to EFS and the Bulletin Boards. Would it be acceptable and useful to post the whole formula or perhaps just what follows the Syntax Error as I continue to try to resolve this?

      Comment


      • #4
        pjwinner
        Absolutely yes post the whole script as it makes it a lot easier
        Alex

        Comment


        • #5
          Syntax Error

          Here's the WHOLE Thing:


          /*----------------------------------------------------------
          This is a 3 Point Break Strategy. It is cobbled together from a number of EFS sources.

          ----------------------------------------------------------*/

          var nNewTrade; // New Trade Trigger 0 = OFF / 1 = ON
          var nsignal; // returns the direction of the trading signal
          var nTradeEntryPrice;

          var nStopLevel;function preMain() {
          setPriceStudy(true);
          setStudyTitle("PB3");
          setCursorLabelName("PB3");
          setColorPriceBars(true); //ADDED
          setDefaultPriceBarColor(Color.grey); //ADDED
          }


          function main() {
          /*----------------------------------------------------------------
          // If new trade, get entry price - used for our profit target
          ----------------------------------------------------------
          This portion of the code identifies if a new trade has been issued
          and records the entry price of our trade. If no new trade has been
          triggered (nNewTrade == 1), then this portion of the code is ignored.
          ----------------------------------------------------------*/



          if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
          // This sets the expected entry price of the current short trade
          nTradeEntryPrice = open();
          // This switches off the nNewTrade variable
          nNewTrade = 0; // Turn off NEW TRADE switch

          }




          /*-----------------------------------------------
          This portion of the code tests for a stop level breach and
          executes trades accordingly.
          ----------------------------------------------------------*/
          if (Strategy.isInTrade() == true && (Strategy.isShort() == true)) {
          // Check if the profit target has been reached/breached
          if (high() >= nStopLevel) {
          // Stop Breached, Execute Cover order.
          Strategy.doCover("Short Stop Exit", Strategy.STOP, Strategy.THISBAR,
          Strategy.ALL, nStopLevel);
          }
          }

          if (Strategy.isInTrade() == true && (Strategy.isLong() == true)) {
          // Check if the profit target has been reached/breached
          if (low() <= nStopLevel) {
          // Stop Breached, Execute Sell order.
          Strategy.doSell("Long Stop Exit", Strategy.STOP, Strategy.THISBAR,
          Strategy.ALL,nStopLevel);
          }
          }



          -


          /*----------------------------------------------------------------
          // Identify new trade signals
          ----------------------------------------------------------------- */

          if (Strategy.isInTrade() == false) {


          if (close(-1) < low(-2) &&
          close(-2) < low(-3) &&
          close(-3) < low(-4) &&
          close() > high (-3)) {


          nNewTrade = 1; // New Trade Trigger
          nsignal = 1; // Buy Signal - Trade Type
          }

          if ( close(-1) > high(-2) &&
          close(-2) > high(-3) &&
          close(-3) > high(-4) &&
          close() < low(-3)) {


          nNewTrade = 1; // New Trade Trigger
          nsignal = -1; // Sell Signal - Trade Type

          }
          var bPosition = false; //ADDED
          if (Strategy.isInTrade() == true) { //ADDED
          var bPosition = true;
          if (Strategy.isLong() == true) setPriceBarColor(Color.lime); //ADDED
          if (Strategy.isShort() == true) setPriceBarColor(Color.red); //ADDED
          }
          }


          /*----------------------------------------------------------------
          // Execute Trades ONLY if nNewTrade is triggered ....
          ----------------------------------------------------------------- */

          if (nNewTrade == 1) { //Execute New Trade
          // new or reversed trade position
          if (Strategy.isInTrade() == true) {
          if ((nsignal > 0) && (Strategy.isShort() == true)) {
          Strategy.doCover("Exit Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
          Strategy.doLong("Rev Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.NEXTBAR,Strategy.getDefaultLotSize() * 3);
          nStopLevel = low(-1) - 5.0;
          lowest = low(-1);
          }
          if ((nsignal < 0) && (Strategy.isLong() == true)) {
          Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR, Strategy.ALL);
          Strategy.doShort("Rev Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.NEXTBAR,Strategy.getDefaultLotSize() * 3);
          nStopLevel = high(-1) + 5.0;
          highest = high(-1);
          }
          } else {
          if ((nsignal > 0)) {
          Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR,Strategy.getDefaultLotSize() * 3);
          nStopLevel = low(-1) - 5.0;
          lowest = low(-1);
          }
          if ((nsignal < 0)) {
          Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR, Strategy.NEXTBAR,Strategy.getDefaultLotSize() * 3);
          nStopLevel = high(-1) + 5.0;
          highest = high(-1);
          }
          } // end if IN TRADE
          } // END EXECUTE NEW TRADE
          };

          //<![endif]>

          Comment


          • #6
            pjwinner
            Enclosed is the script with the syntax errors corrected.
            There was an extra character (ie -) in the space between the portion that checks for the breach and the section that follows. There were a couple of } in the wrong places and a few doubled up Strategy.NEXTBAR in the Execute trades section
            As an aside you may find it easier to develop a script if you use indentation
            Alex

            PHP Code:
            var nNewTrade// New Trade Trigger 0 = OFF / 1 = ON
            var nsignal// returns the direction of the trading signal
            var nTradeEntryPrice;
            var 
            nStopLevel;

            function 
            preMain() {

                
            setPriceStudy(true);
                
            setStudyTitle("PB3");
                
            setCursorLabelName("PB3");
                
            setColorPriceBars(true); //ADDED
                
            setDefaultPriceBarColor(Color.grey); //ADDED
            }

            function 
            main() {

            /*----------------------------------------------------------------
            // If new trade, get entry price - used for our profit target
            ----------------------------------------------------------
            This portion of the code identifies if a new trade has been issued 
            and records the entry price of our trade. If no new trade has been 
            triggered (nNewTrade == 1), then this portion of the code is ignored.
            ----------------------------------------------------------*/

                
            if (Strategy.isInTrade() == true && (nNewTrade == 1)) {
                    
            // This sets the expected entry price of the current short trade
                    
            nTradeEntryPrice open();
                    
            // This switches off the nNewTrade variable
                    
            nNewTrade 0// Turn off NEW TRADE switch
                
            }

            /*-----------------------------------------------
            This portion of the code tests for a stop level breach and 
            executes trades accordingly.
            ----------------------------------------------------------*/

                
            if (Strategy.isInTrade() == true && Strategy.isShort() == true) {
                    
            // Check if the profit target has been reached/breached
                    
            if (high() >= nStopLevel) {
                        
            // Stop Breached, Execute Cover order.
                        
            Strategy.doCover("Short Stop Exit"Strategy.STOPStrategy.THISBARStrategy.ALLnStopLevel);
                    }
                }

                if (
            Strategy.isInTrade() == true && Strategy.isLong() == true) {
                    
            // Check if the profit target has been reached/breached
                    
            if (low() <= nStopLevel) {
                        
            // Stop Breached, Execute Sell order.
                        
            Strategy.doSell("Long Stop Exit"Strategy.STOPStrategy.THISBARStrategy.ALL,nStopLevel);
                    }
                }

            /*----------------------------------------------------------------
            // Identify new trade signals
            ----------------------------------------------------------------- */

                
            if (Strategy.isInTrade() == false) { 
                    if (
            close(-1) < low(-2) && close(-2) < low(-3) && close(-3) < low(-4) && close() > high (-3)) {
                        
            nNewTrade 1// New Trade Trigger
                        
            nsignal 1// Buy Signal - Trade Type
                    

                    if ( 
            close(-1) > high(-2) && close(-2) > high(-3) && close(-3) > high(-4) && close() < low(-3)) {
                        
            nNewTrade 1// New Trade Trigger
                        
            nsignal = -1// Sell Signal - Trade Type
                    
            }
                }
                
                var 
            bPosition false//ADDED
                
                
            if (Strategy.isInTrade() == true) { //ADDED
                    
            var bPosition true;
                }
                if (
            Strategy.isLong() == true) {
                    
            setPriceBarColor(Color.lime); //ADDED
                
            }
                if (
            Strategy.isShort() == true) {
                    
            setPriceBarColor(Color.red); //ADDED
                
            }

            /*----------------------------------------------------------------
            // Execute Trades ONLY if nNewTrade is triggered ....
            ----------------------------------------------------------------- */

                
            if (nNewTrade == 1) { //Execute New Trade
                    // new or reversed trade position
                    
            if (Strategy.isInTrade() == true) {
                        if ((
            nsignal 0) && Strategy.isShort() == true) {
                            
            Strategy.doCover("Exit Short"Strategy.MARKETStrategy.NEXTBARStrategy.ALL);
                            
            Strategy.doLong("Rev Long"Strategy.MARKETStrategy.NEXTBARStrategy.getDefaultLotSize() * 3);
                            
            nStopLevel low(-1) - 5.0;
                            
            lowest low(-1);
                        }
                        if (
            nsignal && Strategy.isLong() == true) {
                            
            Strategy.doSell("Exit Long"Strategy.MARKETStrategy.NEXTBARStrategy.ALL);
                            
            Strategy.doShort("Rev Short"Strategy.MARKETStrategy.NEXTBARStrategy.getDefaultLotSize() * 3);
                            
            nStopLevel high(-1) + 5.0;
                            
            highest high(-1);
                        }
                    } else {
                        if (
            nsignal 0) {
                            
            Strategy.doLong("Go Long"Strategy.MARKETStrategy.NEXTBAR,Strategy.getDefaultLotSize() * 3);
                            
            nStopLevel low(-1) - 5.0;
                            
            lowest low(-1);
                        }
                        if (
            nsignal 0) {
                            
            Strategy.doShort("Go Short"Strategy.MARKETStrategy.NEXTBARStrategy.getDefaultLotSize() * 3);
                            
            nStopLevel high(-1) + 5.0;
                            
            highest high(-1);
                        }
                    } 
            // end if IN TRADE
                
            // END EXECUTE NEW TRADE
            }
            //<![endif]> 

            Comment

            Working...
            X