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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        608 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        355 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X