Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to default indicator to use high of bar in Ninjascript

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

    How to default indicator to use high of bar in Ninjascript

    Hello all,

    I am trying to cause an indicator... the MAX indicator that is pre-installed in NT8... to use the High of the bar instead of the close.

    I am familiar with creating a template Default once the indicator is on the chart. That doesn't seem to hold the High value choice if I set the template to default.

    Can I code this in Ninjascript after creating a copy of the standard MAX indicator?

    Somewhere in State.Configure by chance?

    For reference here is the most relevant code in the MAX indicator where I believe the change would need to be made...

    Code:
        else if (State == State.Configure)
        {
            lastBar        = 0;
            lastMax        = 0;
            runningMax    = 0;
            runningBar    = 0;
            thisBar        = 0;
        }
    }
    
    protected override void OnBarUpdate()
    {
        if (CurrentBar == 0)
        {
            runningMax    = Input[0];
            lastMax        = Input[0];
            runningBar    = 0;
            lastBar        = 0;
            thisBar        = 0;
            Value[0]    = Input[0];
           
    
           
            return;
        }
    
        if (CurrentBar - runningBar >= Period || CurrentBar < thisBar)
        {
            runningMax = double.MinValue;
            for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack > 0; barsBack--)
                if (Input[barsBack] >= runningMax)
                {
                    runningMax = Input[barsBack];
                    runningBar = CurrentBar - barsBack;
                }
        }
    
        if (thisBar != CurrentBar)
        {
            lastMax = runningMax;
            lastBar = runningBar;
            thisBar = CurrentBar;
        }
    
        if (Input[0] >= lastMax)
        {
            runningMax = Input[0];
            runningBar = CurrentBar;
        }
        else
        {
            runningMax = lastMax;
            runningBar = lastBar;
        }
    
        Value[0] = runningMax;​

    #2
    Hello MattD888,

    Thank you for your post.

    Yes, you could just create your own copy of the script and edit the code to use the High series for all of its calculations. You would need to replace the Input[] series with the High[] series.

    Please let us know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    556 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 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
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X