• 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

ATR Indicator Method

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

    #16
    Hello DJ,
    I will simply use the below code

    In variable;
    Code:
    double HOD = 0;
    double LOD = 0;
    in OnBarUpdate
    Code:
    HOD = Math.Max(High[0], HOD);
    LOD = Math.Min(Low[0], LOD);
    Please let me know if I can assist you any further.
    Joydeep M.NinjaTrader Customer Service

    Comment


      #17
      I tried this and got an error about accessing an index with a value that is out of range.
      I tried to put the Plot.Set inside an if (BarsInProgress == 1) statement. Didn't work.
      I tried to add a BarsRequired statement so it wouldn't even get to Plot.Set unless there were more bars than the ATR period required. Didn't work.

      Works fine on a daily chart. Breaks on a tick or minute chart.

      Any suggestions?

      Code:
      Initialize()
      {
      Add(PeriodType.Day, 1);
      }
      
      OnBarUpdate()
      {
      Plot0.Set(ATR(Closes[1], 14)[0] >= 100 ? 1 : 0);
      }

      Comment


        #18
        Hello NinexTim,
        Please try the below code and see if you can get the values.

        Code:
        protected override void OnBarUpdate()
        {
        	if (CurrentBars[0] <0 || CurrentBars[1] < 1) return;
        	
        	Plot0.Set(ATR(Closes[1], 14)[0] >= 100 ? 1 : 0);
        }
        http://ninjatrader.com/support/forum...ead.php?t=3170
        Joydeep M.NinjaTrader Customer Service

        Comment


          #19
          Hi Joydeep,

          I have been following the code and convo here, however I am stuck now.

          I have added

          double atrDailyValue;
          double HOD = 0;
          double LOD = 0;

          Then I added Add(PeriodType.Day,1);

          In the barUpdate() I added:

          atrDailyValue = ATR(Closes[1], 14)[0];
          Print(ATR(Closes[1], 14)[0]);



          HOD = Math.Max(High[0], HOD);
          LOD = Math.Min(Low[0], LOD);

          Print(HOD);
          Print(LOD);

          // Checks to see if daily ATR has been met and if so no more trades will occur.
          if (HOD - LOD <= atrDailyValue)
          {

          What I am trying to do is add the daily chart in for multi timeframe.

          I then want to know the ATR of the daily chart and calculate the current high and low of the day.

          If the High of day - low of day > daily atr do not trade anymore.

          Please advise.

          Thanks

          Comment


            #20
            Hello twitch,
            My apologies, please change the below LOD variable as

            Code:
            double LOD = double.MaxValue;
            else the below line would always return 0 (zero).
            Code:
            LOD = Math.Min(Low[0], LOD);
            Joydeep M.NinjaTrader Customer Service

            Comment


              #21
              Thanks Joydeep,

              The bug has gone and it does not return zero, however it does not return the correct value for the low or high either? Please look on the 6E 03-13 chart daily timeframe.

              Then look at the atr and the HIGH and LOW using the code above.

              0.0107999999999999 is atr
              1.3274 is high
              1.3052 is low

              The chart is showing atr of 0.00679
              high of yesterday 1.3252
              low of yesterday 1.3183

              I am trying to say please use the High[0] of yesterday on the daily chart by using High(BarsArray[1],1)[0] however there is an error and it doesn work like the usual bars array I have seen.

              Please advise.

              Comment


                #22
                I have read that Highs[1][0] will return the secondary previous high.

                Please look at the 6E 03-13 chart and add a daily secondary chart into the code.

                From there print(Highs[1][0]);

                which should give the previous days high. this should be 1.3252 but it shows 1.3186 which is 3 days ago?? This has to be a bug with ninja? The code seems correct.

                Comment


                  #23
                  Sorry I need ot change what I am trying to acheive. Please bear with me.

                  I want to constantly check to see if the range of the present day has reached the daily ATR,

                  If this is true, then stop trading. How can I approach this please?

                  Thanks

                  Comment


                    #24
                    Hello twitch,

                    Please try using the below code to do it

                    Code:
                    //in Initialize
                    Add(PeriodType.Day, 1);
                    
                    //in OnBarUpdate
                    if (Range(Closes[1])[0] > ATR(Closes[1], 14)[0])
                    {  //do something  }
                    Joydeep M.NinjaTrader Customer Service

                    Comment


                      #25
                      Hi Joydeep,

                      This will calculate the range of the previous day? Not the current day which is trading?

                      I need to calculate the range of today and keep measuring the range on each bar update to see if the range of TODAY is more than the ATR(14).

                      The code you have given will calculate yesterday's range and compare to the ATR.

                      Finding it hard to constantly check todays range without getting the max of the session and low of session and comparing.

                      Comment


                        #26
                        Thanks Joydeep,

                        I used HOD = MAX(Highs[0], Bars.BarsSinceSession)[0];
                        LOD = MIN(Lows[0], Bars.BarsSinceSession)[0];

                        and it gives me the current high and low of the session in progress. Thanks!

                        Comment


                          #27
                          Originally posted by NinjaTrader_Joydeep View Post
                          Hello Gennaker,
                          You need to place only the Add code in the Initialize portion of the code.
                          Code:
                          Add(PeriodType.Day, 1);
                          The code will add a daily bar series
                          http://www.ninjatrader.com/support/h....html?add3.htm

                          Once you have the daily bar series added, you can call it from the OnBarUdpate method via the below code to calculate the ATR from the daily bar series.
                          Code:
                          double atrDailyValue = ATR(Closes[1], 14)[0];
                          http://www.ninjatrader.com/support/h...tml?closes.htm

                          If you can upload a sample strategy depicting the issue or email it to support[AT]ninjatrader[DOT]com I can look into it. If you mail it please add Attn:Joydeep in the subject line of the email and give reference of this thread in the body of the email.

                          Also please refer to the SampleMultiTimeFrame strategy that comes with NinjaTrader to get further reference on how to calculate an indicator value based on a different bar series.
                          In Control Center menu bar goto Tools>Edit NinjaScript>Strategies...
                          In the Strategies dialog select SampleMultiTimeframe and click the Ok button



                          I would also suggest you first read how a multi-series indicator works before code it. Please refer here and understand how multi-series indicator works
                          http://www.ninjatrader.com/support/h...nstruments.htm

                          Please let me know if I can assist you any further.


                          When I inserted your code into my strategy to call the daily WilliamsR indicator on a 5 minute chart:

                          Under Initialise:

                          Add(PeriodType.Day, 1); 




                          Onbarupdate:

                          double willRDailyValue = WilliamsR(Closes[1], 10)[0];



                          strategy conditions:

                          if (Position.MarketPosition == MarketPosition.Flat
                          && CurrentDayOHL().CurrentOpen[0] <= PriorDayOHLC().PriorHigh[0]
                          && willRDailyValue(10)[0]>=-20
                          && Bars.FirstBarOfSession
                          && Bars.TickCount <15)



                          {
                          EnterShort(DefaultQuantity, "Short");
                          }

                          I get error willDailyValue is a variable but is used like a method..... any ideas what I am doing wrong here?


                          also this barsarray reference doesnt seem to work either which is xtra strange.
                          && WilliamsR(BarsArray[1], 10)[0] >= -20
                          Last edited by elliot5; 11-14-2014, 05:30 AM. Reason: extra info

                          Comment


                            #28
                            everington_f, you already set a double value for your indicator here, so accessing should be done via

                            willRDailyValue >= -20
                            BertrandNinjaTrader Customer Service

                            Comment


                              #29
                              I know this is an old thread, but does passing Closes[1] to the ATR function allow it to calculate on the High/Low of that Dataseries that ATR actually needs or just the closing prices?

                              Comment


                                #30
                                Hello tomace,

                                Thanks for your post.

                                Yes, Closes[1] does allow the ATR to use the High/Low of the 1st added data series. An alternate approach is ATR(BarsArray[1], period).
                                Paul H.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by pjsmith, Today, 12:50 AM
                                0 responses
                                1 view
                                0 likes
                                Last Post pjsmith
                                by pjsmith
                                 
                                Started by quinton77, Yesterday, 09:59 PM
                                1 response
                                5 views
                                0 likes
                                Last Post NinjaTrader_EricB  
                                Started by akuntysh, Today, 12:02 AM
                                0 responses
                                2 views
                                0 likes
                                Last Post akuntysh  
                                Started by Revan, Yesterday, 11:53 PM
                                0 responses
                                4 views
                                0 likes
                                Last Post Revan
                                by Revan
                                 
                                Started by allangl, Yesterday, 10:50 PM
                                0 responses
                                7 views
                                0 likes
                                Last Post allangl
                                by allangl
                                 
                                Working...
                                X