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

Does Bars refer to current Bars object in OnBarUpdate()?

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

    Does Bars refer to current Bars object in OnBarUpdate()?

    What does the Bars property/field refer to?

    Does it refer to the BarsArray[BarsInProgress] for the current call to OnBarUpdate()? That is, does BarsArray[BarsInProgress] == Bars? Can I substitute one for the other or do they refer to different objects?

    #2
    Bars represents the data that is being processed by your script:



    These are used to find the BarsSinceSession, etc

    BarsInProgress refers to the current call on OnBarUpdate related to the series that may be added, where BarsInProgress == 0 is the primary data series, and BarsInProgress == 1 would be an added data series.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      ...where BarsInProgress == 0 is the primary data series, and BarsInProgress == 1 would be an added data series.
      So that's my question, does the Bars property always refer to the primary data series? Or does it refer to the current data series that is being handled by OnBarUpdate()?

      Comment


        #4
        The Data Series that is being handled by OnBarUpdate

        If you were to check Bars.x in OnBarUpdate, you would get multiple calls for each OBU call.

        If you wanted to check for only one OBU call, you would need to check for Bars.x in a BIP filter:

        Code:
        		protected override void OnBarUpdate()
        		{
        			
        			
        			// This will be called twice as per each OBU call
        			Print("BIP : " + Instrument.FullName + " | Bars  : " + Bars.BarsSinceSession);
        		
        			// These will be called only when that BIP is called
        			if(BarsInProgress == 0)
        			{
        				Print("BIP 0 : " + Instrument.FullName + " | Bars  : " + Bars.BarsSinceSession);
        			}
        			
        			if(BarsInProgress == 1)
        			{
        				Print("BIP 1 : " + Instrument.FullName + " | Bars  : " + Bars.BarsSinceSession);
        			}
                          }
        MatthewNinjaTrader Product Management

        Comment


          #5
          So from within OnBarUpdate(), BarsArray[BarsInProgress] == Bars, no?

          Comment


            #6
            Yes, that would refer to the current data that is being processed in OBU()
            MatthewNinjaTrader Product Management

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by mmckinnm, Today, 01:34 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Conceptzx, 10-11-2022, 06:38 AM
            3 responses
            60 views
            0 likes
            Last Post NinjaTrader_SeanH  
            Started by f.saeidi, Today, 01:32 PM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by traderqz, Today, 12:06 AM
            9 responses
            16 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by kevinenergy, 02-17-2023, 12:42 PM
            117 responses
            2,766 views
            1 like
            Last Post jculp
            by jculp
             
            Working...
            X