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

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.
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            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 port119, Today, 02:43 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post port119
                  by port119
                   
                  Started by Philippe56140, Today, 02:35 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Philippe56140  
                  Started by 00nevest, Today, 02:27 PM
                  0 responses
                  1 view
                  0 likes
                  Last Post 00nevest  
                  Started by Jonafare, 12-06-2012, 03:48 PM
                  5 responses
                  3,986 views
                  0 likes
                  Last Post rene69851  
                  Started by Fitspressorest, Today, 01:38 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post Fitspressorest  
                  Working...
                  X