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 mattbsea, Today, 05:44 PM
        0 responses
        4 views
        0 likes
        Last Post mattbsea  
        Started by RideMe, 04-07-2024, 04:54 PM
        6 responses
        31 views
        0 likes
        Last Post RideMe
        by RideMe
         
        Started by tkaboris, Today, 05:13 PM
        0 responses
        2 views
        0 likes
        Last Post tkaboris  
        Started by GussJ, 03-04-2020, 03:11 PM
        16 responses
        3,282 views
        0 likes
        Last Post Leafcutter  
        Started by WHICKED, Today, 12:45 PM
        2 responses
        20 views
        0 likes
        Last Post WHICKED
        by WHICKED
         
        Working...
        X