Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to get Strategy Analyzer to handle Intrabar movements

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

    How to get Strategy Analyzer to handle Intrabar movements

    Hi All,

    So I have built a strategy in the Analyzer and the actual results from trading are different than what the analyzer states. I know there is a way to add in intrabar tick by tick in the strategy and enable it on the Strategy Analyzer with the Tick Replay checkbox. My result come out really way skewed and inaccurate. I am using this in the State.Configure and also adding in the 1 for ticks in the Long entry like this: EnterLong(1, Convert.ToInt32(DefaultQuantity), @"Long");

    else if (State == State.Configure)
    {
    Calculate = Calculate.OnPriceChange;
    AddDataSeries(BarsPeriodType.Tick,1);
    }​

    Something is wrong and it's just not working. But maybe just start from scratch to help me understand how to enable a strategy in the code so that the Strategy Analyzer will see intrabar ticks. Thank you so much.

    #2
    Hello jayman711,

    Thank you for your post.

    Please see this sample script which demonstrates submitting orders to a 1-tick series:
    https://ninjatrader.com/support/help...ipt_strate.htm

    And this forum post which discusses comparing realtime and historical results:
    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.



    If you are still seeing unexpected results after enabling Tick Replay and adding intrabar granularity, to understand why the script is behaving as it is, 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.
    https://youtu.be/H7aDpWoWUQs?t=2577&...We0Nf&index=14

    If you are using the Strategy Builder in NinjaTrader 8, you can also build prints in the Actions window under Misc -> Print.
    https://drive.google.com/open?id=1CC...D4JjJgEIwJKv6L

    To copy a script and modify the copy (allowing the original to remain in the Strategy Wizard):
    https://www.youtube.com/watch?v=BA0W...utu.be&t=8m15s

    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.

    https://ninjatrader.com/support/foru...956#post671956

    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.

    Comment


      #3
      Thank you so much! Let me check it out and will ask if any more questions.

      Comment


        #4
        Ok maybe I didn't state it clearly because this tick by tick doesn't work. So let me explain again. Let's say I have a strategy that says if the close price is above the 14EMA, then go long. Set a 31 tick profit and 56 tick loss on NQ on the 5 minute. The strategy analyzer will show a profit of 170K for 1 year. But when you run in real trading the profit/losses don't align with the strat analyzer. So what I believe is happening is you might get a bar that moves 31+56=87 ticks. So the strategy analyzer can only determine OHLC but not where the price was within the candle during the 5 minutes. So maybe the bar went up first and triggered you out at 31 ticks but then closed down like 58 ticks where it would have stopped you out so because the bar ended lower the strategy analyzer says you had a loss when really you might have had a gain. So how can I just get Strategy Analyzer to let's say download all the tick data so it can read within bars to give a better result?

        Comment


          #5
          Hello jayman711,

          If the strategy is not properly coded to implement 1-tick intra-bar granularity (meaning placing orders to the barsInProgressIndex of an added 1 tick series), orders will fill with the OHLC information of the bar. Further, for orders to be submitted and filled intra-bar TickReplay must be enabled to work with Calculate.OnPriceChange/.OnEachTick.

          The forum post linked by gabby in post # 2 goes into detail on this.
          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.


          When you say this tick by tick doesn't work, my assumption would be that the orders are not being submitted to the barsInProgressIndex of an added 1 tick series or that TickReplay is not enabled, or that the start and end bar is different so the date range is different.

          The output text files from real-time and backtest would confirm this. That same forum post demonstrates writing the output to file. We are happy to assist with analyzing the output file and discussing what is causing differences.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Cool let me check this out. Thank you Chelsea!

            Comment


              #7
              Thanks Chelsea. I guess I'm bouncing from link to link trying to decipher all this stuff and really just looking for explicit instructions that just say, in the code for section x set this = that, click this checkbox over here, flip this widget on and enable ticks and be done. Let me know if you can just lay it out like that instead of having read a bunch of links which some are broken links anyways. Thank you so much!

              Comment


                #8
                Hello jayman711,

                Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients.

                As Chelsea mentioned, when using Calculate.OnPriceChange or Calculate.OnEachTick a strategy implement 1-tick intra-bar granularity and enable TickReplay. I recommend reading the post Chelsea linked, as it explains in detail why this discrepancy is happening and why those two things are necessary.

                If you have already implemented 1-tick intrabar granularity and enabled TickReplay in your script and continuing to see the same behavior, please follow the instructions to add prints and enable TraceOrders in your script so we can determind why the script is behaving like it is.

                We are happy to assist with analyzing the output file and discussing what is causing differences.

                Apologies for the broken links form my original post, below are the broken links from my original post.

                TraceOrders - https://ninjatrader.com/support/help...raceorders.htm
                OnOrderUpdate - https://ninjatrader.com/support/help...rderupdate.htm

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Yesterday, 05:17 AM
                0 responses
                59 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                133 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                73 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                45 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                50 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X