Getting the MACD with EMA signal line MQL4

 

Hi I have read in this thread that the mt4 macd is actually not the same MACD as for example tradingview and other sources, the 12, 26, 9 period is ema(12), ema(26) and sma(9). How can I change the signal line to a 9 ema, the bar  lags compared to the ema MACD. Also I have looked at the default MACD script in mt4 and it doesn't let me directly change it to ema?


Here is a link to the thread with an explaination of what I mean, the signal line is in SMA I need to change it to EMA as it is at least 1 candle slower compared to the ema macd (this can be seen on tradingview). 

https://www.mql5.com/en/forum/215471#:~:text=Calculating%20Signal%20Line%20of%20MACD,to%20be%20based%20on%20MACD.


Calculation (on MetaTrader)

The MACD is calculated by subtracting the value of a 26-period exponential moving average from a 12-period exponential moving average. A 9-period dotted simple moving average of the MACD (the signal line) is then plotted on top of the MACD.

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

SIGNAL = SMA(MACD, 9) (Please note that MetaTrader uses SMA, while other sources use EMA)

Where:

EMA — Exponential Moving Average;
SMA — Simple Moving Average;
SIGNAL — the signal line of the indicator


Help would be appreciated thanks. 

Signal Line MACD, how to calculate EMA of it?
Signal Line MACD, how to calculate EMA of it?
  • 2017.09.11
  • www.mql5.com
Hi all, what to use as "Close" in the calculation below to find out SignalLine EMA of MACD...
 
CodeBerries: the signal line is in SMA I need to change it to EMA … Help would be appreciated
  1. So copy the «DataFolder»/indicators/macd.mqx and change the code. What's the problem?

  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help (2017)

 
William Roeder #:
  1. So copy the «DataFolder»/indicators/macd.mqx and change the code. What's the problem?

  2. Help you with what? You haven't stated a problem, you stated a want. Show us your attempt (using the CODE button) and state the nature of your difficulty.
              No free help (2017)

    Or pay someone. Top of every page is the link Freelance.
              Hiring to write script - General - MQL5 programming forum (2018)

    We're not going to code it for you (although it could happen if you are lucky or the problem is interesting).
              No free help (2017)

The problem is that I am not sure how to change it I have tried, your a genius bro obviously I am having a problem if I posted this question. Yes I have stated a problem "

Getting the MACD with EMA signal line MQL4", is the problem. 


I do not see the area to change to MODE_EMA

<Deleted>

MQL5 forum
MQL5 forum
  • www.mql5.com
MQL5: Forum on automated trading systems and strategy testing
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. CodeBerries #: I do not see the area to change to MODE_EMA

    You don't see MODE_SMA either. You should look harder.

    CodeBerries: the signal line is in SMA I need to change it to EMA
    SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);

 
William Roeder #:
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. You don't see MODE_SMA either. You should look harder.

Wow you are like my second pair of eyes bro WOW! I did not see MODE_SMA!, genius.  I did not understand how to change it is there a separate file that I can't see. Are you a mod? This is a forum that is your opinion (no free code), some people may choose to answer and help with the question as I would. You come off as a very anal person lol. You have not helped with anything yet lol.


If i knew how to solve the code question I would not be asking in the forum,  "So copy the «DataFolder»/indicators/macd.mqx and change the code. What's the problem?"

Data Structure in MetaTrader 4 Build 600 and Higher
Data Structure in MetaTrader 4 Build 600 and Higher
  • www.mql5.com
MetaTarder 4 build 600 features the new structure and location of the client terminal files. Now, MQL4 applications are placed in separate directories according to the program type (Expert Advisors, indicators or scripts). In most cases, the terminal data is now stored in a special data folder separated from the terminal installation location. In this article, we will describe in details how data is transferred, as well as the reasons for introducing the new storage system.
 
Ilyas #:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post

 
Keith Watford #:

Please edit your post and use the code button (Alt+S) when pasting code.

EDIT your original post, please do not just post the code correctly in a new post

Sure thanks. 

 
Hi does anyone know how to fix this? Thanks
 
Ilyas #: Hi does anyone know how to fix this? Thanks

You have already been shown what to do (see below) ... replace the function "SimpleMAOnBuffer" which calculates the SMA, for the function that calculates the EMA.

EDIT: Here is a hint ... if it is not "Simple" then it is "Exponential". How difficult is that?

All those moving average functions are conveniently located in the include file "MovingAverages.mqh".

Please show some effort, given that you are claim to be 3rd year computer science student (from private message).

Forum on trading, automated trading systems and testing trading strategies

Getting the MACD with EMA signal line MQL4

William Roeder, 2022.09.29 01:03

  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. You don't see MODE_SMA either. You should look harder.


    SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);

 
Fernando Carreiro #:

You have already been shown what to do (see below) ... replace the function "SimpleMAOnBuffer" which calculates the SMA, for the function that calculates the EMA.

EDIT: Here is a hint ... if it is not "Simple" then it is "Exponential". How difficult is that?

All those moving average functions are conveniently located in the include file "MovingAverages.mqh".

Please show some effort, given that you are claim to be 3rd year computer science student (from private message).

Alright I will give it another go thanks. 

 
Fernando Carreiro #:

You have already been shown what to do (see below) ... replace the function "SimpleMAOnBuffer" which calculates the SMA, for the function that calculates the EMA.

EDIT: Here is a hint ... if it is not "Simple" then it is "Exponential". How difficult is that?

All those moving average functions are conveniently located in the include file "MovingAverages.mqh".

Please show some effort, given that you are claim to be 3rd year computer science student (from private message).

I think I have fixed it but I am not sure if it is correct can anyone confirm thanks. I went into the MACD.mq4 file and then opened the MovingAverages.mqh file from within

then I changed to


 int ExponentialMAOnBuffer(const int rates_total,const int prev_calculated,const int begin,

                          const int period,const double& price[],double& buffer[])



//from



int SimpleMAOnBuffer(const int rates_total,const int prev_calculated,const int begin,

                const int period,const double& price[],double& buffer[])



//in

   ExponentialMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer); //the updated code line 



//was



   SimplelMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,ExtMacdBuffer,ExtSignalBuffer);