Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Trade executions incorrect placement in real time trading

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

    Trade executions incorrect placement in real time trading

    This is a super simple test strategy on 1 minute bars. It's goes long if flat, and closes the position if it's open. Simple.

    But once it transitions into real time trading the execution markers and text on the plot do not plot correctly. They are all pegged to the right of the chart when they should be placed on the bars where they actually occurred.

    How can I fix this?

    Click image for larger version

Name:	image.png
Views:	172
Size:	45.2 KB
ID:	1321641

    #2
    Hello BarzTrading,

    In Backtest Calculate is always OnBarClose unless 1-tick intra-bar granularity is implemented and TickReplay is enabled.

    Below is a link to a support article about 1-tick intra-bar granularity and TickReplay.


    When orders are submitted after the condition bar closes, they appear at the open of the next bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      UPDATE: I believe I found the issue. See post #6 below.

      Thanks, Chelsea. I'm reading the resource you provided.

      But in the mean time could you explain how your response relates to all of the execution markers being aligned at the right of the chart? I don't understand based on what you wrote.

      Thanks.
      Last edited by BarzTrading; 10-16-2024, 09:15 PM.

      Comment


        #4
        The post linked below appears to have reported a similar issue with the execution markers all positioning themselves at the right side of the chart.

        In that post, they are speculating that time zones are somehow the source of the problem... ??


        Comment


          #5
          I did the following:

          * Closed all chart windows
          * Reset the database
          * Repaired the database
          * Restarted NT
          * Opened a new chart window and started the strategy.

          This time I didn't see the execution markers at the right of the chart (however, I have in subsequent attempts), but in all cases there is a long gap where several trades are not drawn on the chart.

          After about 10 minute bars, as you can see, the trades start drawing again.

          Click image for larger version

Name:	ES 12-24 (1 Minute) 2024_10_16 (17_55_28).png
Views:	134
Size:	62.3 KB
ID:	1321671

          Comment


            #6

            Sorry for all the posts... but I think this has something to do with different data sources and delayed data. I have both Kinetick (delayed data) and NinjaTrader Brokerage data.

            I believe the reason some trades align at the right is because of the delayed data from Kinetick.

            There is some way in which the trade times are out of sync with the chart times and don't account properly for the delayed data.

            Test #1:
            * Connected to Kinetick delayed data only
            * Reload historical data
            * Reload NinjaScript
            * Start strategy on the Sim101 account
            * For 10 minutes all trade markers are aligned to the right of the chart.
            * After 10 minutes the first real-time trade appears on the chart when it should have been drawn 10 bars earlier.
            * New trades continue to pile up on the right side as the oldest trades on the right "slide off" onto the chart after 10 minutes. Again being charted 10 bars later than they should be.

            Test #2:
            * Connected to NTB data only
            * Reload historical data
            * Reload NinjaScript
            * Start strategy on the NTB Demo account
            * All trades are drawn normally on the chart in the correct place.​

            Comment


              #7
              Hello BarzTrading,

              I'm not clear on what you are asking.

              In your screenshot I am not seeing orders appearing to the right of the chart bars, I am only seeing some execution markers on some bars and on the last bar. The execution marker will appear on the bar the order that was open when the order filled (execution).

              You can print the execution.ToString() if you want to check the execution time and print the Time in OnBarUpdate() if you want to see what bar was open when an order fill executed.



              If the real-time is delayed, the executions would also be delayed until the price received that fills the order.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8

                1.

                The screenshot in post #1 clearly shows the trade markers and labels bunched up at the right side of the screen.

                My original question was why is this happening and how to make it stop happening.

                2.

                I did not see how your reply in post #2 was related. You said "when orders are submitted after the condition bar closes, they appear at the open of the next bar."

                That doesn't make any sense to me. The markers and labels are appearing at the right edge of the chart not the open of the next bar. The trade markers remain at the right edge of the chart for the next 10 minutes until the delayed-data chart catches up with the times on the trades (apparently).

                3.

                I continued trying to figure this out myself. The screenshot in post #5 was intended to highlight the 10 bar gap where there were no trade labels even though NT was executing trades through that whole range.

                There are no markers and labels at the right side of the chart in post #5 because the chart is scrolled backward slightly obscuring them. This is evidenced by the arrow in the upper right corner.

                The trades that were executed during the 10 bar gap are being drawn on the chart 10 bars after where they were executed.

                4.

                I determined that this is likely related to Kinetick data being delayed by 10 minutes. NT does not adjust for the 10 bar delay and therefore does not sync up the trade times with the chart time axis.

                5.

                I only observed this with delayed data. When I ran Test #2 in post #6 against NinjaTrader Brokerage data, I did not see the gap or labels bunching at the right edge of the chart. I presume this is because that data is not delayed data.



                Question #1:

                Are the screenshots in post #1 and post #5 expected behavior. Your responses are suggesting that you're not surprised by seeing this.

                Question #2:

                If you attempt to execute Test #1 in post #6, do you observe something similar with markers and labels bunched at the right edge of the chart and a gap where there are no labels?

                Then after 10 bars (or whatever the delay on your delayed data is) the labels start appearing on the chart. You will still see trades bunched on the right because with a 10 minute delay there are still trades with timestamps that are ahead of the chart time axis.

                Strategy Code:

                Code:
                using System;
                using System.Collections.Generic;
                using System.Linq;
                using NinjaTrader.Cbi;
                using NinjaTrader.Data;
                
                namespace NinjaTrader.NinjaScript.Strategies.Studies
                {
                    public class StudiesLiveTest : Strategy
                    {
                        protected override void OnBarUpdate()
                        {
                            if (Position.MarketPosition == MarketPosition.Flat)
                            {
                                EnterLong();
                            }
                            else
                            {
                                ExitLong();
                            }
                        }
                        protected override void OnStateChange()
                        {
                            if (State == State.SetDefaults)
                            {
                                Name = "Studies - Live Test";
                            }
                        }
                    }
                }

                Question #3:

                It seems to me that the real-time trades in this case are drawn in the wrong place because they do not align with the "condition" bars that triggered the trades.

                The entry and exit points observed after the gap in the screenshot in post #5 are all over the place having no correlation to the bars they are drawn on. This is evidence that they are not aligned properly with the chart data.

                I suppose I could see why NinjaTrader might choose to do this. Can you confirm this is expected behavior.

                Question #4:

                I'm still puzzled by your comments in post #2. Is that still relevant after further clarifying the problem? I don't think it is. Am I wrong about that?

                ---

                If the final answer to all of these questions is "This is expected behavior", I'll accept that now that I understand NT does not make an attempt to align the trade markers and labels with delayed data charts. I suppose there could be good reasons for this decision even though it's rather confusing.


                Comment


                  #9
                  Hello BarzTrading,

                  "My original question was why is this happening and how to make it stop happening."

                  I am seeing orders on the last bar on the chart, all placed while that bar was open. If the data is delayed, the order timestamps will be within the datetime of that bar.

                  Don't real-time trade with delayed data.


                  "I did not see how your reply in post #2 was related. You said "when orders are submitted after the condition bar closes, they appear at the open of the next bar."

                  That doesn't make any sense to me. The markers and labels are appearing at the right edge of the chart not the open of the next bar. The trade markers remain at the right edge of the chart for the next 10 minutes until the delayed-data chart catches up with the times on the trades (apparently).​"

                  A NinjaScript has a Calculate setting that controls when OnBarUpdate runs. If Calculate is set to OnBarClose OnBarUpdate() will run after the bar closes. If the order method is called from OnBarUpdate() after the bar closes, then the order is being sent after the new bar has opened.


                  "I determined that this is likely related to Kinetick data being delayed by 10 minutes. NT does not adjust for the 10 bar delay and therefore does not sync up the trade times with the chart time axis."

                  Yes, you would be placing orders while that last bar was open so the orders appear on that last bar.


                  "Are the screenshots in post #1 and post #5 expected behavior. Your responses are suggesting that you're not surprised by seeing this."

                  Yes, this would be expected for delayed data and real-time orders.



                  "If you attempt to execute Test #1 in post #6, do you observe something similar with markers and labels bunched at the right edge of the chart and a gap where there are no labels?"

                  Yes, if I were to run this script with delayed data the same behavior would occur.


                  "It seems to me that the real-time trades in this case are drawn in the wrong place because they do not align with the "condition" bars that triggered the trades.

                  The entry and exit points observed after the gap in the screenshot in post #5 are all over the place having no correlation to the bars they are drawn on. This is evidence that they are not aligned properly with the chart data.

                  I suppose I could see why NinjaTrader might choose to do this. Can you confirm this is expected behavior.​"

                  Yes, this is expected behavior. The executions are appearing within the bar that was open when the order was filled. If there hasn't been a new bar for 10 minutes, then all of the orders appear on the last bar of the chart that's been open for the last 10 minutes as they were executed when that bar was open.


                  "I'm still puzzled by your comments in post #2. Is that still relevant after further clarifying the problem? I don't think it is. Am I wrong about that?"

                  While I had not yet known you are using delayed data, which isn't suitable for realtime trading, I had thought you were stating the orders are appearing after the condition bar.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks for the explanations and confirmations, Chelsea. Yes, it's not my plan to trade live with delayed data. I was just confused by what I saw and didn't understand the reason for it.

                    I feel it all makes sense now, even if it wasn't the way I expected things to behave.

                    Comment


                      #11
                      Hi Chelsea,
                      with delayed data, live executions are displayed incorrectly on the current bar, and continue to stay displayed on the current bar even though new bars form. I want to log this as a bug to be dealt with. There are numerous reasons why users would want to observe realtime trades, even if they have delayed data. Maybe for trading practice, or in my case for testing the correct operation of automated strategies. Currently I am forced to test realtime executions with forex, which I do have realtime data for, or on market replay, when testing a strategy, because of this bug.
                      saltminer.

                      Comment


                        #12
                        Hello saltminer,

                        Live trading is not supported with delayed data, so our development team would not allow me to submit a bug report on this.

                        However, I will submit a feature request for the development team to consider supporting live trading with delayed data on your behalf.

                        Please note, we receive many requests and cannot reasonably implement all requested features or changes. Interest is tracked internally and if enough interest is tracked, it would be weighed against how feasible it would be to make those changes to consider implementing, so we cannot offer an ETA or promise of fulfillment.

                        When new features are implemented, they will be listed in the Release Notes page of the Help Guide. The ID number may be different than the internal feature request tracking ID, but the description of the feature will let you know if that feature has been implemented.

                        Release Notes - https://ninjatrader.com/support/help...ease_notes.htm


                        If you do not have a brokerage account that is providing real-time data forex data, you can subscribe to a supported data feed, such as Kinetick, IQFeed, Barchart, etc, to obtain that real-time data.

                        If you do not have a real-time data subscription, you could use the Simulated Data Feed for testing.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13

                          However, I will submit a feature request for the development team to consider supporting live trading with delayed data on your behalf.​
                          The main issue from my perspective is that I want to be able to test (or practice) State=Realtime trading with delayed data and see behavior that would match behavior when I am trading in real time with live, undelayed, data.

                          The main use case here is for testing purposes, not so much doing actual realtime trading using delayed data.

                          While the quoted text above is one way to support this, there might be another better way, if the goal is testing rather than "real time trading with delayed data."


                          Comment

                          Latest Posts

                          Collapse

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