Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MAX (Highest High) of an indicator

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

    MAX (Highest High) of an indicator

    Hi, I am trying to build an indicator to calculate the 20 period highest value of an indicator.
    So I tried to use MAX.

    If I use it for volume, it works fine like in the formula below:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 10) return;

    if(Volume[0] > MAX(Volume, 20)[1])
    Plot1.Set(Volume[0] );
    }

    But if I change it to Range(wich is an indicator), for example:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 10) return;

    if(Range[0] > MAX(Range, 20)[1])
    Plot1.Set(Range[0] );
    }


    I get the error message: " Cannot apply indexing with [] to an expression of type 'method Group'.
    So it seems that I cannot reference any indicator when using MAX.
    Then I tried to name it:
    double MyRange = High[0]-Low[0];

    and put it in the formula but get a message saying that I cannot have a double in there.

    Please, can someone help me find the way to do it?
    Thanks.

    #2
    Hello marreta,

    Thank you for your post.

    You would reference Range as Range(), below is the corrected code:
    Code:
    protected override void OnBarUpdate()
    {
    if (CurrentBar < 10) return;
    
    if(Range()[0] > MAX(Range(), 20)[1])
    Plot1.Set(Range()[0] );
    }

    Comment


      #3
      Thanks Patrick, I already tried that , but doens't plot anything in the indicator panel.

      Then I copied the exact same script as the Range indicator that comes with NT, and only changed your example :
      if(Range()[0] > MAX(Range(), 20)[1]);
      Value.Set(Range()[0]);

      No success

      Atached are the cs and picture files
      Thanks
      Attached Files

      Comment


        #4
        marreta, you did not include the check for enough bars to be present that Patrick had in his example -

        if (CurrentBar < 10) return;

        This would go at the top of your OnBarUpdate() method.

        Presently I would expect you see a log error once the study is applied, notifying you that you tried to access an invalid bar.

        Comment


          #5
          Great Bertrand, now it's working.
          Just for curiosity , why does the Range formula has not ( if (CurrentBar < 10) return; ) or anything, and it works ?
          I just copied the hole thing like I said in my last comment.

          Thank you!
          Last edited by marreta; 10-15-2014, 07:35 PM.

          Comment


            #6
            marreta, glad to hear that update - the basic range formula does not work with any prior bars in its calculations - so there would be no such check needed.

            Comment


              #7
              I'm trying to pretty much the same thing, but only put an arrow on the chart when the volume of the current bar is greater than the previous 20 bars.

              Using this line of code for the check:

              if (Volume[0] > MAX(Volume,20)[1])

              I only get the last occurrence of the condition on the chart. How can I get all the historical true occurrences?

              Comment


                #8
                Hello tiger45,

                Thank you for your post.

                You are likely using the same tag each time the arrow is drawn. This will cause the arrow to only be drawn once and replace itself every time the condition is true. To correct this you can add a variable that changes with the bars such as CurrentBar. For example:
                Code:
                DrawArrowUp(CurrentBar+"myTag", true, 0, Low[0] - (4*TickSize), Color.Green);
                For information on CurrentBar please visit the following link: http://www.ninjatrader.com/support/h...currentbar.htm

                Please let me know if I may be of further assistance.

                Comment


                  #9
                  Yes, that was it. Thanks.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  566 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  330 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  547 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  548 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X