Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Missing trades during highspeed playback (e.g. 500x or 1000x)

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

    Missing trades during highspeed playback (e.g. 500x or 1000x)

    I use the playback function extensively to back test my automated strategy. On fast moving time of the day, when I am running on 500x speed, I tend to get missed trades. Often need to slow down to 8x or even lower to catch a trade. I am back testing up to 2000-3000 trades and is impacting the speed of my progress. Is there any tips on improving this situation?

    Strategy analyzer is out for me because my strategy makes decisions on each tick and not close of bar.

    to add on: it is not about not getting filled. But the entire trade entry was not executed. Annotations are drawn on the chart, indicating that the entry criteria has been met. I have overridden OnOrderUpdate with some logging, but they don't show up at all. I use these methods for trade entries.

    Code:
    EnterLongLimit(positionSize, limitEntryPrice,LONGENTRYNAME);
    EnterShortLimit(positionSize, limitEntryPrice,SHORTENTRYNAME);
    Last edited by elirion; 03-07-2024, 01:57 AM.

    #2
    Hello elirion,

    Thank you for your post.

    I recommend adding prints and enabling TraceOrders so we can confirm if an order is not being placed when your conditions are evaluating as true.

    To understand why the script is behaving as it is, such as placing orders or not placing orders (or drawing objects or other actions) when expected, it is necessary to add prints to the script that print the values used for the logic of the script to understand how the script is evaluating.

    In the strategy add prints (outside of any conditions) that print the values of every variable used in every condition that places an order along with the time of that bar.

    This will print to the output window. Backtest the script and when the output from the output window appears save this by right-clicking the output window and selecting Save As... -> give the output file a name and save -> then attach the output text file to your reply.

    Output from prints will appear in the NinjaScript Output window.
    NT8: New -> NinjaScript Output

    The prints should include the time of the bar and should print all values from all variables and all hard coded values in all conditions that must evaluate as true for this action to be triggered. It is very helpful to include labels and operators in the print to understand what is being compared in the condition sets.

    Below I am providing a link to videos that demonstrate adding prints to a script to get further information about the behavior of the script.
    NT8 —


    If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
    NT8 Strategy Builder —


    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    NT8 —
    Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.3:11 Creating a New NinjaScript Strategy13:52 Analyz...


    It is also helpful to set TraceOrders to true in State.Configure as well as print the order object in OnOrderUpdate().

    TraceOrders will output to the NinjaScript Output window a message when orders are being submitted, ignored, cancelled, or rejected.

    Printing the order object in OnOrderUpdate() will allow you to track the progression of the order from submitted, to working, to filled, cancelled, or rejected.

    These tools will let you know what happens to the order.
    TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    I'm also including a link to a forum post with further suggestions on debugging a script.


    Save the output from the output window to a text file. Let me know if you need assistance creating a print or enabling TraceOrders.

    I am happy to assist with analyzing the output from prints and TraceOrders.​
    Gaby V.NinjaTrader Customer Service

    Comment


      #3
      ​Hi Gaby,
      Thanks for your reply.

      I already have a comprehensive persistent logging in place. Please take a look at the png file describing the scenario where (1) trade is missing due to high speed replay and (2) trade is executed during low speed replay. The box in light green represent same logging. The box in red represents missing execution.

      It is not necessary for me print all the values for the logic to determine whether to take a trade or not. The assessment is made and the code determines that a trade is to be entered => and a EnterLongLimit is being fired. This happens to both (1) and (2).

      As you can see from the image, the whole part of OnOrderUpdate() does not even happen for (2). All the progression of the order are totally missing. This has totally nothing to do with my assessment code. I fired a EnterLongLimit method, nothing happens. Even if the order fails, I should at least get the whole stack of logs inside OnOrderUpdate().

      For your comment please.
      Attached Files

      Comment


        #4
        this is an old post with similar description.
        Pardon if this is a repeat of a question already in the forum, but i don't see it anywhere if it is. Regarding the Playback Speed x1 x2 x4 x6 x8 x10 ect. Assuming the strategy I use is correct for Forward testing abilities, which i do believe it is. my question is this. If I run playback at x1 or if I bump the speed up to say


        From post #2: "Since the speed of Playback affects the order in which the ticks come in, playing back the data at a faster than normal rate can alter your fills. "
        Is this statement still valid ?

        Comment


          #5
          Hello elirion,

          Thank you for sharing that data.

          No, the speed of the playback does not affect the strategy's calculations. From the Help Guide:

          "When using market replay, the NinjaTrader core market data updates occur at the granularity provided by the market data provider. However, the NinjaTrader user interface only visually updates in 1-second intervals for performance optimizations. Even though the NinjaTrader UI's are only visually updating at 1-second intervals, orders, indicators, and strategies will calculate just as they were running in real-time."

          HTML Code:
          https://ninjatrader.com/support/helpGuides/nt8/index.html?playback.htm#UnderstandingHowThePlaybac kWorks
          Therefore, if your strategy is not taking trades when expected, in order for us to assist you will need to add prints for all conditions that submit orders so we can see how these are evaluating, and enable TraceOrder so we can see if the order is being submitted, cancelled, or ignored etc. Without this information, we can't say why the trade is missing / not being executed with certainty.

          It's clear to me from your screenshot if or why the trade is missing. Additionally, the missing trade from the highspeed playback and the trade executed from the low speed playback are from two different timestamps. It would be best to compare data from the same exact timestamp (i.e. in lowspeed a trade was executed at 10:00AM but when you test the strategy on the same exact data at a higher speed there is no trade executed at 10:00AM).
          Gaby V.NinjaTrader Customer Service

          Comment


            #6
            Hi Gaby,

            I have overloaded the onOrderUpdate method to print the whole stack of order history, Isn't that exactly the same as TraceOrder already ? Look into the pink section. The order history is printed.

            They are the exact same timestamp my friend. the trade happens at [23:14:55]. You are looking at the wrong place. I am not sure where you are looking at. Where does 10:00AM even appear on my screenshot ?


            Comment


              #7
              The gist of the issue is not about taking trade or not. It is about EnterLongLimit basically doing nothing when it's fired under high speed playback.

              If there are issues with the order entry, onOrderUpdate would have flag it out doesn't it? Now the problem is, onOrderUpdate doesn't even happen.

              Last edited by elirion; 03-07-2024, 10:10 AM.

              Comment


                #8
                If from your statement that "the speed of the playback does not affect the strategy's calculations", playing back fast or slow will yield the exact same output. So it is totally not necessary to print the condition values; They will be same regardless of the playback speed.

                My slow playback already indicates that all condition are ok and the trade is taken. When fast playback doesn't take a trade => there is absolute nothing wrong with my conditions values. If there are indeed discrepancies, then I have to conclude that fast and slow playback do yield different outcome, different from what you suggested earlier.


                Comment


                  #9
                  Hello elirion,

                  Thank you for your response.

                  Where does 10:00AM even appear on my screenshot ?
                  I apologize the miscommunication; I mean 10PM and not 10AM. On the left side, all of your prints are timestamped at 3/7/24 around 10PM. I hope that helps to clarify what I meant. I see you are printing an additional timestamp which is showing 23:14:55 and dated 01 12 2023. Thank you for clarifying about which timestamps specifically you're referring to.

                  The gist of the issue is not about taking trade or not. It is about EnterLongLimit basically doing nothing when it's fired under high speed playback.
                  When an order is not fired even though the conditions for it to be sent were met, it is possible that the Internal Order Handling rules to reduce unwanted positions are ignoring the order.

                  The Help Guide page below has goes over Internal Order Handling rules:



                  I have overloaded the onOrderUpdate method to print the whole stack of order history, Isn't that exactly the same as TraceOrder already ?
                  Not exactly, TraceOrders also explains if an order signal is ignored and why, which is not something that would show up in OnOrderUpdate(). ​

                  We need the information from TraceOrders to narrow down the cause of the order not being sent as expected. The previous links about debugging only go into the basics of TraceOrders, for more information, please see the following links:





                  What does the output in the NinjaScript Output window show with Trace Orders enabled? Please locate an example when an order is not being sent as expected and refer to the output to see if there are any TraceOrders messages that can offer more insight as to why an order was or was not sent as expected.

                  It would be helpful to run this for a slow playback and a fast playback, save the output from each test by right-clicking in the NinjaScript Output window and then Save As. Provide these two files and I can assist with comparing them to see if there any differences.

                  Thank you in advance.
                  Gaby V.NinjaTrader Customer Service

                  Comment


                    #10
                    Hi Gaby , thanks for your help. Please see attached.

                    Reason='Exceeded entry signals limit based on EntryHandling and EntriesPerDirection properties'

                    Attached Files

                    Comment


                      #11
                      i googled and found this


                      trying to understand the explanation there at the moment.

                      Comment


                        #12
                        Hello elirion,

                        Thank you for your response.

                        Were you able to compare this output of the test run on a fast playback to a test run on a slow playback? If so, please provide the output for the slow test as well so we can compare if there is a difference for the time stamp you are asking about.

                        Here also links to the Help Guide pages on these topics.






                        Please let me know if there is anything from the support article on this topic that I can help clear up for you.
                        Last edited by NinjaTrader_Gaby; 03-07-2024, 01:49 PM.
                        Gaby V.NinjaTrader Customer Service

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by jxs_xrj, 01-12-2020, 09:49 AM
                        6 responses
                        3,290 views
                        1 like
                        Last Post jgualdronc  
                        Started by Touch-Ups, Today, 10:36 AM
                        0 responses
                        8 views
                        0 likes
                        Last Post Touch-Ups  
                        Started by geddyisodin, 04-25-2024, 05:20 AM
                        11 responses
                        61 views
                        0 likes
                        Last Post halgo_boulder  
                        Started by Option Whisperer, Today, 09:55 AM
                        0 responses
                        8 views
                        0 likes
                        Last Post Option Whisperer  
                        Started by halgo_boulder, 04-20-2024, 08:44 AM
                        2 responses
                        24 views
                        0 likes
                        Last Post halgo_boulder  
                        Working...
                        X