• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

StdDev Question

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

    StdDev Question

    I am creating a series that contains positive and negative values. They are usually pretty balanced between + and - numbers but in all cases I get a positive number as a result when calling StdDev() on the series. Now perhaps a value of e.g. 7.3 for a 1.0 standard deviation would encompass all numbers between 7.3 and -7.3. Or would the result be different if I would omit all positive numbers? I guess I could just try but was hoping you guys would shed some light on this as well.

    Thanks!

    #2
    Originally posted by molecool View Post
    I am creating a series that contains positive and negative values. They are usually pretty balanced between + and - numbers but in all cases I get a positive number as a result when calling StdDev() on the series. Now perhaps a value of e.g. 7.3 for a 1.0 standard deviation would encompass all numbers between 7.3 and -7.3. Or would the result be different if I would omit all positive numbers? I guess I could just try but was hoping you guys would shed some light on this as well.

    Thanks!
    Standard Deviation will always be a positive number. (The trivial case of zero implies that all values in the distribution are identical. i.e., a rectangular distribution, which, of necessity implies zero deviation from the mean).

    Standard Deviation is a measure of the absolute deviation from the mean of the sample, and so, the larger the dispersion of values, the larger the Standard Deviation. If you eliminate all negative values, it is still possible to have the same value for the standard deviation. That would happen for example if you added the value of the smallest negative number to all values. It would shift the mean, and keep the value of the standard deviation.

    However, your question is implying the removal of the positive values. That will almost certainly contract the value of the standard deviation, as your values will be less dispersed.
    Last edited by koganam; 01-10-2013, 03:02 AM. Reason: Corrected spelling.

    Comment


      #3
      Great response, thank you! I also read up on the subject and now it's crystal. Of course you're right.

      Comment


        #4
        I'm not sure the StDev function produces what I need.

        As I understand it (and that's not saying much), the StDev function will return the standard deviation of a dataset. NT documentation says this is the syntax:

        Code:
        StdDev(High, 20)[0]
        This example calculates the StDev of the last 20 highs. But can I use this function if I feed it my own numbers? What if I want it to calculate the StDev of the last 20 CCI values, for example? Or the StDev of a set of other calculations? This (perhaps not surprisingly) does not work:

        Code:
        StdDev(CCI, 20)[0]
        Thanks in advance!
        Last edited by hawks67; 06-25-2015, 08:08 AM.

        Comment


          #5
          Originally posted by hawks67 View Post
          I'm not sure the StDev function produces what I need.

          As I understand it (and that's not saying much), the StDev function will return the standard deviation of a dataset. NT documentation says this is the syntax:

          Code:
          StdDev(High, 20)[0]
          This example calculates the StDev of the last 20 highs. But can I use this function if I feed it my own numbers? What if I want it to calculate the StDev of the last 20 CCI values, for example? Or the StDev of a set of other calculations? This (perhaps not surprisingly) does not work:

          Code:
          StdDev(CCI, 20)[0]
          Thanks in advance!
          Yes, provided you use the correct syntax. CCI is meaningless without any parameters. Of what CCI are you trying to measure the StdDev?

          Th error in your compilation should tell you what is wrong with your statement. What are the parameters for your CCI?

          Comment


            #6
            Hello hawks67,

            Thank you for your inquiry.

            When calling the CCI indicator, there are two overloads that you can possibly use:

            Code:
            // Overload 1
            CCI(int period)
            
            // Overload 2
            CCI(IDataSeries input, int period)
            So, if you'd like to use the CCI indicator with the StdDev() method, you would need to call the method like this:

            Code:
            // Choice 1
            StdDev(CCI(int period), int period)
            
            // Choice 2
            StdDev(CCI(IDataSeries input, int period), int period)
            To get the 20 period StdDev using the CCI indicator, you'd do this . . .
            Code:
            StdDev(CCI(x), 20)
            . . . where x is the period of the CCI indicator.

            Please, let us know if we may be of further assistance!
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              I see where I erred. Seems pretty obvious now! Thanks to both koganam and Zachary.

              Comment


                #8
                I spoke too soon.

                When I try to assign the StDev value using the example given:

                Code:
                double tempvalue = StdDev(CCI(14), 20);
                I get the usual "cannot explicitly convert" error. Is it not a double?

                So I tried this after checking the help pages:

                Code:
                double tempvalue = StdDev(CCI(14), 20)[0];
                And it says there's no overload.

                I just know this is obvious, but I'm missing it. I want to plot a few lines in a custom indicator that map out the standard deviation of a few data sets, CCI among them. Once I get the CCI down, I'll be able to handle the others.

                Thanks.

                Comment


                  #9
                  Hello hawks67,

                  This is quite odd as double tempvalue = StdDev(CCI(14), 20)[0]; functions fine on my end.

                  Could you provide me the entire error in full?
                  Zachary G.NinjaTrader Customer Service

                  Comment


                    #10
                    No, I can't, because it no longer generates the error. I swear the code was clean, but obviously I was doing something wrong.

                    But even now that I can get that part to work, I'm still stuck as I try to carry that syntax over to my custom indicator.

                    It has two DataSeries in it, Upper and Middle. (I cannibalized/spliced different code into the bollinger indicator plots, but while it works, I have no real idea how when it comes to the structure and syntax.) Upper and Middle reference a second custom indicator ("custind"). I want to take the average of those two values, and then plot the StdDev of that average over the past ten bars.

                    Since this doesn't work:

                    Code:
                    double tempvalue = StdDev(((custind(2, 14).Upper + custind(2, 14).Middle)/2), 10)[0];
                    ...I looked into DataSeries. Definitely above my pay grade, for sure.

                    I've created a DataSeries variable:

                    Code:
                    private DataSeries myDataSeries;
                    I've assigned a new DataSeries to that variable:

                    Code:
                    myDataSeries = new DataSeries(this);
                    But now that it's time for me to load the arithmetic;

                    Code:
                    (custind(2, 14).Upper + custind(2, 14).Middle)   /  2
                    ...which works fine as a single plotted line in its own indicator, I am at a loss when it comes to referencing it - and using StdDev on it - in this second custom indicator. I'd be grateful for any tips or code examples....

                    Comment


                      #11
                      Hello hawks67,

                      The StdDev() overload you are wanting to use accepts an IDataSeries and an int.

                      Because the DataSeries class holds a series of doubles, you would want to try something like this. What this will do is calculate those values for the current bar on each indicator and divide it by two to give you your average:
                      Code:
                      myDataSeries.Set((custind(2, 14).Upper + custind(2, 14).Middle) / 2)
                      And then, you'll do this with your StdDev() method:
                      Code:
                      StdDev(myDataSeries, 10)[0];
                      Zachary G.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by hawks67 View Post
                        No, I can't, because it no longer generates the error. I swear the code was clean, but obviously I was doing something wrong.

                        But even now that I can get that part to work, I'm still stuck as I try to carry that syntax over to my custom indicator.

                        It has two DataSeries in it, Upper and Middle. (I cannibalized/spliced different code into the bollinger indicator plots, but while it works, I have no real idea how when it comes to the structure and syntax.) Upper and Middle reference a second custom indicator ("custind"). I want to take the average of those two values, and then plot the StdDev of that average over the past ten bars.

                        Since this doesn't work:

                        Code:
                        double tempvalue = StdDev(((custind(2, 14).Upper + custind(2, 14).Middle)/2), 10)[0];
                        ...I looked into DataSeries. Definitely above my pay grade, for sure.

                        I've created a DataSeries variable:

                        Code:
                        private DataSeries myDataSeries;
                        I've assigned a new DataSeries to that variable:

                        Code:
                        myDataSeries = new DataSeries(this);
                        But now that it's time for me to load the arithmetic;

                        Code:
                        (custind(2, 14).Upper + custind(2, 14).Middle)   /  2
                        ...which works fine as a single plotted line in its own indicator, I am at a loss when it comes to referencing it - and using StdDev on it - in this second custom indicator. I'd be grateful for any tips or code examples....
                        Code:
                        double tempvalue = StdDev(myDataSeries, 10)[0];
                        Last edited by koganam; 06-25-2015, 03:02 PM.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by tonynt, Today, 01:42 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post tonynt
                        by tonynt
                         
                        Started by NT-Roland, Yesterday, 04:36 PM
                        0 responses
                        3 views
                        0 likes
                        Last Post NT-Roland  
                        Started by Newtrader101, Yesterday, 03:40 PM
                        2 responses
                        12 views
                        0 likes
                        Last Post Newtrader101  
                        Started by Branpo, Yesterday, 02:58 PM
                        2 responses
                        14 views
                        0 likes
                        Last Post Branpo
                        by Branpo
                         
                        Started by sdauteuil, Yesterday, 02:09 PM
                        1 response
                        10 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X