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

ATR based on daily period

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

    ATR based on daily period

    With there being the primary(5min) and the 2 indexes in the script below, in the condition set how do I have the ATR be based on index 1 which would be 14 period based on daily?

    protected override void Initialize()
    {Add(PeriodType.Day, 1);
    Add(PeriodType.Day, 5);
    CalculateOnBarClose = true;
    }

    protected override void OnBarUpdate()
    {
    // Condition set 1
    if ((Close[0] > Highs[2][0]) && ((Highs[1][0] - Lows[1][0]) > ATR(14)[0] * .75))
    {
    EnterLong(200);
    }
    }

    #2
    Hi zachj, no you would need to base the ATR for example on BarsArray[1] here and then also apply a filter to your condition in OnBarUpdate() to only execute it in a certain BarsInProgress, for example the primary one -



    BertrandNinjaTrader Customer Service

    Comment


      #3
      Is this correct below. The first if statement can use any of the bars in progress(or any of the indexes) and the third if statement will only use index 1?

      protected
      overridevoid OnBarUpdate()
      {

      // Condition set 1
      if (Close[0] > Highs[2][0] && Close[0] < Lows[1][0] * 1.05)

      if (BarsInProgress == 1)

      if (Highs[1][0] - Lows[1][0] > ATR(BarsArray[1], 14)[0]*.75)
      {
      EnterLong(
      200);
      }
      }

      Comment


        #4
        Any statement can use any BarsArray (or Highs, Lows etc for that matter). The difference is then with BarsInProgress when it will be processed, so on which series calling OnBarUpdate - that's the filter here.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Ok so the process order I have is correct then? The first if statement calls onbarupdate allowing any of the series thru. Then the third if statement calls onbarupdate only allowing the secondary series through due to barsinprogress? Then it will enter long if everything passes.

          Comment


            #6
            You're understanding is correct, I'm not sure though why you would seek to have the first statement not filtered by a BIP.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              How can it be filtered when its using multiple series? The script below is close of primary > High of index 3
              or basically current price on 5min > weekly high

              Close[0] > Highs[2][0]

              Comment


                #8
                The filtering is not for which series you could access in their values and which not - it would be the event on which the code is called an evaluated, meaning the close / update of your primary or added series. You can still access all streams from both series update events.
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Im not getting it, isnt it needing to call and evaluate both events in both series? What am I needing to filter.

                  Comment


                    #10
                    Before progressing in that area I would suggest reading through this info and examples here - http://www.ninjatrader.com/support/h...nstruments.htm

                    The data series you've added is accessible from any series, however the filter would decide from which event you're acting on the condition - do you want to check the condition when series 0 updates, or do you want it from series 1?

                    So it's two moving pieces here - the bar update event fired for each series, which is determined by BarsInProgress and the actual reference to the price data array for each series you added.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #11
                      Ok so basically I would want it to act on the primary 5min current price data seeing that's what's changing, the highest price in the last week is not changing. So now I have the following correct?...

                      protectedoverridevoid OnBarUpdate()
                      {

                      // Condition set 1
                      if (BarsInProgress == 0)
                      if (Close[0] > Highs[2][0] && Close[0] < Lows[1][0] * 1.05
                      )

                      if (BarsInProgress == 1
                      )
                      if (Highs[1][0] - Lows[1][0] > ATR(BarsArray[1], 14)[0]*.75
                      )
                      {
                      EnterLong(
                      200
                      );
                      }
                      }

                      Comment


                        #12
                        Is the logic below correct?

                        Comment


                          #13
                          zachj, I would work for both conditions and your entry from the primary series so BIP = 0. As you just want to access the higher timeframe info / prices.
                          BertrandNinjaTrader Customer Service

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Segwin, 05-07-2018, 02:15 PM
                          14 responses
                          1,788 views
                          0 likes
                          Last Post aligator  
                          Started by Jimmyk, 01-26-2018, 05:19 AM
                          6 responses
                          837 views
                          0 likes
                          Last Post emuns
                          by emuns
                           
                          Started by jxs_xrj, 01-12-2020, 09:49 AM
                          6 responses
                          3,293 views
                          1 like
                          Last Post jgualdronc  
                          Started by Touch-Ups, Today, 10:36 AM
                          0 responses
                          13 views
                          0 likes
                          Last Post Touch-Ups  
                          Started by geddyisodin, 04-25-2024, 05:20 AM
                          11 responses
                          63 views
                          0 likes
                          Last Post halgo_boulder  
                          Working...
                          X