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

Stochastics Max Minimum

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

    Stochastics Max Minimum

    Never modified plotting of an indicator before and need to know if it possible to change the max and minimum values for Stochastics that came with NT7? My strategy parameters combined with my chart type max it out so my strategy does not see it as rising. Thought about having an equal to ## as rising no longer works when maxed out. Would prefer to have the indicator modified though. I have reviewed the script and nothings jumps out at me, can you point me in the right direction?

    #2
    Hello Hammerhorn,

    Thank you for your post.

    Can you provide an example of the maxed out Stochastics on your chart?

    If possible please provide a screenshot of this plotted on your chart.

    I look forward to your response.

    Comment


      #3
      See attached image. Thank you.
      Attached Files

      Comment


        #4
        Hello Hammerhorn,

        Thank you for your response.

        The following line checks to see if the fastK's calculations are greater than 100, if so it defaults the value to 100:
        Code:
        fastK.Set(Math.Min(100, Math.Max(0, 100 * nom[0] / den[0])));
        You could remove the Math.Min aspect of this if you did not wish to limit it to 100:
        Code:
        fastK.Set(Math.Max(0, 100 * nom[0] / den[0]));
        You would need to right click in the Stochastics NinjaScript Editor and select Save As to give the file a new name in order to edit it.

        Comment


          #5
          Originally posted by Hammerhorn View Post
          Never modified plotting of an indicator before and need to know if it possible to change the max and minimum values for Stochastics that came with NT7? My strategy parameters combined with my chart type max it out so my strategy does not see it as rising. Thought about having an equal to ## as rising no longer works when maxed out. Would prefer to have the indicator modified though. I have reviewed the script and nothings jumps out at me, can you point me in the right direction?
          The problem is not only the MAX or MIN function. The Stochastics indicator simply does what it is supposed to do. With a short lookback period and your UniRenko bars - which smooth price action - you will quickly drive the Stochastics to the maximum value. This is as expected, if you look at the Stochastics formula.

          If you wish that the Stochastics is driven to higher values than 100, you would need to replace the SMA in the Stochastics formula with an infinite impulse response (IIR) filter, which has a reduced lag and overshoots the input variable.

          One example for an appropriate IIR filter would be the Tillson T3, for which the amplification can be set to a larger value then 0.7. It will then show the desired behavior of overshooting the input variable. The T3 is a system indicator, so you just need to replace the SMA in the Stochastics formula with the T3. Use the same period as for the SMA, and set the vFactor to 1. Here is the code:

          Code:
          protected override void OnBarUpdate()
          {
                nom.Set(Close[0] - MIN(Low, PeriodK)[0]);
                den.Set(MAX(High, PeriodK)[0] - MIN(Low, PeriodK)[0]);
          
                if (den[0].Compare(0, 0.000000000001) == 0)
                      fastK.Set(CurrentBar == 0 ? 50 : fastK[1]);
                else
                      fastK.Set(100 * nom[0] / den[0]);
          
                K.Set(T3(fastK, Smooth, 3, 1)[0]);
                D.Set(T3(K, PeriodD, 3, 1)[0]);
           }
          A chart with the StochasticsT3 is attached.

          You could also make experiments with a Hull moving average (HMA) or a Kalman filter.
          Attached Files

          Comment


            #6
            Originally posted by Hammerhorn View Post
            Never modified plotting of an indicator before and need to know if it possible to change the max and minimum values for Stochastics that came with NT7? My strategy parameters combined with my chart type max it out so my strategy does not see it as rising. Thought about having an equal to ## as rising no longer works when maxed out. Would prefer to have the indicator modified though. I have reviewed the script and nothings jumps out at me, can you point me in the right direction?
            What you need to do is write the spec to handle all the instances that you will encounter, then code it.

            Code:
             
            Pseudocode:
            if (rising)
            {
            //what to do 1
            }
            else if (falling)
            {
            //what to do 2
            }
            else if (maxedOut)
            {
            //what to do 3
            }
            else if (minPegged)
            {
            //what to do 4
            }
            You cannot increase or decrease the maximum or minimum values of the Stochastics indicator. Look at the formula and you will see that the max and min are always going to be 100 and 0. Of course, you can multiply all values by a factor, but that just serves to change absolute values: relative values and hence any logic that depends on the values will not change.

            Comment


              #7
              Harry - Thank you very much. StochasticsT3 is just beautiful. Thanks for the code, saved me some headache time.

              Koganam - If Harry's advice did not work I would have then reverted to you example. I need to know how to do that anyway, so thanks again.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              2 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              38 views
              0 likes
              Last Post love2code2trade  
              Started by alifarahani, Today, 09:40 AM
              2 responses
              14 views
              0 likes
              Last Post alifarahani  
              Started by junkone, Today, 11:37 AM
              3 responses
              20 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by frankthearm, Yesterday, 09:08 AM
              12 responses
              44 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X