• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What exactly is Close[0] on OnBarUpdate?

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

    What exactly is Close[0] on OnBarUpdate?

    Suppose we have 3 bars, A, B and C, we're trading the 1min chart. Bars A and B are already formed and completed, and bar C has 10 seconds left to complete. 10 seconds have passed, bar C is completed so OnBarUpdate is triggered and we have a new bar D.

    On the call of OnBarUpdate when bar C was formed, does Close[0] refers to the close of bar C that was just fully formed, or the "close" of bar D that was just initiated but hasn't closed yet?

    #2
    Hello leocrespo,

    Thanks for your post and welcome to the Ninjatrader forums.

    From your description this would be with the CalculateOnbarClose = true. In that case Close[0] would refer to the closing price of the last complete candle, "C" in your example and would remain that way until "D" finished at which point Close[0] would point to "D".

    With CalculateOnbarClose = false, Close[0] would always point to the latest tick of the current bar, so in the described situation if "C" was closed then the Close[0] would be pointing to the forming bar "D" at its current tick value. For clarity, Close[1] would refer to the prior bar close "C".

    I've attached a picture that will assist in understanding the two considerations of CalculateOnBarClose.

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

    Comment


      #3
      I'm going to open this back up cause I'm having a problem with Print(Close[]);
      If I put anything besides 0 in the brackets, then I get the error,"Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."

      I can't use 1 or 2 in the brackets to print without getting this error. FYI, I'm testing this on Market replay. I don't know if that has anything to do with the problem.

      Comment


        #4
        Hello lehula,

        The error is telling you that the DataSeries does not have enough bars to reference that many "BarsAgo." You will have to make sure enough bars are available before making that reference.

        Please refer to the help guide information here for more details - https://ninjatrader.com/support/help...nough_bars.htm

        Please let us know if you have any questions.
        JimNinjaTrader Customer Service

        Comment


          #5
          So it looks like Close only works with the minute charts and not the tick charts. That is why I'm getting the error.

          Comment


            #6
            Originally posted by lehula View Post
            So it looks like Close only works with the minute charts and not the tick charts. That is why I'm getting the error.
            if you say Print (Close[2]) and you are still on Bar 0 then it will blow up. The solution is before Print statement you add If (CurrentBar < 2) return; this is to avoid print value from bar 2 when it has not get there yet.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by jamarc, Today, 02:30 AM
            1 response
            6 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by uday12, Yesterday, 04:19 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by grose, Today, 06:53 AM
            2 responses
            7 views
            0 likes
            Last Post grose
            by grose
             
            Started by Bobisam, Yesterday, 04:57 PM
            1 response
            21 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Started by voltlon, Yesterday, 05:18 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_PaulH  
            Working...
            X