How MT4 calculate its EMA & MACD ?? The formula used by MT4 seems to be different than the formula generally used by other platform.

 

Please help.


===========================================

BACKGROUND OF THE PROBLEM:

I need to calculate MACD in spreadsheet/excel for research purpose. So I searched the formula in investopedia and found the formula.

Source: https://www.investopedia.com/ask/answers/122414/what-moving-average-convergence-divergence-macd-formula-and-how-it-calculated.asp


After I calculate the data, my result is very different with MACD signals & value displayed in my MT4 account.

Because I am using MT4 platform, then I think I need to make sure that the formula I used for this research is matched with the formula used by MT4.


I searched the formula for MACDin MT4 and found this:

MACD = EMA(CLOSE, 12)-EMA(CLOSE, 26)

SIGNAL = SMA(MACD, 9)

Where:
EMA – the Exponential Moving Average;
SMA – the Simple Moving Average;
SIGNAL – the signal line of the indicator.

Source: https://www.metatrader4.com/en/trading-platform/help/analytics/tech_indicators/macd


Because I need EMA, then I searched the formula for EMAin MT4 and found this:

EMA = (CLOSE(i) * P) + (EMA(i - 1) * (100 - P))

Where:

CLOSE(i) – the price of the current period closure;
EMA(i-1) – Exponentially Moving Average of the previous period closure;
P – the percentage of using the price value.

Source: https://www.metatrader4.com/en/trading-platform/help/analytics/tech_indicators/moving_average


===========================================

QUESTIONS:


1. I still don't understand what "P" (the percentage of using the price value) means in MT4's EMA formula. Could anyone please explain it to me with the data example of its calculation?


2.  In MT4's EMA formula, the website tells that I need  EMA(i-1) or Exponentially Moving Average of the previous period closure for the calculation. For the first EMA to be calculated, there would be no EMA(i-1). How MT4 deal with it? Does MT4 use SMA instead as its EMA(i-1)? 


3. The MACD formula in MT4 website doesn't explain how to calculate the value of MACD histogram. Is anyone know how MT4 calculate it?



Thank you.

I greatly appreciate your help.

Moving Average - Technical Indicators - Analytics - MetaTrader 4 Help
Moving Average - Technical Indicators - Analytics - MetaTrader 4 Help
  • www.metatrader4.com
The Moving Average Technical Indicator shows the mean instrument price value for a certain period of time. When one calculates the moving average...
 

Here is the source code for the MQL4 implementation of MACD on MetaTrader 4, by MetaQuotes ...

Code Base

Moving Average Convergence Divergence, MACD

MetaQuotes, 2005.11.29 11:54

Moving Average Convergence/Divergence (MACD) is the next trend-following dynamic indicator.

And, here is the source code for the MQL4 implementation of Moving Averages on MetaTrader 4, by MetaQuotes ...

Code Base

Moving Averages, MA

MetaQuotes, 2005.11.29 11:54

The Moving Average Indicator shows the mean instrument price value for a certain period of time.
 
  1. Why did you post your MT4 question in the MT5 Indicators section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum? (2017)
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2. jonsnow007: 1. I still don't understand what "P" (the percentage of using the price value) means in MT4's EMA formula.

    Most people use Length, thus relating the similar EMA(L) to SMA(L). This is what the iMA call/indicators require. Alpha is defined as A=2/(L+1) and used in place of your P.

  3. jonsnow007: EMA = (CLOSE(i) * P) + (EMA(i - 1) * (100 - P))

    You should never calculate EMA that way, as it amplifies rounding errors. Rewrite to EMA=EMA(i-1) + A * ( CLOSE(i)-EMA(i-1) ) and rounding errors get averaged to zero. You even posted the link https://www.investopedia.com/ask/answers/122414/what-moving-average-convergence-divergence-macd-formula-and-how-it-calculated.asp which says that.

  4. Exponential requires 3.45×(Length+1) bars to converge to 1/10 percent. (EMA Period 5 requires 21 initial bars.)
              Moving average - Wikipedia

  5. jonsnow007: 2.  In MT4's EMA formula, the website tells that I need  EMA(i-1) or Exponentially Moving Average of the previous period closure for the calculation. For the first EMA to be calculated, there would be no EMA(i-1). How MT4 deal with it? Does MT4 use SMA instead as its EMA(i-1)? 

    Per №  4, it doesn't matter as long have you have enough previous values. Some just use the initial value (EMA₀=V₀), MetaQuotes uses EMA₀=SMA(L,L-1) (which means you must have at least L values to start). For large lengths, in an attempt to minimize №  4, I personnally use EMA(n) where n increases each value up to L. #.i. EMA₀=value₀, EMA₁=(2/3) value₁ + (1/3) EMA₀, EMA₂=(2/4) value₂ + (2/4) EMA₁, …

  6. jonsnow007: 3. The MACD formula in MT4 website doesn't explain how to calculate the value of MACD histogram. Is anyone know how MT4 calculate it?

    The histogram is just MACD minus signal. Of no value in code, it just shows the cross a little easier (when the thickness of the lines become obscurring).

 

All I need is something very simple......make my MACD red going down and green going up.  How do I do that?

 
wctucker1 #: All I need is something very simple......make my MACD red going down and green going up.  How do I do that?

Please don't double post or high-jack another thread. In answering your question, by searching the CodeBase or Market for a MACD that does that. Here is one from the CodeBase ...

Code Base

Tipu MACD

Kaleem Haider, 2017.05.11 10:43

Tipu MACD is one the popular indicators in the Market. The original code for Tipu MACD is modified by removing compatibility with Tipu Panel. This version of Tipu MACD is open for everyone who is interested in developing an Expert Advisor.