Value of multiple indicators in one data window differ

 

Hi,

When I add two standard MACDs to the same indicator window (and hide the histogram so that I can only see the Signal line) then the values are different than if I have a totally new indicator which combines the two signal lines of the MACDs.  

Below is a sample of the issue.  The top "indicator" window has the two MACDs in the same window.  The green/faster MACD shows bigger moves and crosses the slower MACD signal line (red line) more often.  

The bottom indicator is a custom indicator based on the same MACD function, but the outcome varies and the faster MACD signal line (green line) is smoother and does not cross the slower MACD signal line.

Can anyone say what the issue is and possibly how to overcome it so that the bottom indicator can be fixed to look like the top one?  Is this an issue in MT4 which can be overcome?

Double MACD signal indicator 

 

The bottom indicator would look the like the top one if it was coded correctly to produce the same values as the top one. Obviously it is not.

 

The top window indicator is show when we attach 2 MACD with 2 parameter (5,8,3) and (12,26,9) into 1 indicator window. It will draw wrong value of MACD.

MT4 will try to draw with the value like it is separate window, so the value of MACD will draw wrong place. Let test the simple thing bellow.


 

Bellow is the source code of (4). Is the code bellow is correctly when we code the  indicator to recognize the cross over of 2 MACD ?

 

/+------------------------------------------------------------------+

//|                                                       MACD 2.mq4 |

//|                        Copyright 2014, MetaQuotes Software Corp. |

//|                                              https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2014, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property  indicator_separate_window

#property  indicator_buffers 2

#property  indicator_color1  Lime

#property  indicator_color2  Red

#property  indicator_width1  2

#property  indicator_width2  2

//--- input parameters


extern string  NOTE0="--->FAST MACD<---";

extern int     MACD1FastEMA=5;

extern int     MACD1SlowEMA=8;

extern int     MACD1Signal=3;

extern int     enMACD1Mode=1;

extern int     enMACD1AppliedPrice=0;

extern string  NOTE1="--->SLOW MACD<---";

extern int     MACD2FastEMA=12;

extern int     MACD2SlowEMA=26;

extern int     MACD2Signal=9;

extern int     enMACD2Mode=1;

extern int     enMACD2AppliedPrice=0;

//--- indicator buffers

double         FastBuffer[];

double         SlowBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   IndicatorDigits(Digits+1);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(0,FastBuffer);

   SetIndexBuffer(1,SlowBuffer);

   SetIndexLabel(0,"FAST");

   SetIndexLabel(1,"SLOW");


   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {


   int limit=rates_total-prev_calculated;

   for(int i=0;i<limit;i++)

   {

      FastBuffer[i]=iMACD(NULL,Period(),MACD1FastEMA,MACD1SlowEMA,MACD1Signal,enMACD1AppliedPrice,enMACD1Mode,i);

      SlowBuffer[i]=iMACD(NULL,Period(),MACD2FastEMA,MACD2SlowEMA,MACD2Signal,enMACD2AppliedPrice,enMACD2Mode,i);

   }


//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+

 
Please edit and use SRC when posting codes. Can't really see what the codes are.
 
/+------------------------------------------------------------------+

//|                                                       MACD 2.mq4 |

//|                        Copyright 2014, MetaQuotes Software Corp. |

//|                                              https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2014, MetaQuotes Software Corp."

#property link      "https://www.mql5.com"

#property version   "1.00"

#property strict

#property  indicator_separate_window

#property  indicator_buffers 2

#property  indicator_color1  Lime

#property  indicator_color2  Red

#property  indicator_width1  2

#property  indicator_width2  2

//--- input parameters



extern string  NOTE0="--->FAST MACD<---";

extern int     MACD1FastEMA=5;

extern int     MACD1SlowEMA=8;

extern int     MACD1Signal=3;

extern int     enMACD1Mode=1;

extern int     enMACD1AppliedPrice=0;

extern string  NOTE1="--->SLOW MACD<---";

extern int     MACD2FastEMA=12;

extern int     MACD2SlowEMA=26;

extern int     MACD2Signal=9;

extern int     enMACD2Mode=1;

extern int     enMACD2AppliedPrice=0;

//--- indicator buffers

double         FastBuffer[];

double         SlowBuffer[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function                         |

//+------------------------------------------------------------------+

int OnInit()

  {

//--- indicator buffers mapping

   IndicatorDigits(Digits+1);

   SetIndexStyle(0,DRAW_LINE);

   SetIndexStyle(1,DRAW_LINE);

   SetIndexBuffer(0,FastBuffer);

   SetIndexBuffer(1,SlowBuffer);

   SetIndexLabel(0,"FAST");

   SetIndexLabel(1,"SLOW");



   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| Custom indicator iteration function                              |

//+------------------------------------------------------------------+

int OnCalculate(const int rates_total,

                const int prev_calculated,

                const datetime &time[],

                const double &open[],

                const double &high[],

                const double &low[],

                const double &close[],

                const long &tick_volume[],

                const long &volume[],

                const int &spread[])

  {



   int limit=rates_total-prev_calculated;

   for(int i=0;i<limit;i++)

   {

      FastBuffer[i]=iMACD(NULL,Period(),MACD1FastEMA,MACD1SlowEMA,MACD1Signal,enMACD1AppliedPrice,enMACD1Mode,i);

      SlowBuffer[i]=iMACD(NULL,Period(),MACD2FastEMA,MACD2SlowEMA,MACD2Signal,enMACD2AppliedPrice,enMACD2Mode,i);

   }



//--- return value of prev_calculated for next call

   return(rates_total);

  }

//+------------------------------------------------------------------+
 

Hi

there is a point here

when you attach 2nd macd into first macd window mt4 auto scale 2nd macd to fit into first macd window, so values will be shifted.

it differs from writing new indicator with 2 signal values

if you open each macd in it's own window you will see that values will match with new written indicator

hope my comments be enough clear.

regards

Hooshang

 

problem is scale value for each indicator are difference.

if set scale to fixed value for 2 indicator it will show correct.

I have test this indicator (MACD2) this is correct.

I have fixed scale for the same value and this is result.

 

 
rockyhoangdn:

problem is scale value for each indicator are difference.

if set scale to fixed value for 2 indicator it will show correct.

I have test this indicator (MACD2) this is correct.

I have fixed scale for the same value and this is result.

 

Thanks for the input so far everyone.  One workaround identified.

But what if I want the outcome of the new indicator to be like the two combined indi's with non fixed scales (as the faster MACD then has wider swings)?  How can that be achieved?

In short, I am looking for a custom indicator which drawns the two MACD signal lines on their own scales like if you had dropped two MACDs on one indicator window, which does not force a single scale for both lines. 

Is it possible to read the scale of the indicator window and then multiply the buffer value of the smaller indi to fit in?

 
raybez:

Thanks for the input so far everyone.  One workaround identified.

But what if I want the outcome of the new indicator to be like the two combined indi's with non fixed scales (as the faster MACD then has wider swings)?  How can that be achieved?

In short, I am looking for a custom indicator which drawns the two MACD signal lines on their own scales like if you had dropped two MACDs on one indicator window, which does not force a single scale for both lines. 

Is it possible to read the scale of the indicator window and then multiply the buffer value of the smaller indi to fit in?


OK, some further digging and I came across the WindowPriceMin() & WindowPriceMax() functions.  How can the code above provided by trandongphat be modified to make use of these additional functions so that the faster MACD signal line buffer can be "adjusted" to fit in with the slower MACD?
 
raybez:

OK, some further digging and I came across the WindowPriceMin() & WindowPriceMax() functions.  How can the code above provided by trandongphat be modified to make use of these additional functions so that the faster MACD signal line buffer can be "adjusted" to fit in with the slower MACD?

I found a possible partial work around on https://www.mql5.com/en/forum/142578, for those also looking for a solution.