Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by helpwanted, Today, 03:06 AM
    1 response
    11 views
    0 likes
    Last Post sarafuenonly123  
    Started by Brevo, Today, 01:45 AM
    0 responses
    9 views
    0 likes
    Last Post Brevo
    by Brevo
     
    Started by aussugardefender, Today, 01:07 AM
    0 responses
    5 views
    0 likes
    Last Post aussugardefender  
    Started by pvincent, 06-23-2022, 12:53 PM
    14 responses
    242 views
    0 likes
    Last Post Nyman
    by Nyman
     
    Started by TraderG23, 12-08-2023, 07:56 AM
    9 responses
    387 views
    1 like
    Last Post Gavini
    by Gavini
     
    Working...
    X