Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator in Strategy

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

    Indicator in Strategy

    Hello.

    I have a indicator with 3 plots.

    How can i get the plots values of the indicator inside a strategy?

    I save in my indicator the last 10 ticks and if I use "MyIndicador(150)[0]", it loose the ticks saved. I have tried to initialize the indicator in the strategy "OnStateChange" but it do not work.

    PD: Sry for my english.

    Thank.

    #2
    Hello hectorzx,

    Thank you for writing in.

    As you have mentioned OnStateChange(), are you referring to NinjaTrader 8?

    To call different plots of an indicator, you'll want to access the Values collection.

    With three plots on your indicator, Values[0] would denote the first plot, Values[1] the second, and Values[2] the third. The order of these plots is determined by the order of the AddPlot() methods in your indicator's script.

    Example:
    Code:
    // this will print the current value of the indicator's first plot
    Print(MyIndicator(150).Values[0][0]);
    
    // this will print the current value of the indicator's second plot
    Print(MyIndicator(150).Values[1][0]);
    
    // this will print the current value of the indicator's third plot
    Print(MyIndicator(150).Values[2][0]);
    Alternatively, if you have created your indicator plots through the indicator wizard (and did not manually generate them), the indicator will have public properties that your strategy can access instead.

    Here is an example indicator below:
    Code:
    public class MyIndicator : Indicator
    {
         protected override void OnStateChange()
         {
              if (State == State.SetDefaults)
                   AddPlot(Brushes.Orange, "A");
         }
    
         [Browsable(false)]
         [XmlIgnore]
         public Series<double> A
         {
              get { return Values[0]; }
         }
    }
    You can just access the current value of your A plot from your strategy by:
    Code:
    Print(MyIndicator(150).A[0]);
    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    558 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    324 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    101 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    545 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    547 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X