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

Running strategies on 1 tick charts

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

    #16
    Hello samish18,

    Thanks for your notes.

    Did you watch the demonstration video in the forum thread linked in post # 14?

    You would need to compare the output in the NinjaScript Output window to the test results to narrow in on what differences might be occurring between your tests as seen in that demonstration video.

    Please watch the demonstration video on the forum thread linked in post # 14 and follow the steps seen in the video to compare your tests to narrow in on what might be causing differences between tests. The forum thread is also linked below.

    Comparing Realtime, Replay, Historical Performance: https://forum.ninjatrader.com/forum/...nce#post100192
    Brandon H.NinjaTrader Customer Service

    Comment


      #17
      In following the video, when trying to run the strategy, I am not getting error from the print statements: "Strategy Error on calling OnBarUpdate method on bar 207: Index (zero based) must be greater than or equal to zero and less than the size of the argument list"

      Comment


        #18
        Hello samish18,

        Thanks for your notes.

        To clarify, are you running your strategy that you have your own custom logic in?

        What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)

        Have you reduced the code of your script and added debugging prints to locate the exact line of code causing the error message?

        What is the line of code causing the error?

        I recommend debugging your code and finding the exact index that is causing the error and then check the size of that collection to understand the cause.
        Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


        To locate the line of code causing the error, reduce the code by commenting out sections of code in the script and test to see if the error persists. Continue commenting out sections of code until you test and see the error stop occurring. This will indicate the last section of code you commented out is likely throwing th error. Then uncomment that section of code and comment out individual lines of code within that section and retest. Once you comment out a line of code and the error stops, the error is likely being cause by that line of code. You could then add debugging prints one line above that code that prints out the index being accessed in that line of code and CurrentBar to see how it is evaluating.

        Here is a help guide page on debugging tips: https://ninjatrader.com/support/help...script_cod.htm

        Brandon H.NinjaTrader Customer Service

        Comment


          #19
          I was able to fix the issue and run the strategy live and backtested. I am using limit orders, so it makes sense that not every trade in the backtest was completed, however, when trades do match (the order is filled on both live and backtest) I am getting a couple points of slippage of every entry and exit despite using limit orders, I have included of the comparison between live and backtest. As you can see, the first two orders with 5:00:08 and 5:00:09 entries did not have their orders filled live. The issue exists in that when an order is filled, such as the short entry at 5:00:11, I am experiencing slippage despite using limit orders. In this case there was no slippage on entry but 3/4 points of slippage on exit.
          Attached Files

          Comment


            #20
            Hello samish18,

            Thanks for your notes.

            Are you referring to seeing slippage for the orders that are placed when running the strategy real-time?

            Or, are you referring to seeing slippage for the orders that are calculated in the backtest?

            Are you using EnterLongLimit()/ExitShortLimit() for your entry orders and are you using ExitLongLimit()/ExitLongStopLimit() and ExitShortLimit()/ExitShortStopLimit() for your exit orders?

            From the Discrepancies Realtime vs Backtest help guide:

            Getting Filled on an Order
            • Fills are determined based on 4 data points, OHLC of a bar since that is the only information that is known during a backtest.
            • During simulation using real-time live market data or Playback, the fill algorithm is dynamic in that it uses incoming market data (both price and volume) to determine if an order should be filled or not.
            • During real-time live brokerage trading, orders are filled according to market dynamics.

            The Fill Price of Orders
            • During a backtest assumptions are made on the fill price of an order is based on the OHLC of a bar and the price of the order itself. You can also have differences depending on which fill algorithm you choose.
            • During simulation using real-time market data or Playback, the fill price is based on incoming market data and volume, you may receive better or worse fill prices dependant on where the bid or ask price is and what volume is available at this market prices.
            • During real-time brokerage trading, orders are filled according to market dynamics.
            ​Discrepancies Realtime vs Backtest: https://ninjatrader.com/support/help...ime_vs_bac.htm

            Note that there would be no slippage on a Limit order, you either get your price specified or the order would not be filled. Also note that when backtesting with 1-Tick intrabar granularity order fills could be accurate within 1 tick. This would be 1 tick for each execution (entries and exits).

            Brandon H.NinjaTrader Customer Service

            Comment


              #21
              I am using those commands to enter long and short and am including 1 bar of slippage in the backtest. My issue is with the discrepancy between fill prices

              Comment


                #22
                Hello samish18,

                Thanks for your notes.

                Since you are using Limit orders you would need to make sure that your strategy's logic is placing orders at identical prices. Slippage only applies to Market orders, not Limit orders.

                You will also need to follow the Comparing Realtime, Replay, and Historical Guide linked below to make sure your logic works the same between historical and live tests.

                Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #23
                  The logic for the strategy is quite simple and should not have any discernable difference between live and backtest. This leads me to believe this is a latency issue, do you concur?

                  Comment


                    #24
                    Hello samish18,

                    Thanks for your notes.

                    Latency is the time it takes for a packet sent from one computer to be received by another computer.

                    Backtest orders generated in the Strategy Analyzer are not transmitted through the internet so there is no latency applied to these orders.

                    Live orders would be affected by latency because they are actually transmitted through the internet.

                    Further, there could be latency when receiving real-time market data.
                    Brandon H.NinjaTrader Customer Service

                    Comment


                      #25
                      I know what latency is. My question is, based on the information above, does it seem that latency is the issue?

                      Comment


                        #26
                        Hello samish18,

                        Thanks for your notes.

                        The behavior could possibly be related to latency since Live orders would be affected by latency and receiving real-time market data could be affected by latency, whereas the generated Strategy Analyzer backtest results do not have any latency at all applied to data or order fills.

                        There would be no methods or properties available to simulate latency in Strategy Analyzer backtest results.

                        The Comparing Realtime, Replay, and Historical guide linked below would need to be followed and you would need to evaluate each data point to understand exactly what is different between tests to understand the behavior.
                        Citizens of the NinjaTrader Community, A common question we hear from clients is 'why are results from backtest different from real-time or from market replay?'. Live orders are filled on an exchange with a trading partner on an agreed upon price based on market dynamics. Backtest orders are not using these market dynamics.
                        Brandon H.NinjaTrader Customer Service

                        Comment


                          #27
                          I am running this strategy on a very powerful VPS, it seems absurd that I would experience latency on the order of near points lost.

                          Comment


                            #28
                            Hello samish18,

                            Thanks for your notes.

                            There is a note in the Backtest Help Guide page that mentions that tests will not be exactly identical when comparing backtest results to realtime results.

                            From the help guide linked below:

                            "3. A certain level of discrepancy between realtime and backtest results would be expected, especially on more exotic barstypes like Point & Figure and Renko, please also review this page for more details."

                            Backtesting a Strategy: https://ninjatrader.com/support/help...a_strategy.htm

                            If you want to make sure the strategy is working the same logically, you would need to do the comparing test and make prints in your script similar to the sample linked below:


                            Beyond that, you still may see differences from real-time when latency is included along with other dynamic market behavior like if you submitted a market order that also has slippage. A limit order can also not be filled if the market blows past it which could cause differences from historical.

                            Something you could consider trying is using IsFillLimitOnTouch to see if that helps any.​

                            IsFillLimitOnTouch: https://ninjatrader.com/support/help...mitontouch.htm
                            Last edited by NinjaTrader_BrandonH; 05-02-2024, 11:58 AM.
                            Brandon H.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by marco231, Yesterday, 11:32 PM
                            1 response
                            4 views
                            0 likes
                            Last Post marco231  
                            Started by sofortune, Yesterday, 10:55 PM
                            0 responses
                            3 views
                            0 likes
                            Last Post sofortune  
                            Started by sofortune, Yesterday, 10:19 PM
                            0 responses
                            9 views
                            0 likes
                            Last Post sofortune  
                            Started by sofortune, Yesterday, 10:10 PM
                            0 responses
                            7 views
                            0 likes
                            Last Post sofortune  
                            Started by sofortune, Yesterday, 09:49 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post sofortune  
                            Working...
                            X