Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical Trades Showing On Wrong Chart Bar

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

    Historical Trades Showing On Wrong Chart Bar

    Hi,

    I have a strategy that runs on daily bars, and I'm add()'ing a 1 minute bar series in Initialize() so I can book a trade using intrabar granularity.

    I check to see if my condition is hit using the 1 minute bar (BarsInProgress != 0) and I look 2 minutes before the close of the daily bar (determined using Bars.Session.NextEndTime). If my condition is met, I book the trade using the secondary bar (EnterLong(1,numberOfContracts, longName1)).

    When I run my strategy on a chart (or backtest), the date and time of the trade shown on the Executions tab for all of the historical trades shows the correct date and time of the trade (1 minute before the end time for the daily bar in the current day).

    However on the chart, the trade is always shown on the bar for the next day, even though the trade was executed during the bar for the current day.

    Is there any way to make the trade show on the correct bar on the chart ?

    Bob A.

    #2
    Hi Bob, please add Print statements to your strategy code to check in which sequence the BIP's are updated / called.

    Comment


      #3
      Hi Bertrand,

      I've attached a file showing the trace using Print statements along with pictures of the chart and the Executions grid (from the strategy tester).

      BIP=0 is the daily bar, and the Print is done using:

      str = "BIP=" + BarsInProgress + " " + Time + " " + Instrument.FullName
      + " Bar Entry at " + DateTime.Now.ToString()
      + " " + BarsPeriod.Value + " " + BarsPeriod.Id
      + " " + currentState
      + " Close " + Close[0].ToString()
      + " Avg High " + avgHigh + " Avg Low " + avgLow
      + " Position " + Position.MarketPosition + " " + Position.Quantity;
      if (longTradePending == true)
      str += " LongPending ";
      if (inLongTrade == true)
      str += " inLong ";
      if (shortTradePending == true)
      str += " ShortPending ";
      if (inShortTrade == true)
      str += " inShort ";
      if (longDoneForDay == true)
      str += " LongDoneForDay ";
      if (shortDoneForDay == true)
      str += " ShortDoneForDay ";

      BIP=1 is the 1 Minute bar, and the Print is done using:

      str = "BIP=" + BarsInProgress + " " + Time + " " + Instrument.FullName
      + " Bar Entry at " + DateTime.Now.ToString()
      + " High " + Highs[1][0]
      + " Low " + Lows[1][0]
      + " Close " + Closes[1][0]
      + " Avg High " + avgHigh + " Avg Low " + avgLow
      + " Minutes To Close " + minutesToClose;

      The OnOrderUpdate Print is done using:

      str = "OnOrderUpdate" + Times[1][0] + " " + Instrument.FullName
      + " " + BarsPeriod.Value + " " + BarsPeriod.Id
      + " " + DateTime.Now.ToString() + order.ToString();

      The debug Print log and the Execution grid match, and show trades being done on 3/1 and 3/5 at 2:14 PM (which is as expected since the trades were entered on the 2:13 PM bar on these days).

      The Chart shows the trades being done on 3/2 and 3/8, which is one (trading) day after they were done according to the Print and Execution log files.

      If you see something I'm doing wrong here, please let me know.

      Thanks,

      Bob A.
      Attached Files

      Comment


        #4
        Please open up a Data Box window and mouse over the execution for Long A. What time does it say on it there for the execution and the bar?
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          I had (mistakenly) closed the strategy analyzer window, so I re-ran everything. A complete set of pictures (including the data box) and the trace log are attached.

          Thanks for your help (and Bertrand too) !

          Bob A.
          Attached Files

          Comment


            #6
            BAltman,

            Thanks. I will get back to you at a later point in time.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Hi BAltman,

              This should be a bug and it should be resolved in B12. Thank you for reporting.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                I think I'm getting historical trade arrows showing on the wrong bar too in beta v11. It might be a little different than the wrong day problem reported.

                It was a manually executed simulation trade.

                It appears to be plotting the trade arrows within the bar that contains the recorded trade time, but I have my doubts about the recorded trade time because the trade could not have been filled on the bar shown.

                On a longer 3 minute chart the arrows could be fine, but on a 1 minute chart where there is higher time resolution the arrows are below the low of the bar.

                I remember the trade, but not the exact trade entry and exit times.

                Is this an issue with the recorded trade time as I suspect, or something else?
                Attached Files

                Comment


                  #9
                  jamesaq,

                  It sounds like you may have an out of sync PC clock causing your executions to be timestamped differently than your bars. Please be sure to sync your PC clock before starting NinjaTrader.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    Josh,

                    Thanks.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    599 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    344 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    103 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    558 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    557 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X