Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using Existing Indicators

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

    Using Existing Indicators

    I'd like to use a Stochastics indicator in a custom indicator.

    Can anyone help or point me in the right direction?

    e.g. Stochastics myStoch = new Stochastics(Closes[1], 3, 14, 7) and can this be placed in Initialize()?

    and

    1. how to reference the data in Stochastics e.g. D & K from the custom indicator

    2. how to re-set the parameters in Stochastics
    Last edited by futurenets; 02-24-2015, 10:45 AM.

    #2
    Hello,

    Thank you for the question.

    In a NinjaScript file there is no need to create a new instance of the object you are referring to, so to access any indicator you just need to call it by name.

    You can look at each included indicator in the help guide, here is the Stochastic: http://www.ninjatrader.com/support/h...tochastics.htm

    In the help guide we can see this indicators needs one of the following two basic overload options:

    Stochastics(int periodD, int periodK, int smooth)
    Stochastics(IDataSeries input, int periodD, int periodK, int smooth)


    You can call this with just using the Periods you want, or you can specify that this indicator will calculate off of a specific data series such as Close, Open, Low, High vaues.

    Here is an example on how to use the Stochastics.

    Code:
    double stochPrice = Stochastics( 14, 10, 2)[0];
    First we decalre a type of double, this would be a simple variable for the value the Stochastics is returning.

    the [0] at the end of the indicator call defines we want the price from 0 bars ago or the current bar. You can do the same call but use a bars ago to access values from the past.

    Here is an example using the DataSeries overload:

    Code:
    double stochPrice = Stochastics(Open, 14, 10, 2)[0];
    
    or
    
    double stochPrice = Stochastics(High, 14, 10, 2)[0];
    
    or
    
    double stochPrice = Stochastics(Close, 14, 10, 2)[0];
    Please let me know if I may be of additional assistance.

    Comment


      #3
      or this?

      private Stochastics myStoch;

      OnStartUp() or Initialize()?
      myStoch = Stochastics(IDataSeries input, int periodD, int periodK, int smooth);

      OnBarUpdate()
      double myVar = myStoch[0];

      Comment


        #4
        Hello,

        This would not work in Initialize but in OnBarUpdate or OnStartUp it should work. This is not the documented or supported way but it is possible. I am not enti

        Here is an example using OnStartUp.

        Code:
        private Stochastics myStoch;
        		
        protected override void OnStartUp()
        {
        	  myStoch = Stochastics(Close, 14, 10, 2);
        }
        protected override void OnBarUpdate()
        {
        	Print(myStoch[0]);
        }

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        57 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        36 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        165 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        101 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        162 views
        2 likes
        Last Post CaptainJack  
        Working...
        X