Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Backtesting Strategy: Possible to buy at start of bar and get that bar's Open price?

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

    Backtesting Strategy: Possible to buy at start of bar and get that bar's Open price?

    Hey all!
    Just been coding a strategy for backtesting purposes and I've hit a wall. I'm currently using end of day data, in a 1 day candlestick chart, btw.

    So is it possible to get the Open price of a bar, and then put in a buy, which would execute at the start of that same day? For example this code:
    Code:
    protected override void OnBarUpdate() {
    if (Time[0].DayOfWeek == DayOfWeek.Wednesday) {
    EnterLong(DefaultQuantity, "");
    )
    if (Time[0].DayOfWeek == DayOfWeek.Thursday) {
    ExitLong;
    )
    }
    executes the trade on Thursday's open, and exits the trade on Friday's close. Is there a way around this?

    I did try and shift the days back, which results in the correct days being executed, but then I can't access the Open price on Wednesday.

    Any ideas?

    Thanks for the help, Tim.

    #2
    Hello Tim,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    The bars are historical in backtesting so the calculations are done on the close of the bar, so the OnBarUpdate() method does not see that it is Wednesday's Daily bar until it closes. Unfortunately, there is no method around this for all bar types, however you can use Market Replay to replay the market and test your strategy in replay: http://www.ninjatrader.com/support/h...ket_replay.htm

    Comment


      #3
      Thanks for getting back to me.

      Is there a list somewhere with the instruments and dates that are available with replay data that can be downloaded?

      Comment


        #4
        Hello Tim,

        Thank you for your response.

        Unfortunately, no such list exists.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        648 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        369 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        572 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X