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 not working

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

    Stochastics not working

    My strategy isn't doing what it's suppose to do, so I decided to print out the indicator values to troubleshoot. And I found the problem.

    My strategy checks whether Stochastics K is greater than D:
    Stochastics(7, 14, 1).K[1] > Stochastics(7, 14, 1).D[1]

    And I print out the values and the comparison:
    Print("K: "+ Stochastics(7, 14, 1).K[1] +" D: "+ Stochastics(7, 14, 1).D[1]+ " "+ (Stochastics(7, 14, 1).K[1] > Stochastics(7, 14, 1).D[1]));

    Here's what I got:
    K: -9.80548975348938E-12 D: 64.2857142857133 False
    K: 99.999999999999 D: 99.9999999999992 False
    K: 40.0000000000003 D: 32.4247593774356 True
    K: -9.80548975348938E-12 D: 64.2857142857133 False
    K: 99.999999999999 D: 99.9999999999992 False
    K: 40.0000000000003 D: 32.4247593774356 True
    K: -9.80548975348938E-12 D: 64.2857142857133 False
    K: 99.999999999999 D: 99.9999999999992 False
    K: 40.0000000000003 D: 32.4247593774356 True

    It's giving me 3 different sets of values, of which, only the third one is what the actual values are, the 40 and 32 set. And btw, how is there a negative K value? And 99.999999999999 is definitely bigger than 99.9999999999992

    And if I do:
    Stochastics(7, 14, 1).K[0] > Stochastics(7, 14, 1).D[0]
    I get:
    K: 99.9999999999902 D: 78.5714285714276 True
    K: 49.999999999999 D: 40.7142857142849 True
    K: 99.9999999999902 D: 78.5714285714276 True
    K: 49.999999999999 D: 44.9999999999992 True
    K: 46.666666666667 D: 29.1916766706687 True
    K: 46.666666666667 D: 29.1916766706687 True
    K: 99.9999999999902 D: 85.7142857142847 True
    K: 49.999999999999 D: 46.4285714285706 True

    What is going on?

    Note: I'm using 3 time intervals.
    And, this is using Real Time Data.




    EDIT:
    I just made a test with just the original interval 5 minutes, printing the values out as time goes:
    Print("K: "+ Stochastics(7, 14, 1).K[1] +" D: "+ Stochastics(7, 14, 1).D[1]+ " "+ (Stochastics(7, 14, 1).K[1] > Stochastics(7, 14, 1).D[1]));

    This should just give me one set of the same values right? No, I got these as soon as I enable the strategy:
    K: 14.2857142857146 D: 49.0377203512988 False
    K: 21.4285714285718 D: 42.0989448410947 False
    K: 13.3333333333337 D: 36.4849097533754 False
    K: 40.0000000000003 D: 32.4247593774356 True
    K: 33.3333333333337 D: 29.6678671468591 True
    K: 46.666666666667 D: 29.1916766706687 True
    K: 53.3333333333336 D: 31.7687074829936 True
    etc. etc.
    And none of these values are correct, which as of 23:10 EST 9/27/2015, for the 5 minute chart, K is 81.82, D is 41.42
    Last edited by emoryhu; 09-27-2015, 09:19 PM.

    #2
    Hello emoryhu,

    Thanks for your post and welcome to the forums!

    In multi time frame strategy/indicator your code is called by each OnBarUpdate event in each time frame. So in your examples above you were getting the stochastics values from each time frame.

    You will need to determine how you want your code to run and then likely use BarsInProgress test as a way to isolate when your code executes or that only some parts of your code execute on one time frame while referencing data from another timeframe.

    In any case, you will want to read this section of the helpguide in its entirety in order to understand what is happening and when: http://ninjatrader.com/support/helpG...nstruments.htm
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by andrewtrades, Today, 04:57 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    3 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    436 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    7 views
    0 likes
    Last Post FAQtrader  
    Started by rocketman7, Today, 09:41 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X