Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtest, Stop orders and trend lines

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

    Backtest, Stop orders and trend lines

    Though I have done a lot of indicator programming, I started strategy programming and backtesting only recently. Therefore I would greatly appreciate if someone could point me in the right direction.

    What I want to do in my strategy is buy at stop, with the stop price being the trend line value at the bar. For real time trading I would code this like:

    Code:
    CalculateOnBarClose = false;
    .
    .
    If (FirstTickOfBar)
      If (Close[0] >  trendLineValue) EnterLong(1, entryString);
      else EnterLongStop(1, trendLineValue, entryString);
    To make sure that the stop entry order is not rejected if the open of the bar is above the stop price, which is quite common if the trend line is sloping down.

    In the backtest strategy code I just wrote

    Code:
    EnterLongStop(1, trendLineValue, entryString);
    because I read in some threads in this forum, that in backtest, orders are always processed at the bar following the signal bar.

    When I looked at the backtest chart, I saw that the entries were not where I would have expected them to be, would it have been real time trading.

    There surely must be a simple workaround for this kind of problem, but so far I just couldn't find out what it is.

    #2
    Hello Cugel,

    Thank you for your post.

    You are likely running into the fact that Backtesting in the Strategy Analyzer will always be CalculateOnBarClose = True as the Backtest is done on Historical Data which only has the Open, High, Low and Close and not each tick that created the bar.

    However, there is a method to simulate an intra-bar fill. You can view this method at the following link: http://www.ninjatrader.com/support/f...ead.php?t=6652

    Please let me know if I may be of further assistance.
    Last edited by NinjaTrader_PatrickH; 11-13-2012, 01:02 PM.

    Comment


      #3
      Patrick,

      thank you for your quick reply. I've already downloaded the sample strategy and taken a look at it. That is exactly what I had been looking for.

      The entry of the replay/real time was systematically earlier than the entry on the backtest. With some additional coding, I'm hoping to get a much better match between backtest and replay now.

      Comment


        #4
        Hello Cugel,

        I am glad to hear that will work for you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        649 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        370 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        109 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        574 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        576 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X