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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    127 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    73 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    115 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    109 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    88 views
    0 likes
    Last Post CarlTrading  
    Working...
    X