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

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 cls71, Today, 04:45 AM
    0 responses
    1 view
    0 likes
    Last Post cls71
    by cls71
     
    Started by mjairg, 07-20-2023, 11:57 PM
    3 responses
    213 views
    1 like
    Last Post PaulMohn  
    Started by TheWhiteDragon, 01-21-2019, 12:44 PM
    4 responses
    544 views
    0 likes
    Last Post PaulMohn  
    Started by GLFX005, Today, 03:23 AM
    0 responses
    3 views
    0 likes
    Last Post GLFX005
    by GLFX005
     
    Started by XXtrader, Yesterday, 11:30 PM
    2 responses
    12 views
    0 likes
    Last Post XXtrader  
    Working...
    X