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

Using SMA Indicator on two exposed doubles

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

    Using SMA Indicator on two exposed doubles

    I've created a simple Indicator that exposes two double Series called foo and bar. I am trying to add an SMA to a chart and reference one of these however, they do not show up, Here is the Indicator that exposes the doubles:

    Code:
        public class SampleDoubleSeries : Indicator
        {
            private Series<double> foo;
            private Series<double> bar;
    
            protected override void OnStateChange()
            {
                if(State == State.SetDefaults)
                {
                    Name                    = "Sample Double series";
                    Calculate                = Calculate.OnBarClose;
                    IsOverlay                = true;
                }
    
                else if(State == State.Configure)
                {
                    foo            = new Series<double>(this);
                    bar            = new Series<double>(this);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if(CurrentBar < 0) return;
                foo[0] = Close[0];
                bar[0] = Open[0];
            }
    
            #region Properties
            [Browsable(false)]
            [XmlIgnore]
            public Series<double> Foo
            {
                get { return foo; }    
            }
    
            [Browsable(false)]
            [XmlIgnore]        
            public Series<double>  Bar
            {
                get { return bar; }    
            }
            #endregion
        }
    When I try to reference my SampleDoubleSeries Indicator from the SMA preferences window, I don't see a way to choose either one of my series names foo or bar. Any suggestions would be appreciated.

    #2
    Hello swooke,

    Thanks for your post.

    Exposing a Series object will not make it appear on the property grid. This would be used if you would like to access the Series object as MyInstantiatedSampleDoubleSeries.Foo[0] or MyInstantiatedSampleDoubleSeries.Bar[0] from a hosting script.

    If you want to access a Series as the input series for another indicator, a plot must be used.

    AddPlot - https://ninjatrader.com/support/help...8/?addplot.htm

    Note that you can take the same approach as you are to expose a public Series object, but have the public Series object return the Values[] associated with that plot. The MACD indicator can be used as a reference for how this is done.

    Please let us know if you have any additional questions.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by llanqui, Today, 11:10 AM
    1 response
    15 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by reynoldsn, 05-10-2024, 07:04 PM
    2 responses
    23 views
    0 likes
    Last Post reynoldsn  
    Started by llanqui, Today, 10:29 AM
    1 response
    12 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by Trader146, 05-10-2024, 09:17 PM
    1 response
    22 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by bourasrafik, Today, 03:26 PM
    0 responses
    5 views
    0 likes
    Last Post bourasrafik  
    Working...
    X