• 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

BarsInProgress Clarification

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

    BarsInProgress Clarification

    Can somebody clarify what exactly BarsInProgress refers to or more specifically when this example if statement would be executed, Assuming I'm using 2 data series. The main data series being 1m and the higher time frame being 5m. Since the [1] data series in this case is the 5m does that mean this if statement will only run at the conclusion of every 5m bar? In other words, it only runs this method at the start of each new 5m bar for the previous bar which is now [1][1]? If my understanding is not correct please explain exactly what happens when BarsInProgress == 1. I need to know what happens here so I can make multi-time frame indicators that actually work as intended. Thanks in advance.

    if((BarsInProgress == 1)
    {
    do something.
    }

    #2
    Hello,

    Thank you for the post.

    Since the [1] data series, in this case, is the 5m does that mean this if statement will only run at the conclusion of every 5m bar?
    As long as your Strategy/Indicator's calculation mode is set to Calculate.OnBarClose, that is correct.

    ... it only runs this method at the start of each new 5m bar for the previous bar which is now [1][1]
    It will run the IF statement at the close of the most current bar (Bars[1][0]) then after the call to OnBarUpdate is finished, it will become Bars[1][1] in the next call to OnBarUpdate.

    The condition if(BarsInProgress == 1) is to filter context. So you know that the OnBarUpdate function is being called for that series specifically. While you know that the OnBarUpdate function is being called for the secondary series, you can use the singular price series arrays such as Close[] Open[] etc. Even if the OnBarUpdate is being called for the primary series (if(BarsInProgress == 0)), you can still access the secondary series with the plural price data arrays: Closes[1][0] would be the most current bar of the 5M series.

    Please see this help guide link on multi-timeframe and multi-instrument strategies, see the sections titled "Working With Multi-Time Frame Objects" and "How Bars Data is Referenced":
    https://ninjatrader.com/support/help...nstruments.htm

    Please let us know if we may be of any further assistance.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Hi Chris,

      Thanks for the reply. I'm still confused about 1 thing.
      Assuming again we are talking about the main data series[0][0] being 1m and the secondary data series 5m [1][0] every 5th bar both of these data series are going to be in progress at the exact same time unless one data series always takes priority over the other. Does the on bar update call each data series in sequential order? The reason this is important is that in the below example. It's saying that if i lock the method behind a BarsInProgress == 1 if statement then i can assign values without even referencing the data series number in the array. So I could assign the value of Close[0] to a double called 5mclose and it would never confuse the 5m bar close with the 1m bar close that would update at the same time every 5th bar? Ultimately what im saying is that it appears that it's not possible for more than one data series to be in-progress simultaneously. Is this correct?


      This is the example code provided from the reference samples:

      protected override void OnBarUpdate()
      {
      // Executed on primary bar updates only
      if (BarsInProgress == 0)
      {
      // Set DataSeries object to store the trading range of the primary bar
      primarySeries[0] = Close[0] - Open[0];
      }
      else if (BarsInProgress == 1) // Executed on secondary bar updates only
      {
      // Set the DataSeries object to store the trading range of the secondary bar
      secondarySeries[0] = Close[0] - Open[0];
      }

      // When both trading ranges of the current bars on both time frames are positive and there is not currently a position, enter long
      if (primarySeries[0] > 0 && secondarySeries[0] > 0 && Position.MarketPosition == MarketPosition.Flat)
      EnterLong();
      }
      Last edited by gordongekko; 12-27-2017, 01:27 PM.

      Comment


        #4
        Hello,

        Thank you for the follow-up.

        Code:
        ...it's not possible for more than one data series to be in-progress simultaneously. Is this correct?
        That is correct. OnBarUpdate will be called for one series at a time.

        The reason we use if((BarsInProgress == 1) is for the context of which series this OnBarUpdate belongs to. If BarsInProgress == 1, Close[0] will refer to the secondary series. If BarsInProgress == 0, Close[0] will refer to the primary series.

        Does the on bar update call each data series in sequential order?
        If the strategy/indicator has two data series of the same instrument and CalculationMode == Calculate.OnEachTick, the primary series OnBarUpdate will be called, then the secondary series. If the instruments are different, OnBarUpdate will be called in the sequence the ticks are received.

        Please let us know if you have any questions.
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          So if i'm using 3 different time frames (1m[0][0] 3m[1][0] and 10m[2][0]) for the same instrument will on bar update be called for each series in sequential order (as they appear in the array as 0,1, and 2) if more then one close at the same time which will happen every 3rd and 10th bar. Another question is this. Why gate a method behind an if statement requiring barsinprogress == (data series) when you can just say this : If( close[0] > close[1] && close [1][0] > close[1][1] && close[2][0] > close[2][1])
          {
          run method
          }

          How is this different from making 3 different statements and assigning the result of a method to a seperate double and comparing those in a 4th if statement? Are they both viable and do they produce the same result?

          Comment


            #6
            Hello,

            Thank you for the reply.

            It will depend on the time frame you have chosen for the three time series. If your primary series was a 1 minute, 2nd was a 3 minute, and the 3rd was a 10 minute and your calculation mode is set to OnBarClose, then yes, they will process in order.

            Alternatively, if your primary series is a 1-minute series and your secondary series is a 1 tick series and your calculation mode is set to OnBarClose, then they will not process in order.

            The reason you would check if a specific bar is closing with (BarsInProgress == X) is that there might be times where you want to know when the bar of a specific series closes. Or maybe you want to perform logic every 10 minutes instead of every minute.

            Using Closes[x][x] is ok to use if you just want the price of your other series at an arbitrary time.

            In this reference sample, they are entering a position on a 5-minute series and exiting that position on a 15-minute series:
            https://ninjatrader.com/support/foru...ead.php?t=5787

            Please let us know if you have any questions.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by johnnybegoode, Today, 12:38 AM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_EricB  
            Started by percma, Today, 03:44 AM
            0 responses
            2 views
            0 likes
            Last Post percma
            by percma
             
            Started by mrzz93, Today, 03:06 AM
            1 response
            18 views
            0 likes
            Last Post mrzz93
            by mrzz93
             
            Started by HighTrade, Yesterday, 06:37 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_ChrisSch  
            Started by BarzTrading, Yesterday, 09:30 PM
            0 responses
            1 view
            0 likes
            Last Post BarzTrading  
            Working...
            X