Announcement

Collapse
No announcement yet.

add exit condition

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

  • add exit condition

    Good morning to everybody,

    On the Back Testing Tutorial 2

    Could somebody please explain the difference between this
    fixed stop exit Strategy

    if (open(0) <= nStop) {
    Strategy.dosell("Long Stop", Strategy.MARKET, Strategy.THISBAR);
    bExitFlag = true;

    and.....

    }else if (low(0) <= nStop) {
    Strategy.doSell("Long Stop" , Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);

    what does each of the do?

    thanks a lot...

    Jaime

  • #2
    Jaime
    The first condition checks if the Open of the bar is equal to or below the stop in which case it closes the trade using the Open as the exit price.
    If instead the Open is above the bar then the strategy uses the next condition and checks if the Low of the bar is equal to or below the stop in which case it uses the stop as the exit price of the trade.
    Alex

    Comment


    • #3
      Re: add exit condition

      Originally posted by jaimeog
      Good morning to everybody,

      On the Back Testing Tutorial 2

      Could somebody please explain the difference between this
      fixed stop exit Strategy

      if (open(0) <= nStop) {
      Strategy.dosell("Long Stop", Strategy.MARKET, Strategy.THISBAR);
      bExitFlag = true;

      and.....

      }else if (low(0) <= nStop) {
      Strategy.doSell("Long Stop" , Strategy.STOP, Strategy.THISBAR, Strategy.ALL, nStop);

      what does each of the do?

      thanks a lot...

      Jaime
      Jamie,

      It may help to keep in mind that the strategy object or "backtester" is being invoked for the most part when a bar is completed.

      So if you have a long position there is a possibility that the open of the next bar will actually be lower then your stop price, possibly significantly lower. If only the second case is coded, then the reported exit price will be at the exact level of your stop price.

      Since there was a price gap, there is no way realistically that you would have gotten out at that price, because the market gapped through it (which definately can and will happen if you trade long enough).

      So the first case is testing for that gap condition and executes the exit trade specifying MARKET-THISBAR, which again because the strategy object is looking at complete bars only, has no way of knowing where the "market" price was intrabar, and reports the trade price at the OPEN of the current bar, which for gaps is a realistic price.

      Hope this helps....and BTW, it's certainly wise to study as closely as possibility, as you are doing those backtesting tutorials, as they are IMHO invaluable and very well written and thought out and should be followed as closely as possible.
      Glen Demarco
      [email protected]

      Comment


      • #4
        Alexis,

        I did not see your reponse until after I repsonded, sorry about that.
        Glen Demarco
        [email protected]

        Comment


        • #5
          thanks a lot

          demarcog and Alexis,

          thanks a lot for you help,

          everything is clear now...

          have a great day,

          Jaime

          Comment

          Working...
          X