Thanks!
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
StdDev Question
Collapse
X
-
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!Tags: None
-
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).Originally posted by molecool View PostI 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 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.
-
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:
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(High, 20)[0]
Thanks in advance!Code:StdDev(CCI, 20)[0]
Last edited by hawks67; 06-25-2015, 08:08 AM.
Comment
-
Yes, provided you use the correct syntax. CCI is meaningless without any parameters. Of what CCI are you trying to measure the StdDev?Originally posted by hawks67 View PostI'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:
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(High, 20)[0]
Thanks in advance!Code:StdDev(CCI, 20)[0]
Th error in your compilation should tell you what is wrong with your statement. What are the parameters for your CCI?
Comment
-
Hello hawks67,
Thank you for your inquiry.
When calling the CCI indicator, there are two overloads that you can possibly use:
So, if you'd like to use the CCI indicator with the StdDev() method, you would need to call the method like this:Code:// Overload 1 CCI(int period) // Overload 2 CCI(IDataSeries input, int period)
To get the 20 period StdDev using the CCI indicator, you'd do this . . .Code:// Choice 1 StdDev(CCI(int period), int period) // Choice 2 StdDev(CCI(IDataSeries input, int period), int period)
. . . where x is the period of the CCI indicator.Code:StdDev(CCI(x), 20)
Please, let us know if we may be of further assistance!Zachary G.NinjaTrader Customer Service
Comment
-
I spoke too soon.
When I try to assign the StDev value using the example given:
I get the usual "cannot explicitly convert" error. Is it not a double?Code:double tempvalue = StdDev(CCI(14), 20);
So I tried this after checking the help pages:
And it says there's no overload.Code:double tempvalue = StdDev(CCI(14), 20)[0];
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
-
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:
...I looked into DataSeries. Definitely above my pay grade, for sure.Code:double tempvalue = StdDev(((custind(2, 14).Upper + custind(2, 14).Middle)/2), 10)[0];
I've created a DataSeries variable:
I've assigned a new DataSeries to that variable:Code:private DataSeries myDataSeries;
But now that it's time for me to load the arithmetic;Code:myDataSeries = new DataSeries(this);
...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:(custind(2, 14).Upper + custind(2, 14).Middle) / 2
Comment
-
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:
And then, you'll do this with your StdDev() method:Code:myDataSeries.Set((custind(2, 14).Upper + custind(2, 14).Middle) / 2)
Code:StdDev(myDataSeries, 10)[0];
Zachary G.NinjaTrader Customer Service
Comment
-
Originally posted by hawks67 View PostNo, 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:
...I looked into DataSeries. Definitely above my pay grade, for sure.Code:double tempvalue = StdDev(((custind(2, 14).Upper + custind(2, 14).Middle)/2), 10)[0];
I've created a DataSeries variable:
I've assigned a new DataSeries to that variable:Code:private DataSeries myDataSeries;
But now that it's time for me to load the arithmetic;Code:myDataSeries = new DataSeries(this);
...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:(custind(2, 14).Upper + custind(2, 14).Middle) / 2
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
580 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
335 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
102 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment