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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    44 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    54 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    34 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    95 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    57 views
    0 likes
    Last Post PaulMohn  
    Working...
    X