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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        63 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        35 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        54 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        61 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        48 views
        0 likes
        Last Post CarlTrading  
        Working...
        X