Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsArray - BarsInProgress

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

    BarsArray - BarsInProgress

    Hello,

    I need to ask now why it is necessary to have in the script
    if (BarsInProgress !=0) return;

    When I do my strategies with different dataseries eg
    &&(HMA(BarsArray[3],89)[0] < SMA(BarsArray[3],50)[0])
    && Rising(HMA(BarsArray[8],55))

    I get not results in backtesting!!

    But when I remove the if (BarsInProgress !=0) return;

    then I have trades and numbers in the strategy-analyzer.

    Sorry for this question after months working with NT. But do I need the "if BarsInProgress..."?? in my NT-script-strategies?

    Thanks
    Tony

    #2
    tonynt,

    if (BarsInProgress !=0) return;

    This code would check if the BarsInProgress is not 0, then return if that's the case. This essentially makes it so only the primary series will work here. If you use multiple instruments or timeframe series then I would suggest removing it.
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you.

      And you would suggest also NOT to add to the conditions then eg

      if ( Position.MarketPosition == MarketPosition.Flat
      && BarsInProgress ==3
      && BarsInProgress ==5
      && BarsInProgress ==8

      && Falling(HMA(BarsArray[3],55))
      && Falling(HMA(BarsArray[5],55))
      && Falling(HMA(BarsArray[8],55))
      .......

      EnterShort(1000);

      ??

      Thanks
      Tony



      Originally posted by NinjaTrader_AdamP View Post
      tonynt,

      if (BarsInProgress !=0) return;

      This code would check if the BarsInProgress is not 0, then return if that's the case. This essentially makes it so only the primary series will work here. If you use multiple instruments or timeframe series then I would suggest removing it.

      Comment


        #4
        tonynt,

        This here,

        && BarsInProgress ==3
        && BarsInProgress ==5
        && BarsInProgress ==8

        Will never be true, because BarsInProgress is equal to only one value at a time. You would need to adjust this to be different depending on what you are trying to accomplish.
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          OK,

          When you would not use BarsInProgress in a multiple timeframe series then I understand you would use it in a one timeframe series. But why should one use it there when there is only one dataseries?? I already tried to understand the "BarsInProgress-Section" in the help guides. Can y give me please one example when this makes sense to use BarsInProgess?

          Thanks
          Tony

          Originally posted by NinjaTrader_AdamP View Post
          tonynt,

          This here,

          && BarsInProgress ==3
          && BarsInProgress ==5
          && BarsInProgress ==8

          Will never be true, because BarsInProgress is equal to only one value at a time. You would need to adjust this to be different depending on what you are trying to accomplish.

          Comment


            #6
            tonynt,

            BarsInProgress is a way to find out which series called the OnBarUpdate() method. So for example,

            Code:
            if ( BarsInProgress == 0 )// the primary series is getting updated
            {
                //do something with primary series
            }
            else if ( BarsInProgress == 1)// the secondary series is getting updated
            {
               //do something with secondary series
            }
            else if ( BarsInProgress == 2)// the tertiary series is getting updated 
            {
               //do something with tertiary series
            }
            There is no need to use it at all if you are using only a single series indicator or strategy. It is only for multiple series.

            Perhaps you are confusing this with CurrentBar?

            Adam P.NinjaTrader Customer Service

            Comment


              #7
              Adam,

              Yes, this is what I understandt that there is no need for with one dataseries. Therefore I did my question (beginning of this thread) when I start a strategy eg in a 21 Range-Bar-Chart and there are the condtions with my dataseries 3, 8 and 2

              &&(HMA(BarsArray[3],89)[0] < SMA(BarsArray[3],50)[0])
              && Falling(HMA(BarsArray[8],55))
              && Closes[2][1] > Opens[2][1]
              && Closes[2][0] < Opens[2][0])

              I was wondering if I need BarsInProgress because its multi-dataseries and I was surprised that I didn´t get results in backtesting and only WITHOUT BarsInProgress there were results in this multi-dataseries strategy.

              So, finally I understand that I don´t need BarsInProgress in this example here?

              Thanks
              Tony





              Originally posted by NinjaTrader_AdamP View Post
              tonynt,

              BarsInProgress is a way to find out which series called the OnBarUpdate() method. So for example,

              Code:
              if ( BarsInProgress == 0 )// the primary series is getting updated
              {
                  //do something with primary series
              }
              else if ( BarsInProgress == 1)// the secondary series is getting updated
              {
                 //do something with secondary series
              }
              else if ( BarsInProgress == 2)// the tertiary series is getting updated 
              {
                 //do something with tertiary series
              }
              There is no need to use it at all if you are using only a single series indicator or strategy. It is only for multiple series.

              Perhaps you are confusing this with CurrentBar?

              http://www.ninjatrader.com/support/h...currentbar.htm

              Comment


                #8
                tonynt,

                The only thing to consider here is that if you have 4 series added, OnBarUpdate() would get called 4 times so this condition may be true 4 times. You could try setting a flag to disable it on the other OnBarUpdate() calls.

                You could force this code to only execute once on the series of your choice by using BarsInProgress.

                So for example, just use && BarsInProgress == 0
                Adam P.NinjaTrader Customer Service

                Comment


                  #9
                  Adam,

                  You mean the 4 condtions have to be true, but OnBarUpdate should not be called 4 times but only 1 time?? So, therefore I need the BarsInProgress, no? Or how could I do your suggestion with the flag? But in the strategy eg SMA(dataseries3), HMA(dataseries5) EMA(dataseries8) closes[2] have to be checked.

                  Thanks
                  Tony

                  Originally posted by NinjaTrader_AdamP View Post
                  tonynt,

                  The only thing to consider here is that if you have 4 series added, OnBarUpdate() would get called 4 times so this condition may be true 4 times. You could try setting a flag to disable it on the other OnBarUpdate() calls.

                  You could force this code to only execute once on the series of your choice by using BarsInProgress.

                  So for example, just use && BarsInProgress == 0

                  Comment


                    #10
                    tonynt,

                    Basically, if you have 4 series added to your chart, it will call OnBarUpdate() whenever one of them gets updated. It can be as many as 4 times in a row if they are different instruments with the same timeframe, but if its different time frames it's possible it may be called 1-4 times. The point is that you could have the conditions you setup be true for the 4 series different OnBarUpdate calls.

                    If you are trying to execute trades on the primary series, using information from the secondary, etc. series, I would suggest using the following.

                    if ( BarsInProgress == 0 ) // continue with you entrance/exit code.
                    Adam P.NinjaTrader Customer Service

                    Comment


                      #11
                      Adam,

                      Yes, I want to do execute trades on the primary dataseries using informations from 2nd, 3rd... dataseries. But this I think I wrote at the beginning. So, why did you suggest me in your first reply to remove BarsInProgress. Now you suggest to use
                      ( BarsInProgress == 0 )

                      ???

                      Thanks
                      Tony


                      Originally posted by NinjaTrader_AdamP View Post
                      tonynt,

                      Basically, if you have 4 series added to your chart, it will call OnBarUpdate() whenever one of them gets updated. It can be as many as 4 times in a row if they are different instruments with the same timeframe, but if its different time frames it's possible it may be called 1-4 times. The point is that you could have the conditions you setup be true for the 4 series different OnBarUpdate calls.

                      If you are trying to execute trades on the primary series, using information from the secondary, etc. series, I would suggest using the following.

                      if ( BarsInProgress == 0 ) // continue with you entrance/exit code.

                      Comment


                        #12
                        tonynt,

                        Sorry for the confusion here.

                        I suggested you remove this :

                        && BarsInProgress ==3
                        && BarsInProgress ==5
                        && BarsInProgress ==8

                        Because its a condition that will never be true. If you use BarsInProgress == 0, and just that, it will do what you want here and eliminate the code from executing on the different series OnBarUpdate() calls.
                        Adam P.NinjaTrader Customer Service

                        Comment


                          #13
                          Adam,

                          thx. So, with these multi-dataseries I do not "if BarsInProgress !=0" but I do
                          in my condtions - even when checking several dataseries - ONLY "if BarsInProgess == 0".

                          And my intention starting this question was to know how to do when I start the strategy from another chart (other dataseries than 0). Eg when execution should be on close of bar of 3rd dataseries then I change in my conditions "if BarsInProgress == 3" && Closes[3][0]>Closes[3][1] &&HMA(BarsArray 5) && SMA(BarsArray 8)....

                          Got it?

                          Thanks
                          Tony


                          Originally posted by NinjaTrader_AdamP View Post
                          tonynt,

                          Sorry for the confusion here.

                          I suggested you remove this :

                          && BarsInProgress ==3
                          && BarsInProgress ==5
                          && BarsInProgress ==8

                          Because its a condition that will never be true. If you use BarsInProgress == 0, and just that, it will do what you want here and eliminate the code from executing on the different series OnBarUpdate() calls.

                          Comment


                            #14
                            TonyNT,

                            BarsInProgress == 0 is always referencing the series from the chart that you attached the strategy to.

                            If you want to submit your orders on a separate series, you would do as you have said :

                            Code:
                            And my intention starting this question was to know how to do when I start the strategy from another chart (other dataseries than 0). Eg when execution should be on close of bar of 3rd dataseries then I change in my conditions "if BarsInProgress == 3" && Closes[3][0]>Closes[3][1] &&HMA(BarsArray 5) && SMA(BarsArray 8)....
                            Adam P.NinjaTrader Customer Service

                            Comment


                              #15
                              Adam,

                              Things could be much easier if the BarsInProgress 'index' could optionally be put inside the brackets of the OnBarUpdate() method (e.g., OnBarUpdate(0)).

                              That way you could eliminate the need to set up the IF conditional statement and just separate code under the appropriate call. Making it an option would maintain compatibility with existing code.

                              Do you know if there are any other similarly called methods (OnExecution(), OnOrderUpdate(), OnStartup(), OnConnection) which have indexes. And also, how does the BarsInProgress index work inside these other methods?
                              Last edited by borland; 08-22-2012, 11:06 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              70 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              42 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              25 views
                              0 likes
                              Last Post Deep42
                              by Deep42
                               
                              Started by TheRealMorford, 03-05-2026, 06:15 PM
                              0 responses
                              28 views
                              0 likes
                              Last Post TheRealMorford  
                              Started by Mindset, 02-28-2026, 06:16 AM
                              0 responses
                              54 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Working...
                              X