Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to code a simple indicator that uses the price from x bars ago

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

    How to code a simple indicator that uses the price from x bars ago

    Hi All,

    I'm new to NT indicator development and have read some of the helpful steps in the guide but am struggling to create a simple indicator. Any advice or assistance would be greatly appreciated.

    I'm trying to create an indicator that is a simple line whose value is the closing price from x periods ago. e.g. 26 bars ago.

    I've tried the below, but nothing shows on the chart.

    Code:
    protected override void OnBarUpdate()
            {
                // Use this method for calculating your indicator values. Assign a value to each
                // plot below by replacing 'Close[0]' with your own formula.
                PriceXBarsAgo.Set(Close[26]);
            }
    Thanks in advance.

    David

    #2
    Hi David, welcome to the forums here - have you checked if you get an error shown in the NT log tab (the right most one in the Control Center) when you apply this script to a chart? That would likely be the case since you're not able to access the prior bars after you've passed bar 26 on your chart series (counted from the left most / starting bar with a value of 0). That's why typically a check for enough CurrentBars is added in the OnBarUpdate() section to ensure this access would only be tried if enough bars are available to work with - here's a dedicated tip on this mater - http://www.ninjatrader.com/support/f...ead.php?t=3170

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    648 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    369 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    108 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    572 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    573 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X