Exposing Fast & Slow EMA in the standard shipped MACD example...

Earthy Stag beetle  

Hello All,

I want to make a straightforward change to the example shipped MACD to expose the Fast & slow EMA's as lines in the same window as the histogram & signal.

The standard shipped example MACD (attached) exposes the histogram & signal in a separate window. I can build it, it works - all good.

I have read the docs and made the following changes/additions to the standard MACD, the rest of the code remains as is:

//+------------------------------------------------------------------+
//|                                                         MACD.mq5 |
//|                   Copyright 2009-2020, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "2009-2020, MetaQuotes Software Corp."
#property link        "http://www.mql5.com"
#property description "Moving Average Convergence/Divergence - 2l ine"
#include <MovingAverages.mqh>
//--- indicator settings
#property indicator_separate_window
#property indicator_buffers 4
#property indicator_plots   4
#property indicator_type1   DRAW_HISTOGRAM
#property indicator_type2   DRAW_LINE
#property indicator_type3   DRAW_LINE
#property indicator_type4   DRAW_LINE
#property indicator_color1  clrSilver
#property indicator_color2  clrRed
#property indicator_color3  clrGreen
#property indicator_color4  clrBlue
#property indicator_width1  2
#property indicator_width2  1
#property indicator_width3  1
#property indicator_width4  1
#property indicator_label1  "MACD"
#property indicator_label2  "Signal"
#property indicator_label3  "FastEMA"
#property indicator_label4  "SlowEMA"
//--- input parameters
input int                InpFastEMA=12;               // Fast EMA period
input int                InpSlowEMA=26;               // Slow EMA period
input int                InpSignalSMA=9;              // Signal SMA period
input ENUM_APPLIED_PRICE InpAppliedPrice=PRICE_CLOSE; // Applied price
//--- indicator buffers
double ExtMacdBuffer[];
double ExtSignalBuffer[];
double ExtFastMaBuffer[];
double ExtSlowMaBuffer[];

int    ExtFastMaHandle;
int    ExtSlowMaHandle;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,ExtMacdBuffer,INDICATOR_DATA);
   SetIndexBuffer(1,ExtSignalBuffer,INDICATOR_DATA);
//   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_CALCULATIONS);
//   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(2,ExtFastMaBuffer,INDICATOR_DATA);
   SetIndexBuffer(3,ExtSlowMaBuffer,INDICATOR_DATA);
//--- sets first bar from what index will be drawn
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,InpSignalSMA-1);
//--- name for indicator subwindow label
   string short_name=StringFormat("MACD(%d,%d,%d)",InpFastEMA,InpSlowEMA,InpSignalSMA);
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
//--- get MA handles
   ExtFastMaHandle=iMA(NULL,0,InpFastEMA,0,MODE_EMA,InpAppliedPrice);
   ExtSlowMaHandle=iMA(NULL,0,InpSlowEMA,0,MODE_EMA,InpAppliedPrice);
  }

If I run this from MetaTrader, nothing appears (Actually volumes appear unrequested 🤷‍♀️).

If I run this from the dev IDE, Fast & slow EMA appear superimposed on the main chart, but the MACD signal/histogram window does not appear.

I am not great at graphics/drawing stuff/indicator development and would be grateful if someone can take a look and see what I have done wrong/I have missed. Unfortunately what I have done makes sense to me - but something is plainly wrong.

With my best regards, Insectoid creature.

Files:
MACD.mq5  5 kb
Fernando Carreiro  
Earthy Stag beetle:Hello All,I want to make a straightforward change to the example shipped MACD to expose the Fast & slow EMA's as lines in the same window as the histogram & signal.The standard shipped example MACD (attached) exposes the histogram & signal in a separate window. I can build it, it works - all good.I have read the docs and made the following changes/additions to the standard MACD, the rest of the code remains as is:

If I run this from MetaTrader, nothing appears (Actually volumes appear unrequested 🤷‍♀️).If I run this from the dev IDE, Fast & slow EMA appear superimposed on the main chart, but the MACD signal/histogram window does not appear. I am not great at graphics/drawing stuff/indicator development and would be grateful if someone can take a look and see what I have done wrong/I have missed. Unfortunately what I have done makes sense to me - but something is plainly wrong.With my best regards, Insectoid creature.

Not feasible! The fast and slow EMAs are of the same scale as the price, while histogram and signal are of the scale of price ranges.

If you were to place them in the same window, then the histogram and signal would become so small you would not see them, because they have different scales.

Earthy Stag beetle  

Thank you Fernando,

Good answer and I didn't think of that.

However perhaps you have given me hope; a) I could apply a scaling factor or; b) show the Fast & slow EMA in the chart window and the signal/histogram in the sub window.

Do either of these ideas sound feasible? You might be able to tell my level of expertise by these questions (i.e., low 🤠). I have some coding skills but less so with the huge landscape of MQL5 libraries.

Thanks,

With my best regards, ESB.
Fernando Carreiro  
Earthy Stag beetle #: However perhaps you have given me hope; a) I could apply a scaling factor or; b) show the Fast & slow EMA in the chart window and the signal/histogram in the sub window. Do either of these ideas sound feasible? You might be able to tell my level of expertise by these questions (i.e., low 🤠). I have some coding skills but less so with the huge landscape of MQL5 libraries.
  1. The scaling is technically feasible, but would still be meandering all over the place due to the variance of the values. I also find the ideia useless to place them on the same window as the histogram and signal. What is the point?
  2. Placing them on the main window is much more useful but it is unfeasible because a custom indicator cannot plot buffers in both windows at the same time. It can only plot buffers, either on the main chart, or on the sub-window, but not both.
Earthy Stag beetle  

Hi Fernando,

I apologise for my slow repy: a) I was thinking and; b) I have been distracted by work.

I had watched a MACD strategy YouTube video, I have been looking to discover how to spot when not to trade when the market is reversing and the idea looked worth investigating.

Hence I was looking for a two line MACD, I couldn't find one so thought I'd roll my own based on the example MACD shipped with MetaTrader 5. It's always a good idea to understand the problem before diving into code and I hadn't fully grasped what I should be doing.  Anyway, lucky me, I found what I was looking for here.

So for the time being, my search is over and I thank you for taking the trouble to read my request and think about it.

Wishing you well and thanks again, ESB.

Indicators: MACD Histogram, multi-color - Renko Line Break vs RSI EA is a UAC issue, but how to fix it?
Indicators: MACD Histogram, multi-color - Renko Line Break vs RSI EA is a UAC issue, but how to fix it?
  • 2010.08.24
  • www.mql5.com
Mq5 file in "c:\program files\metatrader 5\mql5\indicators\examples\". Your problem is an uac issue, you can resolve it by following this procedure: forum. I am developing an ea and i use this macd indicator
Fernando Carreiro  
Earthy Stag beetle #: Anyway, lucky me, I found what I was looking for here.

But that is just a normal MACD. It has nothing to do with ploting the Fast and Slow EMAs themselves in the window.

It's the MACD line (difference between Fast and Slow EMA), the Signal (an EMA of the MACD line), and the histogram (difference between MACD line and signal).