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 SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    21 views
    0 likes
    Last Post SalmaTrader  
    Started by CarlTrading, 07-05-2026, 01:16 PM
    0 responses
    11 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 05-29-2026, 05:09 AM
    0 responses
    622 views
    0 likes
    Last Post CaptainJack  
    Started by CaptainJack, 05-29-2026, 12:02 AM
    0 responses
    420 views
    0 likes
    Last Post CaptainJack  
    Started by charlesugo_1, 05-26-2026, 05:03 PM
    0 responses
    293 views
    1 like
    Last Post charlesugo_1  
    Working...
    X