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

Calculate Property and Historical Final Bar

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

    Calculate Property and Historical Final Bar

    My question is similar to this old thread: https://ninjatrader.com/support/foru...storical+close

    Specifically, I'm asking about the behavior of the Calculate property of an indicator as it relates to the right-most bar on a chart when dealing only with historical data.

    I see some odd behavior and just want to make sure I'm understanding correctly.

    Setup: I've created a simple SMA indicator that will, in addition to plotting the SMA, print to Output each time OnBarUpdate is called.

    Scenario #1: Calculate=OnBarClose

    In this case, OnBarUpdate is never called for the final bar on the chart. As I understand, that's because in this mode the previous close is only processed at the open of the following bar. But with no next bar, the final bar does not get processed.

    ...
    CurrentBar=1033, Count=1037, Close[0]=2859.75
    CurrentBar=1034, Count=1037, Close[0]=2855.25
    CurrentBar=1035, Count=1037, Close[0]=2853.75

    Scenario #2: Calculate=OnPriceChange

    In this case, OnBarUpdate IS called for the final bar. As I understand, because this is historical bar data, OnPriceChange doesn't actually cause processing at the OHL prices, but it does process "at the close" using the correct closing price for the bar.

    ...
    CurrentBar=1034, Count=1037, Close[0]=2855.25
    CurrentBar=1035, Count=1037, Close[0]=2853.75
    CurrentBar=1036, Count=1037, Close[0]=2836.75

    First, am I understanding this correctly?
    Second, I agree with the poster of the linked thread that this is counter intuitive.
    Third, I can see reasons that your developers have done it this way to handle cases where you are transitioning from historical to real-time and why you might not want to change it.

    If my understanding is correct, then I should be fine if I always use Calculate=OnPriceChange for all of my historical data processing to get the behavior that most people would expect.

    Finally, a suggestion:

    Please consider adding discussions of this confusion to the help documentation on both the Calculate page (https://ninjatrader.com/support/help...?calculate.htm) and the OnBarUpdate page (https://ninjatrader.com/support/help...nbarupdate.htm).

    Postscript: The timeouts on this website are way too short. I lost all my work on this post, but luckily anticipated that I might be logged out and copied it before I tried to submit. The login attempted to redirect me back to my new thread page, but it was empty.

    #2
    Hello BarzTrading,

    Thank you for your note.

    Since a new bar has yet to be created as of Friday, Fridays bar, CurrentBar=1036, Count=1037, Close[0]=2836.75, wouldn’t be a historical bar yet but rather the current bar. See the 2nd note at the following link which mentions that that an update can be called not necessarily at the close of the bar.



    CME settles the ES at 315PM Chicago Time and the contract reopens at 3:30 and trades till 4. The trading between 3:30-4PM could trigger on OnBarUpdate due to price changes after settlement.



    What specifically would you suggest the help guide be updated with regarding Calculate?

    I will pass on your suggestion about the forums time out.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      OK. I thought I understood, but I'm not so sure now.

      I'm fairly new to futures, so, to be honest I'm a bit confused by the trading hours and the implications of this for how bars are formed. The following page describes the trading hours for ES as:

      Sunday - Friday 5:00p.m. - 4:00p.m. CT with a trading halt from 3:15p.m. - 3:30p.m. CT; Daily Maintenance period Monday - Thursday 4:00p.m. - 5:00p.m.
      https://www.cmegroup.com/trading/why...0-futures.html

      Imagine it's 7pm CT on a Wednesday and I'm looking at daily bars of ES. Which prices are reflected in the right most bar and the penultimate bar?

      What point in time during the day constitutes the end of the bar? And when does a new bar begin?

      I'm using Kinetick data.
      Last edited by BarzTrading; 08-13-2018, 07:25 AM.

      Comment


        #4
        Hello BarzTrading,

        7PM on wednesday would be the new bar which closes thursday.

        Is there a script you are working on which is having an issue or something you are trying to implement?

        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Alan.

          I'm understanding where my confusion was coming from.

          1) I was looking at the daily data with an equities mindset where a daily bar represents the time from the open (9:30) to the close (16:00). In this case, if you were looking at daily bars at 7pm in the evening, then you would expect the last bar to be today's bar and the closing price on this last (right most) bar to be the last price at 16:00 of the same day.

          However, with futures data, especially on ES, running nearly 24/7, the close occurs at 16:00 and then the next "day" starts at 17:00. In this case, therefore, the right most bar if I'm looking at 19:00 in the evening, is the bar that started two hours early at 17:00 and is currently developing and does not represent a full day or session.

          So, when our indicators process all but the last bar, they are processing up to 16:00 of the same day. The right most bar, the developing bar, in this case, correctly, should not be included when analyzing the daily data.

          2) I was also thinking in a historical-only mindset rather than a real-time mindset. If someone handed you a set of historical daily data, you'd expect that every bar represents one full day of trading. However, that's not quite accurate because NinjaTrader/Kinetick still has the current day's data that is developing in real-time.

          Question:

          * Is there a way to turn off the developing bar on a chart and only show the completed bars?

          ---

          It doesn't really matter, but in answer to your question what I'm working on, this thread speaks to it: https://ninjatrader.com/support/foru...d.php?t=111634

          My main goal is just to understand precisely how NinjaTrader works and what I'm really looking at and analyzing.

          Thanks for your assistance.

          Comment


            #6
            Hello BarzTrading,

            There is no way to turn off the current bar which is developing however you could run your indicator/strategy with Calculate set to OnBarClose, so that not until that bar closes and a new one opens will the script be processed for that bar.

            If you opened a 1440 minute chart, (1440 minutes in 1 day), then clicked on the chart>data series, and set the session template to US Equities RTH, then no night session would be charted however the bar during the regular session would update throughout the session.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thanks, Alan. Both of these approaches allow me to do what I want.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 05:00 AM
              0 responses
              5 views
              0 likes
              Last Post PaulMohn  
              Started by ZenCortexAuCost, Today, 04:24 AM
              0 responses
              5 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by ZenCortexAuCost, Today, 04:22 AM
              0 responses
              2 views
              0 likes
              Last Post ZenCortexAuCost  
              Started by SantoshXX, Today, 03:09 AM
              0 responses
              16 views
              0 likes
              Last Post SantoshXX  
              Started by DanielTynera, Today, 01:14 AM
              0 responses
              3 views
              0 likes
              Last Post DanielTynera  
              Working...
              X