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 CarlTrading, 03-31-2026, 09:41 PM
    1 response
    54 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    29 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    40 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    56 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    47 views
    0 likes
    Last Post CarlTrading  
    Working...
    X