NexusFi: Find Your Edge


Home Menu

 





I'm feeling really stupid and need clarification


Discussion in MultiCharts

Updated
    1. trending_up 165 views
    2. thumb_up 1 thanks given
    3. group 2 followers
    1. forum 6 posts
    2. attach_file 2 attachments




 
Search this Thread
  #1 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 90 since May 2019
Thanks Given: 8
Thanks Received: 10

OK, for years, I've been applying EMAs to code (Exponential MA). Until lately, I never really considered how they are calculated. I thought they were some derivative of a simple moving average (sum of value / number of values).

With that being said, I looked at the function code for the EMA (XAVERAGE) function in multicharts and saw this:

 
Code
inputs: 
	PriceValue( numericseries ), 
	Len( numericsimple ) ;                                             

variables: 
	var0( 2 / ( Len + 1 ) ) ;

if CurrentBar = 1 then
	XAverage = PriceValue
else
	XAverage = XAverage[1] + var0 * ( PriceValue - XAverage[1] ) ;
That really looks nothing like the SMA calculation. So I Googled EMA calculation and got this explanation...

EMA = Closing price x multiplier + EMA (previous day) x (1-multiplier)

Again, that looks close to the formula but not quite exact to what MC has in their function.

So, who's right? And am I reading this right... Is the EMA simply the current close X the multiplier described by Investopedia as...

Next, you must calculate the multiplier for smoothing (weighting) the EMA, which typically follows the formula: [2 ÷ (number of observations + 1)]. For a 20-day moving average, the multiplier would be [2/(20+1)]= 0.0952.

PLUS the EMA value of the previous day x (1-Multiplier)???

In other words, it's not summing up values for X number of periods?

Again, I'm feeling a little dumb right now. Please clarify.

BTW, I am asking this because as you might have seen in several threads, I'm having a real hard time with multi-data strats giving me the same result as an indicator does let alone if a strat is calculating the same EMA if only one instrument in the chart. And I'm exploring my options here. Thanks


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Building models w/Neuroshell and Adaptatrade
Platforms and Indicators
Need TOS RSI Converted to NT8
NinjaTrader
Ticksandtrades.com
Trading Reviews and Vendors
NT8 coding values of "Additional Data"
NinjaTrader
Using multiple Versions of the same DLL in MC.Net
MultiCharts
 
  #2 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,697 since Jul 2012
Thanks Given: 1,904
Thanks Received: 7,411


Sinatra Fan View Post
OK, for years, I've been applying EMAs to code (Exponential MA). Until lately, I never really considered how they are calculated. I thought they were some derivative of a simple moving average (sum of value / number of values).

With that being said, I looked at the function code for the EMA (XAVERAGE) function in multicharts and saw this:

 
Code
inputs: 
	PriceValue( numericseries ), 
	Len( numericsimple ) ;                                             

variables: 
	var0( 2 / ( Len + 1 ) ) ;

if CurrentBar = 1 then
	XAverage = PriceValue
else
	XAverage = XAverage[1] + var0 * ( PriceValue - XAverage[1] ) ;
That really looks nothing like the SMA calculation. So I Googled EMA calculation and got this explanation...

EMA = Closing price x multiplier + EMA (previous day) x (1-multiplier)

Again, that looks close to the formula but not quite exact to what MC has in their function.

So, who's right? And am I reading this right... Is the EMA simply the current close X the multiplier described by Investopedia as...

Next, you must calculate the multiplier for smoothing (weighting) the EMA, which typically follows the formula: [2 ÷ (number of observations + 1)]. For a 20-day moving average, the multiplier would be [2/(20+1)]= 0.0952.

PLUS the EMA value of the previous day x (1-Multiplier)???

In other words, it's not summing up values for X number of periods?

Again, I'm feeling a little dumb right now. Please clarify.

BTW, I am asking this because as you might have seen in several threads, I'm having a real hard time with multi-data strats giving me the same result as an indicator does let alone if a strat is calculating the same EMA if only one instrument in the chart. And I'm exploring my options here. Thanks


You'd have to do the math in a spreadsheet to compare the 2 calculations, you might find they are equivalent.

In any event, you might be getting different results with multi-data charts because the calculations might be starting at different times. Expo. Moving Average is start point dependent - if you have different starting points, you'll have different results forever.


Follow me on X Reply With Quote
  #3 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 90 since May 2019
Thanks Given: 8
Thanks Received: 10



kevinkdog View Post
You'd have to do the math in a spreadsheet to compare the 2 calculations, you might find they are equivalent.

I'm trying to, but it's hard for me to reconcile. At your recommendation, I opened a spreadsheet and made a comparison of the two. I attached the pic. As you can see, the multiplier is correct, but the EMA equation doesn't seem to match. Please explain where I'm going wrong here.




kevinkdog View Post
In any event, you might be getting different results with multi-data charts because the calculations might be starting at different times. Expo. Moving Average is start point dependent - if you have different starting points, you'll have different results forever.

I agree with you on starting points. But here's my issue. When I insert an EMA "Indicator" and in the formatting, I select Data2 (25 tick bar for example), It gives me the SAME indicator as if I had a single data chart with either the indicator or STRATEGY. BUT, when I setup a simple strategy code asking the XAverage function to calculate on Data2, the results are NOT the same. In other words, I can have all this loaded at the same time on the same chart and get different results which is unacceptable. Hence, my struggle is real


EMA code comparison


Started this thread Reply With Quote
  #4 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,697 since Jul 2012
Thanks Given: 1,904
Thanks Received: 7,411


Sinatra Fan View Post
I'm trying to, but it's hard for me to reconcile. At your recommendation, I opened a spreadsheet and made a comparison of the two. I attached the pic. As you can see, the multiplier is correct, but the EMA equation doesn't seem to match. Please explain where I'm going wrong here.





I agree with you on starting points. But here's my issue. When I insert an EMA "Indicator" and in the formatting, I select Data2 (25 tick bar for example), It gives me the SAME indicator as if I had a single data chart with either the indicator or STRATEGY. BUT, when I setup a simple strategy code asking the XAverage function to calculate on Data2, the results are NOT the same. In other words, I can have all this loaded at the same time on the same chart and get different results which is unacceptable. Hence, my struggle is real


EMA code comparison

In the line where you write "NOT SAME" if you do the math, you will say they are the same.

For the data2 discrepancy, it sounds like you have a data aliasing issue, where the average might be calculated on the frequency (bar size) of data1, rather than data2.


Follow me on X Reply With Quote
  #5 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 90 since May 2019
Thanks Given: 8
Thanks Received: 10


kevinkdog View Post
In the line where you write "NOT SAME" if you do the math, you will say they are the same.

So using those two formulas... I entered closing prices for about 20 or so candles. I then entered the formulas for both and the outcomes are NOT equal. What am I doing wrong?

EDIT, I just noticed that the Investipedia value is the same


EMA code comparison calcs


Started this thread Reply With Quote
  #6 (permalink)
 kevinkdog   is a Vendor
 
Posts: 3,697 since Jul 2012
Thanks Given: 1,904
Thanks Received: 7,411


Sinatra Fan View Post
So using those two formulas... I entered closing prices for about 20 or so candles. I then entered the formulas for both and the outcomes are NOT equal. What am I doing wrong?




EMA code comparison calcs

If you can post the spreadsheet, or PM me the spreadsheet. I am teaching all day class right now, so it will have to wait until tonight, sorry.


Follow me on X Reply With Quote
Thanked by:
  #7 (permalink)
 
Sinatra Fan's Avatar
 Sinatra Fan 
Orlando FL
 
Experience: Intermediate
Platform: MultiCharts, Ninja
Trading: Emini ES
Posts: 90 since May 2019
Thanks Given: 8
Thanks Received: 10


kevinkdog View Post
If you can post the spreadsheet, or PM me the spreadsheet. I am teaching all day class right now, so it will have to wait until tonight, sorry.

OK, I found the issue and yes, I stand corrected. They are equal.

So, let me see if I can print out the prices they are getting for each bar to see WTH is going on.

Will keep you posted.


Started this thread Reply With Quote




Last Updated on January 23, 2025


© 2025 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 - Downloads - Top
no new posts