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

Wrong value of Stochastics %D in ninjatrader strategy

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

    Wrong value of Stochastics %D in ninjatrader strategy

    In my OnBarUpdate(), the return value of Stochastics(7,14,3).D[0] is always either 100 or 0.
    In NT8, how to obtain stochastics %D value ?

    Thanks!

    #2
    Hello marketstudent,

    Thanks for your post.

    Using the following print statement: Print ("CB: "+CurrentBar+" D Value: "+Stochastics(7,14,3).D[0]);

    I see the following (From CL 02-17 3 minute):

    CB: 3423 D Value: 24.2944985011549
    CB: 3424 D Value: 28.1202393238
    CB: 3425 D Value: 35.1884613494524
    CB: 3426 D Value: 44.689501531607
    CB: 3427 D Value: 55.7532720690615
    CB: 3428 D Value: 63.9462292093868

    Do you see any error messages in the "Log" tab of the control center that relate to the Ninjascript you have coded?

    If no errors can you copy the print statement example and test to see if you get values between 0 and 100 printed in the output window (File>Ninjascript Output)?
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Hello Paul,

      I used the same code below to check stochastics %D value. The instrument is FXCM currency pair. I tried all the currency pairs, they gave the same result, either 0 or 100. I am not sure how to proceed forward from here.

      Thanks!

      if (CurrentBar < BarsRequiredToTrade){

      Print("Strategy - Instrument Name=" + Instrument.FullName + ",\tCurrentBar = " + CurrentBar + ",\t BarsRequiredToTrade=" + BarsRequiredToTrade);
      return;

      }
      //Add your custom strategy logic here.
      string alertid = Instrument.FullName + ", " + BarsPeriod.Value + " " + BarsPeriod.BaseBarsPeriodType;
      String message;
      message = alertid + " Stratgegy" + " stochastics D value = " + Stochastics(7,14,3).D[0].ToString();
      Print(message);

      Comment


        #4
        Hello marketstudent,

        Thanks for your reply.

        I used my code on Forex and had expected results.

        I used your code, in a strategy, and produced expected results (small sample):
        Strategy - Instrument Name=EURUSD, CurrentBar = 17, BarsRequiredToTrade=20
        Strategy - Instrument Name=EURUSD, CurrentBar = 18, BarsRequiredToTrade=20
        Strategy - Instrument Name=EURUSD, CurrentBar = 19, BarsRequiredToTrade=20
        EURUSD, 5 Minute Stratgegy stochastics D value = 32.0026417726305
        EURUSD, 5 Minute Stratgegy stochastics D value = 35.34811955306
        EURUSD, 5 Minute Stratgegy stochastics D value = 40.4593679318007
        EURUSD, 5 Minute Stratgegy stochastics D value = 48.2838596907854
        EURUSD, 5 Minute Stratgegy stochastics D value = 57.7801124457674

        Can you provide further information about your data source such as whom you are connected to.

        Do you see stochastics on your chart?
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hi Paul,

          The code works for single instrument strategy, but not for strategy with multiple instruments. In my strategy's OnStateChange(), I have the code block below to add multiple instruments. The question is how to obtain correct stochastics %D value when strategy has multiple instruments.

          Thanks!


          else if (State == State.Configure)
          {
          Print("TrendResume Strategy - BarsPeriodType:" + BarsPeriod.BaseBarsPeriodType + " \t BarsPeriodValue:" + BarsPeriod.Value);

          AddDataSeries("AUDCHF", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
          AddDataSeries("AUDJPY", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
          AddDataSeries("AUDNZD", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
          }

          Comment


            #6
            Hello marketstudent,

            Thanks for your reply.

            In a multi series or multi time frame all of the references can change depending on which BarsArray calls the OnBarUpdate() method. There is also more than one way to code this. Please review the helpguide on multi series/time coding as there are critical concepts to understand before coding. Here is a link: http://ninjatrader.com/support/helpG...nstruments.htm

            one short answer:
            Stochastics(BarsArray[0], 7,14,3).D[0] will point to the base/chart bars
            Stochastics(BarsArray[1], 7,14,3).D[0] will point to (in your example) AUDCHF
            Stochastics(BarsArray[2], 7,14,3).D[0] will point to (in your example) AUDJPY
            Stochastics(BarsArray[3], 7,14,3).D[0] will point to (in your example) AUDNZD
            Paul H.NinjaTrader Customer Service

            Comment


              #7
              Paul,

              Got it. Thanks for the clarification !

              Comment


                #8
                Paul,

                I modified the code, the code is attached below for your review. The primary instrument is AUDCAD.
                In the NinjaScript Output, only the primary instrument's Stochastics %D has correct value, the Secondary instruments got either 100 or 0 in their stochastics %D value.

                Please check !

                protected override void OnStateChange() {
                ....
                else if (State == State.Configure)
                {
                Print("TrendResume Strategy - BarsPeriodType:" + BarsPeriod.BaseBarsPeriodType + " \t BarsPeriodValue:" + BarsPeriod.Value);

                AddDataSeries("AUDCHF", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
                AddDataSeries("AUDJPY", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
                AddDataSeries("AUDNZD", BarsPeriod.BaseBarsPeriodType, BarsPeriod.Value);
                }

                }
                protected override void OnBarUpdate()
                {
                //Add your custom strategy logic here.

                if (CurrentBar < BarsRequiredToTrade){

                Print("Instrument Name=" + Instrument.FullName + ",\tCurrentBar = " + CurrentBar + ",\t BarsRequiredToTrade=" + BarsRequiredToTrade);
                return;

                }
                //Add your custom strategy logic here.
                string alertid = Instrument.FullName + ", " + BarsPeriod.Value + " " + BarsPeriod.BaseBarsPeriodType + ", BarsInProgress=" + BarsInProgress;
                String message;
                message = alertid + ", stochastics D value = " + Stochastics( BarsArray[BarsInProgress],7,14,3).D[0].ToString();
                Print(message);

                return;
                }

                Comment


                  #9
                  Hello marketstudent,

                  Thanks for your reply.

                  I have been able to replicate the multi series incorrect/unexpected results of Stochastics.

                  We will investigate and update this thread when we have further information.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello marketstudent,

                    If you haven't already, please update to 8.0.4.0 and test to see if you have the same results.
                    Paul H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kempotrader, Today, 08:56 AM
                    0 responses
                    6 views
                    0 likes
                    Last Post kempotrader  
                    Started by kempotrader, Today, 08:54 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post kempotrader  
                    Started by mmenigma, Today, 08:54 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post mmenigma  
                    Started by halgo_boulder, Today, 08:44 AM
                    0 responses
                    1 view
                    0 likes
                    Last Post halgo_boulder  
                    Started by drewski1980, Today, 08:24 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post drewski1980  
                    Working...
                    X