EMA Accuracy

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

Moderator: admin

EMA Accuracy

Postby kelvinocw » Wed Mar 27, 2019 12:39 pm

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! :D
kelvinocw
 
Posts: 3
Joined: Wed Mar 27, 2019 12:27 pm

Re: EMA Accuracy

Postby Apprentice » Wed Mar 27, 2019 1:40 pm

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;
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 21067
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Accuracy

Postby kelvinocw » Wed Mar 27, 2019 4:42 pm

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

Postby kelvinocw » Wed Mar 27, 2019 4:52 pm

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

Postby Apprentice » Fri Mar 29, 2019 4:54 am

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
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 21067
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: EMA Accuracy

Postby Apprentice » Fri Mar 29, 2019 5:17 am

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
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 21067
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia



Return to Discussions

Who is online

Users browsing this forum: No registered users and 2 guests