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

Standard Deviation Wont Calculate

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

    Standard Deviation Wont Calculate

    I cannot get standard deviation to calculate for my strategy, and I am not sure why. Every time I print the value I get " NaN "

    I am using the code:

    Shake[0] = StdDev(ShakeCalc, DevLength)[0];

    In my code, ShakeCalc[0] = (MomNext / Volatility);

    ShakeCalc is defined as a series<double> , and is printing as it should
    DevLength is defined as an int

    Shake is also defined as a series<double> because ilI need to run indicators on this value to create my final calculations

    Initially, I tried to print " Shake[0] ", but after getting errors and even printing the " StdDev(ShakeCalc, DevLength)[0]; " i still get NaN. I am not sure where I am messing up, please let me know how I can fix this. I also tried removing the [0], it seems as though StdDev is not working in some way
    Last edited by thereyoflite1; 12-30-2021, 01:48 PM.

    #2
    Hello thereyoflite1,

    Thank you for your post.

    I would try printing out what the values of ShakeCalc[0] and DevLength as well as MomNext and Volatility are for each bar. What do you get printing those values?

    Thanks in advance; I look forward to assisting you further.

    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your fast response,

      These are some values from prints (I also tried " Print("this is stddev: " + StdDev(5)); " which is expressed in the third line of the prints) :


      This is shake: NaN
      this is Shakecalc: -33.8554328977246
      this is stddev: Std. dev.(NQ 03-22 (1 Minute),5)
      this is volatility: 0.00432444388184407
      this is MomNext: -0.146405919661748
      DevLength: 15

      This is shake: NaN
      this is Shakecalc: -24.9565257631552
      this is stddev: Std. dev.(NQ 03-22 (1 Minute),5)
      this is volatility: 0.00406906981425378
      this is MomNext: -0.101549845651501
      DevLength: 15

      This is shake: NaN
      this is Shakecalc: 54.4607287410781
      this is stddev: Std. dev.(NQ 03-22 (1 Minute),5)
      this is volatility: 0.00405462797098479
      this is MomNext: 0.220817994073791
      DevLength: 15

      The calculated values look how I think they should, but the standard deviation function is not giving me a number, just what you see above.
      Looking forward to learning how I can fix this issue! One of the last steps in development for this strategy.

      Thanks,
      Rey

      Comment


        #4
        thereyoflite1,
        Is the Standard Deviation Indicator/Strategy that you are working on ........... is it available for public use?
        I'm looking for a Standard Deviation based indicator to use on my Charts

        Thanks so much

        Comment


          #5
          Hello thereyoflite1,

          Thank you for your reply.

          Looks like you're printing StdDev incorrectly - you're not using a bar index so it's printing you what it's being calculated from instead. Try this:

          Print("this is stddev: " + StdDev(5)[0]);

          What you've got in your first post certainly looks like it should return a value and not NaN based on the other values being printed. Could you provide a working example script that reproduces? Anything unnecessary to reproduce should be removed. If you don't wish to post your script publicly, you can also send it in directly to scriptingsupport [at] ninjatrader [dot] com with 3420056 ATTN. Kate W. in the subject line and a link to this thread in the body of the email.

          Thanks in advance; I look forward to assisting you further.
          Kate W.NinjaTrader Customer Service

          Comment


            #6
            Thank you for your reply,

            When I printed " Print("this is stddev: " + StdDev(5)[0]); " I was able to get values to return as intended.
            When I printed " Print("this is stddev: " + StdDev(DevLength)[0]); " I was also able to get values to return as intended.

            This leads me to believe that the issue is "ShakeCalc" but ShaleCalc is a series<double> so I am not sure what is wrong. I will send it in via email ASAP, please give me a couple of hours.

            Comment


              #7
              Hello thereyoflite1,

              Thank you for your reply.

              Just so you know, due to the New Years holiday it's fairly likely I won't have an answer for you until Monday, however, once you get the script to me I'll let you know my findings as soon as I am able.

              Thanks in advance; I look forward to assisting you further.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hello Kate,

                No worries, I have sent in the email with the code in a text document as well as the download link to the .zip file for the code exported from ninjatrader (for some reason it would not attach to the email). Looking forward to receiving your input and resolving this issue.

                Happy New Years!

                Rey

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by suroot, 02-25-2017, 04:43 AM
                11 responses
                2,548 views
                0 likes
                Last Post Zilvercat  
                Started by Rogers101, 05-05-2024, 11:30 AM
                16 responses
                50 views
                0 likes
                Last Post Rogers101  
                Started by ninza33, Today, 12:31 PM
                2 responses
                10 views
                0 likes
                Last Post ninza33
                by ninza33
                 
                Started by Bobin, 03-12-2024, 08:51 AM
                15 responses
                482 views
                0 likes
                Last Post fiddich
                by fiddich
                 
                Started by Skifree, Today, 11:21 AM
                4 responses
                15 views
                0 likes
                Last Post Skifree
                by Skifree
                 
                Working...
                X