Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What is difference between "Look Back Period" and "Bars Ago" in Strategy Wizard?

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

    What is difference between "Look Back Period" and "Bars Ago" in Strategy Wizard?

    What is difference between "Look Back Period" and "Bars Ago" in Strategy Wizard?

    In attached screenshot please see
    -Blue arrow showing the ""Look Back Period" iIam talking about
    -Red arrows showing the "Bars Ago" feature I am talking about

    I have done various tests, but am still having trouble finding out how they differ.


    Thanks!
    Attached Files

    #2
    Hello Matheyas5,


    The Look Back Period is referring to the lookBackPeriod paramter for your CrossAbove() method. This value represents the number of bars back to check the cross above condition. If you use 5 like in your image, then the condition would be true if your indicator crossed above your compared value within the last 5 bars.


    Bars ago in Ninjatrader represents the number of bars from the current bar on which you want to calculate your values. To calculate your indicator method on the current bar, use 0. To calculate your indicator method on the previous bar, use 1, and so on.
    Shawn B.NinjaTrader Customer Service

    Comment


      #3
      Hi Shawn,

      One follow up question to this.

      I'd like to use the Strategy Wizard to send a signal if there was a CrossAbove() exactly 5 bars ago. Rather then send a signal if there was a CrossAbove() within the last 5 bars.

      I tried doing this via changing the Lookback Period (circled in blue) from 5 to 1 in the screenshot in post #1 of this thread and leaving both "bars ago" inputs (circled in red) set to 5.

      This did not seem to work. And I don't see anything in the resulting code (shown below) that look like it mentions 5 Bars Ago.
      Code:
      if (CrossAbove(MACD(12, 26, 9).Avg, MACD(12, 26, 9), 1))
      Any idea why this is?

      Thanks!

      Comment


        #4
        Hi Matheyas5,

        This would not be directly possible using CrossAbove or CrossBelow. The Cross methods allow for a look back period (within x bars) but does not have a bars ago index.

        This is because CrossAbove does not return a dataseries or boolseries that can be used to find a cross 5 bars ago.

        From the Strategy Wizard, the work around would be to create the logic of this check.
        Code:
        if (IndicatorA[6] < IndicatorB[6] && IndicatorA[5] > Indicator2[5])
        This would detect a cross 5 bars ago. If indicatorA is less than indicatorB 6 bars ago and then is greater than 5 bars ago, then it crossed above 5 bars ago.

        An alternative would be to unlock the script and create a boolseries. Set the value of the current bar of the bool series to the true or false value of CrossAbove.

        Code:
        In #region properies:
        private BoolSeries crossAboves;
        
        In Initialize():
        crossAboves = new BoolSeries(this);
        
        In OnBarUpdate() (or other method):
        crossAboves = CrossAbove(IndicatorA, IndicatorB, 1);
        if (crossAboves[5] == true)
        {
        // execute code
        }
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ShawnB View Post
          Hello Matheyas5,


          The Look Back Period is referring to the lookBackPeriod paramter for your CrossAbove() method. This value represents the number of bars back to check the cross above condition. If you use 5 like in your image, then the condition would be true if your indicator crossed above your compared value within the last 5 bars.


          Bars ago in Ninjatrader represents the number of bars from the current bar on which you want to calculate your values. To calculate your indicator method on the current bar, use 0. To calculate your indicator method on the previous bar, use 1, and so on.


          Bars Ago with 0 value is actual bar or last bar closed?

          Comment


            #6
            Yes, generally speaking, BarsAgo=0 is the most recently closed bar.

            Don't use expression "actual bar" -- no one knows what that means.

            -=o=-

            Technically, a more precise answer depends on CalcuateOnBarClose.

            The expression "actual bar" is too vague, so I don't recommend
            that term. Saying "current bar" always means "CurrentBar", which
            is an integer property in NinjaScript, so that term is taken.

            I always use these self-explanatory terms, because they are precise,
            "Most recently closed bar"
            "Active bar under construction"

            To wit, here is a table of how it works,

            COBC=True
            BarsAgo=1 is next recently closed bar.
            BarsAgo=0 is most recently closed bar.
            Active bar under construction is not accessible.

            COBC=False
            BarsAgo=2 is next recently closed bar.
            BarsAgo=1 is most recently closed bar.
            BarsAgo=0 is active bar under construction.

            See that?
            The meaning of the BarsAgo index stays the same, but the values
            shift by 1 when you set COBC=False.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by maybeimnotrader, Yesterday, 05:46 PM
            1 response
            18 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by Perr0Grande, Yesterday, 08:16 PM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by f.saeidi, Yesterday, 08:12 AM
            3 responses
            25 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by algospoke, Yesterday, 06:40 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by quantismo, Yesterday, 05:13 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Working...
            X