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

OHLC Current Bar

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

    OHLC Current Bar

    Hello,
    As I understand, Open[0],High[0],Low[0] and Close[0] should result in values for the current bar.

    However Open[0] etc seems to result in values of the previous bar rather than current bar. On the other hand Open[-1], High[-1] seems to result into values from the current bar.

    Please check out the attached strategy which prints out these values into the output window. I have also attached a jpeg file showing the results mentioned above.

    I need to output results of the current bar and if I use [-1] in my strategy I start getting exception errors. Attached BuySellStrategy (placed on any chart) and Exception.jpg for the output window highlights this problem.

    Appreciate your help.

    Thanks
    Attached Files

    #2
    Hello Trader-,

    Thanks for your post.

    The values of Open[0], High[0], Low[0] and Close[0] will be of the current bar. What defines the current bar is the state of CalculateOnBarClose and if you are looking at historical data or live data.

    When looking at live data and CalculateOnBarClose is set to false, the current bar will be the currently forming bar on the right edge of the chart. In this condition, Open[0] will not change, High[0], Low[0] and Close[0] can change as each tick is processed up until the bar closes where then the High, Low and Close values will then be fixed. Your code would execute on each tick and if the High[0], Low[0] or Close[0] change, these would be reflected in your code. Open[1], High[1], Low[1] and Close[1] would be of the previously completed bar and would not change

    When looking at live data and CalculateOnBarClose is set to true, then Open[0], High[0], Low[0] and Close[0] are fixed and represent the last completed bar and not the currently forming bar. Your code would only execute on bar close and the values of the Open, High Low and Close would not change.

    When looking at Historical data, regardless of the state of CalculateOnBarClose true or false, the code will process the same as if CalculateOnBarClose = true meaning that your code will only execute once per bar. This is because historical bars only contain the OHLC values of the finished bar and not all of the ticks that made up the bar. When processing historical data, using a [-1] for a bar index will provide the values of the next historical bar however when you use [-1] for live data it will produce unexpected results/error as there are no future bars.

    To provide a visual reference I've attached a chart and identified what the bar index is for each condition of CalculateOnBarClose.

    Reference: http://ninjatrader.com/support/helpG...onbarclose.htm
    Attached Files
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      Hello Trader-,

      Thanks for your post.

      The values of Open[0], High[0], Low[0] and Close[0] will be of the current bar. What defines the current bar is the state of CalculateOnBarClose and if you are looking at historical data or live data.
      Thanks for the detailed response. I guess I was working with historical data, which was producing the results that confused me.

      Thanks once again

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jclose, Today, 09:37 PM
      0 responses
      4 views
      0 likes
      Last Post jclose
      by jclose
       
      Started by WeyldFalcon, 08-07-2020, 06:13 AM
      10 responses
      1,413 views
      0 likes
      Last Post Traderontheroad  
      Started by firefoxforum12, Today, 08:53 PM
      0 responses
      10 views
      0 likes
      Last Post firefoxforum12  
      Started by stafe, Today, 08:34 PM
      0 responses
      10 views
      0 likes
      Last Post stafe
      by stafe
       
      Started by sastrades, 01-31-2024, 10:19 PM
      11 responses
      169 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Working...
      X