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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    161 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    308 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    245 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    349 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    179 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X