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

CurrentBar[0]

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

    CurrentBar[0]

    Hi,

    If I running on Historical Data and primary bar index is 10 min and secondary bar index is 1 Tick, if I Call Closes[0][0] in OnBarUpdate for the 1 tick seires will I get the Close of the last 10min bar OR the price of the current 10min bar that is forming? ie

    Code:
    If(BarsInProgress == 1)
    {
         // is x the close of the last 10 min bar or the price of the one forming now?
         double x = Closes[0][0] ;
    
    }

    #2
    Hello,

    When processing historical data, you should see the final close price of the current bar of the primary 10-minute series (the bar on the primary series that would have been forming at that time). For example, when this code runs on a tick that comes in at 3:34pm, you will receive the final close price of the 3:40pm bar for the 10-minute series.

    Since the primary bar will already have its final close price, even at a time when that bar would not have been closed in real-time, Closes[0][0] will refer to that price.

    Once the script switches to realtime, you would then receive the final close price of the previous primary bar.
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Originally posted by GKonheiser View Post
      Hi,

      If I running on Historical Data and primary bar index is 10 min and secondary bar index is 1 Tick, if I Call Closes[0][0] in OnBarUpdate for the 1 tick seires will I get the Close of the last 10min bar OR the price of the current 10min bar that is forming? ie

      Code:
      If(BarsInProgress == 1)
      {
           // is x the close of the last 10 min bar or the price of the one forming now?
           double x = Closes[0][0] ;
      
      }
      'x' is always the close of the last 10 min bar

      Why?
      Because the close price of the bar that is forming now has not finished yet, so no 'Close' price is available.

      I'm not sure what historical vs realtime has to do with it. Dave, could you elaborate again on this distinction?

      Comment


        #4
        That's a good question, and I actually should have mentioned that what I noted would apply with CalculateOnBarClose = False. In this case, referencing Close[0] in realtime will give you the Last price of the currently forming bar as it forms. On Historical data, we don't have the same concept of a "currently forming bar," because we are actually working with 4 already-defined data points for each historical bar (Open, High, Low, Close). So if you reference the close price of a historical bar, at a time when the bar would not yet have closed if it were realtime, the final close price does already exist in the OHLC values, so Close[0] will refer to the actual closing price of that bar.

        With CalculateOnBarClose = True, then the same concept applies, but with a different discernible result. What you will see in this case, is that Close[0] will still represent the Last traded price, but it will happen on the last tick of the bar (a.k.a. the Close). Thus, the instant that the script processes this, a new bar will begin forming, which gives the impression that Close[0] referenced the previous bar.
        Dave I.NinjaTrader Product Management

        Comment


          #5
          Because when running live data Close[0] == Current Last Price if CalculateOnBarClose == False.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by cmtjoancolmenero, Today, 05:05 PM
          0 responses
          1 view
          0 likes
          Last Post cmtjoancolmenero  
          Started by lucasmelo152, 06-28-2021, 12:51 PM
          8 responses
          2,124 views
          0 likes
          Last Post Ymcapital  
          Started by Creamers, 04-27-2024, 05:32 AM
          11 responses
          69 views
          0 likes
          Last Post Creamers  
          Started by NM_eFe, 04-30-2024, 06:14 AM
          5 responses
          32 views
          0 likes
          Last Post NM_eFe
          by NM_eFe
           
          Started by Jonker, 04-27-2024, 01:19 PM
          2 responses
          20 views
          0 likes
          Last Post Jonker
          by Jonker
           
          Working...
          X