Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem getting standard deviation

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

    Problem getting standard deviation

    I'm trying to get the standard deviation of an exponential moving average. I'm computing the EMA correctly but the standard deviation added to it isn't agreeing with my indicaor plot. Am I doing this correctly?
    emaValue = EMA(Close,emaLength)[0];
    sdValue = emaValue + ( (StdDev(EMA(Close,emaLength),emaLength)[
    0])*nearSD );

    where nearSD is a standard deviation of 1.25 and the emaLength is 50.

    Thanks.

    #2
    Originally posted by sgordet View Post
    I'm trying to get the standard deviation of an exponential moving average. I'm computing the EMA correctly but the standard deviation added to it isn't agreeing with my indicaor plot. Am I doing this correctly?
    emaValue = EMA(Close,emaLength)[0];
    sdValue = emaValue + ( (StdDev(EMA(Close,emaLength),emaLength)[
    0])*nearSD );

    where nearSD is a standard deviation of 1.25 and the emaLength is 50.

    Thanks.
    Hi sgordet,

    Are you sure the error lies in the calculating of the standard deviation? I'm asking because your code works for me:

    PHP Code:
    double emaValue, sdValue;
    emaValue = EMA(Close, 50)[0];
    sdValue = emaValue + (StdDev(EMA(Close, 50), 50)[0] * 1.25);
    Print("sdValue: " + sdValue); 
    
    Which results in the Output Window giving:

    PHP Code:
    sdValue: 40,9066868415689
    sdValue: 40,8914600323389
    sdValue: 40,8866103656912
    sdValue: 40,863510027969
    sdValue: 40,8349191891388
    sdValue: 40,8072947583349
    sdValue: 40,8338112049111
    sdValue: 40,8327923220022
    sdValue: 40,8387091990463
    sdValue: 40,8418285523929
    sdValue: 40,811338468799
    sdValue: 40,7529942163232
    sdValue: 40,6684611082766 
    
    Regards,

    Comment


      #3
      sgordet, could it be you perhaps just run into a rounding error here, comparing chart plots to the raw output window value?

      Comment


        #4
        It seems pretty far to me.

        Attached is the indicator I'm comparing my standard deviation from the EMA to. My standard deviation is printing out from a strategy I wrote. The indicator is a variation of one of the NT supplied ones--I just added a 2nd standard deviation to it, but maybe I did something incorrectly there.
        Attached Files

        Comment


          #5
          Looks and plots ok here for me - I'm a bit confused on your inputs here, the latest indicator uses Std dev's of 1 and 2, while in the first post you compare to 1.25?

          Comment


            #6
            Thanks for paying such close attention. I had changed the standard deviation in the indicator input. Both the indicator and strategy use 1.25 for the calculation.
            1338.85 from the strategy print. 1335.59 from the indicator on screen. This is on S&P emini. It's just a little over a tick, but I would like them to be the same. Maybe it's not possible.

            Comment


              #7
              If I call your custom indicator from a strategy and compare both Upper1 and Upper2 values if both indicator inputs are set to use your 1.25 they match perfectly with the indicator display, please see my shot attached - are you using the same CalculateOnBarClose setting for indicator vs strategy?
              Attached Files

              Comment


                #8
                Print from Strategy

                Thanks for all of your help with this. Yes, both have CalculateonBarClose set to false.
                I found SampleStrategyPlot on your website and tried to use that code to overlay my strategy standard deviation over the indicator. I've set it slightly off from the indicator so that I could see it before doing the actual overlay. Nothing printed to the chart. Could you please take a look. It's attached.
                Attached Files

                Comment


                  #9
                  Hmm, tried that one and see the upper level a little displaced on the chart due to the 0.25 displacement factor you've got in...were you expecting more plots or would you not see anything plotting with this script on your end? In that case - did you try another symbol and timeframe as well and were there any Control Center log tab errors?

                  Comment


                    #10
                    I can see the discrepancy

                    I'm sorry. I forgot to enable the strategy. Now I can see the plot.
                    I took the .25 constant out and there is a difference betweeen the standard deviation in my strategy and in my indicator. It seems to me that I have to be calculating one of them incorrectly.
                    There were no control center errors.
                    The green is from the strategy. The blue is from the indicator.
                    Attached Files

                    Comment


                      #11
                      Hello,

                      In this case you will need to use Print() statements to debug your code to find where the error is in the calculation and compare them to your Indicator. i would add them into the idnicator as well so that you can get exact comparisons.



                      Let me know if I can be of further assistance.
                      BrettNinjaTrader Product Management

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      633 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      364 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      105 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      567 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      568 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X