Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Historical bars with two instruments

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

    Historical bars with two instruments

    I have an indicator I made that relies on the difference in prices between two instruments on the same chart. So I calculate (Closes[0][0] - Closes[1][0]) for each bar.

    But for historical bars, it looks like the OnBarUpdate is called for all of the bars for one instrument, and then called for all of the bars for the other instrument. I need OnBarUpdate called by the sequential X-axis values, not all one instrument and then all of the other.

    Is there a setting I need to change to do this for historical bars?

    Thanks!
    Bryan

    #2
    Interesting... I also notice in Playback-Market Replay - in a Strategy - if I have main series of 1 minute, and 2nd series of 5 minutes, then only the main series is called for historical bars. (I removed/added strategy in middle of playback).

    There might be some older posts related to this, but something does appear to be off with this.

    Comment


      #3
      Yes, this is a problem that I also had in v6.5 and v7 with multiple indicators on a chart. When processing historical bars, it would process all of the bars through the first indicator, then process all bars through the second indicator, etc. Rather than processing one bar at a time through all indicators. This really messed up a strategy that I had written that depended on each indicator being processed in order for each bar.

      Anyhow... I need historical bars to process OnBarUpdate one at a time for each both bar series.

      Comment


        #4
        Hello cassb,

        I've created a script to test this, but I am not able to reproduce this behavior using 8.0.2.0.

        Attached is the script I've used to test, and the output this produced in the output window.

        I've added this script to an ES 03-17 1 minute chart.

        Please add this to an ES 03-17 1 minute chart on your end and let me know if you get different output.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thanks Chelsea. I think the problem I am having has something to do with the Tick Replay checkbox. When I check that, I get weird results. Try this on your computer - set your test indicator to calculate OnEachTick. Then check results with Tick Replay unchecked and once again with it checked and see if you get the same results.

          Also, I am putting the second instrument right on the same chart as well, to see the difference in Closes on each bar. I attached a screen shot of how I have it set up.

          Notice in my screen shot the price for the CL 03-17 contract jump down to the price of the CL 02-17 contract for several bars, then back up again. I wonder why it's doing that? This was without Tick Replay Checked. I also attached a second screen shot with Tick Replay checked and you can see that the chart looks completely different.

          Thanks!
          Attached Files

          Comment


            #6
            Hello cassb,

            Thank you for providing the additional test parameters necessary to reproduce the behavior.

            I am doing further testing using Tick Replay and I will let you know what I find.

            As a tip, using a contract month that has not yet rolled over will introduce further complication I will need to test for.

            As the CL is trading the 02-17 and has not yet rolled to the 03-17, I will use the ES 03-17 and NQ 03-17 with Kinetick tick and minute data for comparisons to limit the amount of variables. I will test again once I've understood the behavior with tick replay better using the CL 03-17.

            I appreciate your patience.
            Last edited by NinjaTrader_ChelseaB; 12-27-2016, 04:41 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              No problem, thank you! Maybe I uncovered a bug, who knows. :-) I am not entirely sure what Tick Replay even does... I assumed it means when historical bars are painted onto the chart, they are painted tick by tick instead of just by OHLC.

              Comment


                #8
                Hello cassb,

                That is incorrect. It does not affect the chart.

                The Tick Replay is intended to be used to use tick data to trigger OnMarketData historically, as well as OnBarUpdate when Calculate is .OnEachTick or .OnPriceChange as in NinjaTrader 7, these items to do not work historically.

                Below is a link to the help guide on Tick Replay.


                We should be seeing that OnBarUpdate triggers once for each historical tick for each series when Calculate is set to .OnEachTick. I am expecting the ticks to be in order to the granularity of millisecond. (Meaning any ticks that share a time stamp with the same millisecond would not necessary be in order)
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hm. If Tick Replay does not affect how historical bars are processed/painted on the chart, then what happens when processing historical bars when I have .OnEachTick set for my indicator with Tick Replay off? What happens when Tick Replay is on? It seems like OnEachTick and Tick Replay do the same thing then?

                  "[Tick Replay] will ensure that the market data (bid/ask/last) that went into building a bar is loaded in the exact sequence of market data events. This guarantees that your indicators and strategies are historically calculated tick-per-tick exactly as they would have been if the indicator/strategy was running live during a period."

                  ^^^
                  That is what I need it to do with my indicator.

                  Comment


                    #10
                    Hi cassb,

                    Not quite, enabling TickReplay is required for Calculate.OnEachTick to process historically.

                    These do not perform the same function.

                    If Calculate is set to Calculate.OnEachTick with the TickReplay turned off, this will change the behavior of the script in real-time but will not change the behavior of the script historically.
                    This is the same as NinjaTrader 7 in that CalculateOnBarClose is always true in historical data. Only with NT7 intra-bar granularity had to be manually added by being coded into the script instead of being added with a simple checkbox.
                    http://ninjatrader.com/support/helpG...onbarclose.htm

                    Try an experiment.

                    Create a new indicator. Set Calculate to Calculate.OnEachTick in OnStateChange() when State == State.SetDefaults.

                    Add a condition to OnBarUpdate() that requires IsFirstTickOfBar to be false (so this will only print when an intra-bar tick is processing).

                    Open the output window, then open a chart and ensure TickReplay is disabled in the Data Series window for that chart.

                    Run the script. (Observe there are no prints from the historical data)

                    Enable TickReplay in the Data Series window for the chart

                    Right-click the chart -> select Reload NinjaScript (Observe there are now prints from the historical data)

                    In short TickReplay adds 1 tick intra-bar granularity for use historically with Calculate.OnEachTick (and OnMarketData) which without TickReplay does not work historically. This setting will use much higher CPU and memory resources to provide tick data historically for these methods.


                    In NinjaTrader 7 this would be accomplished by adding intra-bar granularity of 1 tick to the script.


                    Think of TickReplay as adding 1 tick granularity to the script for the purpose of logic processing only (not to be used for high accuracy in order fills).

                    Think of Calculate.OnEachTick as CalculateOnBarClose = false.

                    Please let me know if this does not clarify the purpose of TickReplay.
                    Last edited by NinjaTrader_ChelseaB; 12-28-2016, 08:32 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      OK, we are on the same page then, thanks!

                      How is testing of my script going?

                      Bryan

                      Comment


                        #12
                        Originally posted by NinjaTrader_ChelseaB View Post
                        Hello cassb,

                        Thank you for providing the additional test parameters necessary to reproduce the behavior.

                        I am doing further testing using Tick Replay and I will let you know what I find.

                        As a tip, using a contract month that has not yet rolled over will introduce further complication I will need to test for.

                        As the CL is trading the 02-17 and has not yet rolled to the 03-17, I will use the ES 03-17 and NQ 03-17 with Kinetick tick and minute data for comparisons to limit the amount of variables. I will test again once I've understood the behavior with tick replay better using the CL 03-17.

                        I appreciate your patience.
                        Hi Chelsea. I just wondered how it was going with your testing.

                        Thanks!
                        Bryan

                        Comment


                          #13
                          Do you need anything else from me?

                          Comment


                            #14
                            Hello cassb,

                            Thank you for your patience.

                            Chelsea will follow up on his findings. Can you detail if you were able to follow Chelsea's instructions at the following link?


                            I look forward to your response.

                            Comment


                              #15
                              Yes, I was able to follow his instructions, thank you. He helped to clarify the purpose of TickReplay.

                              We still are trying to determine why my indicator is processing all of the historical ticks for instrument #1 on the chart, and then all of the ticks for instrument #2. Rather than tick 1 for instrument 1, tick 1 for instrument 2, tick 2 for instrument 1, tick 2 for instrument 2, etc.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              86 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              48 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              29 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              32 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              67 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X