Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stdev discrepencies

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

    Stdev discrepencies

    Greetings,

    I've got a series of data in a DataSeries object for the last 17 periods. I want to find the Standard Deviation for the FIRST 9 periods...when I input the values on the statistical calculator (in Windows) the values for SUM and AVERAGE match what I'm getting in my output, however there are small differences in Standard Deviation, I'm at a loss to explain why?

    The data in question:

    the DataSeries is called "MINORS" and the period data is as follows:

    [0] = 24; [1] = 34; [2] = 38; [3] = 37; [4] = 37; [5] = 32; [6] = 30.2;
    [7] = 48.1; [8] = 47;

    the STDEV command: Ds = StdDev(MINORS, 9)[0];

    The Output Window reports the StdDev as "7.2252" however the calculator outputs "7.6635", why the difference?

    #2
    Sorry I don't know. Please see the StdDev sources to see how NT calculates the StdDev.

    Comment


      #3
      Thank you for the reply. So I guess you agree at least that my command line to calculate "Ds" is at least correct?

      As for the discrepency I guess you are also correct there must be some difference in how the calculator and NT are figuring Stdev, however without knowing how the calculator is doing it just looking at the NT source isn't much help. I checked the Help files in the calculator and it simply seems to give instructions on how to calculate Stdev, but not the internal math processes used...

      Comment


        #4
        Syntax looks correct but you can verify in the Help Guide.
        RayNinjaTrader Customer Service

        Comment


          #5
          No Stdev discrepencies with this code

          I use this code to get standard deviation:

          ...

          double sum = 0;
          for ( int i = 1; i <= Periods; i++)
          sum += Math.Pow(Close[i-1]-SMA(Periods)[0],2);

          Value.Set(Math.Sqrt(sum/(Periods-1)));

          ...

          Difference between Ninjatrader and other charting applications (or Excel) is division by N (Periods) or N -1 (both is "correct" but division by N-1 is more common).

          Comment


            #6
            Thank you for that helpful information!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by CarlTrading, 03-31-2026, 09:41 PM
            1 response
            152 views
            1 like
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            87 views
            1 like
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            131 views
            2 likes
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            127 views
            1 like
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            106 views
            0 likes
            Last Post CarlTrading  
            Working...
            X