Announcement

Collapse
No announcement yet.

Syntax error with stop and limit attempt

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

  • Syntax error with stop and limit attempt

    Hi!

    I want to create a very simple (KISS!) stop and limit. I don't go for all these elaborate indicators like Donchian Channels (whatever they are). My strategy is a simple opening range breakout system where both the profit target and the stop are 100 points away from the entry price.

    So, I created a variable called nEntryPrice like so:

    Code:
    var nEntryPrice;
    Then once price has broken the opening range nEntryPrice is assigned the value of the current bar's open like so:

    Code:
    if(!Strategy.isLong()) {
    Strategy.doLong("Long Break", Strategy.CLOSE, Strategy.THISBAR);
    nEntryPrice = open(0);
    }
    So far, so good. However, I then try to set my stop and limit using the following code:

    Code:
    if(Strategy.isLong) && (close(0) > nEntryPrice + 100)  || (close(0)  < nEntryPrice - 100) {
    Strategy.doSell("Long Exit", Strategy.MARKET, Strategy.THISBAR);
    }
    but unfortunately this line of code gives me a syntax error. What I am I doing wrong?
    Last edited by onetouch; 01-14-2007, 05:00 PM.

  • #2
    Hi onetouch,

    From what I can tell, the syntax error in your 'if statement' is likely due to the parenthesis structure. There is also an issue with your Strategy.isLong() method call.

    if(((Strategy.isLong()) && (close(0) > (nEntryPrice + 100))) || (close(0) < (nEntryPrice - 100))){


    }


    Take a look at the EFS & Backtest docs link. There are other links below that may help as well.

    Comment


    • #3
      Thanks, that got rid of the syntax error. The code doesn't work the way I want it to (as I expected) but at least I have something to work with now.

      I've read all the files you suggested several times but I'm finding it very hard going to backtest my very simple system. The documentation uses Donchian channels to illustrate but I find it difficult to port that over to my simple 100 point stop and limit system.
      Last edited by onetouch; 01-14-2007, 06:00 PM.

      Comment


      • #4
        You are welcome.

        Here is another link to some backtest code that is saved in the fileshare. I am not sure if all of these examples are referenced in the tutorials, regardless, this is a direct link.

        Comment

        Working...
        X