Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
I want to calculate a SMA and standard deviation for an indicator that has some empty values which I believe will skew the results. For example, if I calculate a SMA on a 100 data points where 25% are empty values, that will obviously skew my mean downwards. That is, it would be lower than if it was calculating the SMA of the other 75 data points which is what Im hoping to do. Same goes for the StDev.
Is there a way to exclude these empty values from the SMA and StDev calculations?
Thnaks
Can you help answer these questions from other members on NexusFi?
Either there is no bar. In that case the SMA is calculated from the data points as you wish.
Or there are bars that show the same value as the prior bar, because there was no incoming tick. In that case the SMA is calculated from the regular bars and those inserted bars.
Sorry if my expression "empty value" didnt make sense. What I meant is when an indicator shows N/A in the Data box.
I wish there was a way to omit those when calculating SMA and StDev so that they are calculated on those 75 values in my example in my previous post instead of calculating the whole 100 values and including those N/A.
You are not looking at a "SMA" when you are eliminating data as by definition you are taking the closing prices at the end of an interval summing them and dividing the number by the total number of intervals to arrive at a SIMPLE Moving Average.
Whether the interval is traded or not, the interval has a value as far as the chart is concerned.
Consider the above chart of a lightly traded stock. The each interval is 5 minute so the 20 SMA (total of 100minutes of data) as you can see is smooth and calculated from the closing price and when there is no volume the closing price is the same as the previous close.
So....if you want to calculate "empty" cells then you would eliminate all 5 min data points that have a zero volume over the 100 minutes, keeping track of the number of positive volume numbers to arrive at your average of the sum of positive volume prices.
But I fail to see how this has any meaning in reality.
You would be treating prices where the volume was in the range > 20,000 shares (eg. latter half of the second PM hour of the first day) the same as weight as data with very low data < 1000 shares ( the two 5 min intervals in the following day between 2:00pm - 3:00pm
So as I see it you could use all price data and multiplying it by volume (thereby eliminating zero volume intervals) and then adding the results and dividing by the total intervals in the average period. I suppose this would have some relevance.
But to cherry pick data without zero volumes does not make much sense to me, when as little as 1 share traded would be considered the same significance as say 10,000 shares.
At least the SMA which is calculated without reference to volume has a consistency to its interpretation.
Edit: I guess my example is not the same as yours as I only deal in share prices but the thoughts behind my discussion probably still applies in your case as well. If not, Just ignore me
Underxposed, thanks for your answer and I understand that, but it doesnt really apply. All I am trying to do is calculating the average and SD of the indicator when its not N/A.
I thought of using an array and then calculating the Avg and SD on that array. How would I calculate those on an array?
Sorry, I should check what folder I am in before answering.
I have done a fair bit of programming in my working life but I don't do the type of trading you do and certainly don't use NinjaTrader so my comments on what you are attempting may be off base here.
then you would write some kind of script where you would test "P" to see if it would be NULL and ignore "I" otherwise add "I" to an accumulator and increment a counter by one...then at the end of the "SMA" (it is not really a SMA as it is not simple anymore) make your division.
Actually in practise I suppose you would just consider the the first number of the addition array and the next number
Let us say you are doing a 5"SMA"....then you would compute the first sma on I1 to I5 as I described above... for the second SMA you would have to check out P1 to see if it was a valid number (ie. you then have used I1 in the calculation)
if P1 were " null" then you would not subtract I1 from the accumulator as it was not used in the calculation and leave the counter unchanged
if P1 was "non-null" then I1 would be subtracted from the accumulator and the counter decreased by one
From the result of the above "IF" statements...
Then you would perform an inspection on P6...
if P6 was "null" the "SMA" would be simply the division of the adjusted accumulator value by the adjusted counter value...as you would ignore I6
if P6 was "non-null" then you would add I6 to the accumulator and increment the counter by one and perform the division
then you loop back and continue a similar analysis with rest of the data.
This is in general what I would do...handicapped by not knowing the script language and the data
That is the limit to what I can suggest...hope it helps
Maybe your indicator should hold a value instead of holding nothing. I guess that it is badly coded.
What is the purpose of that indicator?
Alternatively you may want to code a new SMA that first builds a secondary array from the input values by omitting those price bars that do not contain any values.