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 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.
    JesseNinjaTrader Customer Service

    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]);
        }
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        834 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,290 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        10 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        62 views
        0 likes
        Last Post halgo_boulder  
        Started by Option Whisperer, Today, 09:55 AM
        0 responses
        8 views
        0 likes
        Last Post Option Whisperer  
        Working...
        X