NexusFi: Find Your Edge


Home Menu

 





Exclude empty values for calculations


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one tonycashflow with 3 posts (1 thanks)
    2. looks_two Fat Tails with 2 posts (0 thanks)
    3. looks_3 Underexposed with 2 posts (1 thanks)
    4. looks_4 Quick Summary with 1 posts (0 thanks)
    1. trending_up 1,359 views
    2. thumb_up 2 thanks given
    3. group 2 followers
    1. forum 7 posts
    2. attach_file 2 attachments




 
Search this Thread

Exclude empty values for calculations

  #1 (permalink)
 tonycashflow 
Montreal Qc/Canada
 
Experience: Intermediate
Platform: MT4 and others
Trading: ES, Forex
Posts: 7 since May 2012
Thanks Given: 10
Thanks Received: 1

Hi,

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

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Trade idea based off three indicators.
Traders Hideout
ZombieSqueeze
Platforms and Indicators
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
How to apply profiles
Traders Hideout
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102



tonycashflow View Post
Hi,

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

What do you call an empty value?

Such thing does not exist.

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.

Reply With Quote
  #4 (permalink)
 tonycashflow 
Montreal Qc/Canada
 
Experience: Intermediate
Platform: MT4 and others
Trading: ES, Forex
Posts: 7 since May 2012
Thanks Given: 10
Thanks Received: 1


Fat Tails View Post
What do you call an empty value?

Such thing does not exist.

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.


Started this thread Reply With Quote
Thanked by:
  #5 (permalink)
 Underexposed 
Calgary Alberta/Canada
 
Posts: 934 since Feb 2014

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

Reply With Quote
  #6 (permalink)
 tonycashflow 
Montreal Qc/Canada
 
Experience: Intermediate
Platform: MT4 and others
Trading: ES, Forex
Posts: 7 since May 2012
Thanks Given: 10
Thanks Received: 1

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?

Thanks

Started this thread Reply With Quote
  #7 (permalink)
 Underexposed 
Calgary Alberta/Canada
 
Posts: 934 since Feb 2014


tonycashflow View Post
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 calculated those on an array?

Thanks

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.

What type of array are you considering?

is it something like

Time interval: ................................................. T1.... T2... T3.... T4.... T5... T6
Indicator: ....................................................... I1 .... I2 .. I3 ... I4 .... I5... I6
Parameter (eg. volume or equivalent) ........... P1 .... P2 . P3 ... P4 ... P5... P6

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

Reply With Quote
  #8 (permalink)
 
Fat Tails's Avatar
 Fat Tails 
Berlin, Europe
Market Wizard
 
Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker: Interactive Brokers
Trading: Keyboard
Posts: 9,888 since Mar 2010
Thanks Given: 4,242
Thanks Received: 27,102


tonycashflow View Post
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.



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.

Reply With Quote




Last Updated on June 23, 2014


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts