EMA Accuracy

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

EMA Accuracy

Hi guys,How do i code EMA calculations accurately?The values doesn't seem to be accurate or in line with the EMA values from MT4 platforms or Tradingview.com?Please help me out thank you!
kelvinocw

Posts: 3
Joined: Wed Mar 27, 2019 12:27 pm

Re: EMA Accuracy

Can you provide an algorithm used for two mentioned?

We have.
k = 2.0 / (n + 1.0);
EMA= (1 - k) * previous value of EMA + k * source;

Apprentice
FXCodeBase: Confirmed User

Posts: 21652
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Accuracy

Thanks for replying.The codes that u gave me is great but the problem is what is the starting value of yesterdays EMA.Is there any short cut to grab the value?
kelvinocw

Posts: 3
Joined: Wed Mar 27, 2019 12:27 pm

Re: EMA Accuracy

Because the current candle EMA is calculated by the close price which is updated every second with a weighted multiplier which is K + previous candle EMA. The problem is how do i get the previous candle EMA? How do i get the most precise previous day EMA value that would be used in the equation to get the most precise today's EMA?
kelvinocw

Posts: 3
Joined: Wed Mar 27, 2019 12:27 pm

Re: EMA Accuracy

we use this logic.

if (period == first) then
value = source;
else
value = previous value of EMA;
end

You can find other implementations on the internet.
https://stockcharts.com/school/doku.php ... g_averages

Apprentice
FXCodeBase: Confirmed User

Posts: 21652
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Accuracy

They use same formula.

Stockcharts version
EMA: {Close - previous} x multiplier + previous.

TS Version
EMA: (1 - multiplier) * previous + multiplier * Close ;
EMA: previous - multiplier*previous + multiplier * Close ;
EMA: previous + multiplier*(Close-previous)
EMA: (Close-previous)*multiplier +previous

Apprentice
FXCodeBase: Confirmed User

Posts: 21652
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Accuracy

Apprentice
FXCodeBase: Confirmed User

Posts: 21652
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia