How can I determine the color of the last few histogram bars?

 

The following MACD indicator code displays a MACD histogram with Red and Blue bars above and below the centerline.

QUESTION: How do I discover the color of the recent bars?

QUESTION: What actually causes the color change?

// MACD_inColor_Alert.mq4 |

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1
#property indicator_color3 DodgerBlue
#property indicator_width3 3
#property indicator_color4 Red
#property indicator_width4 3

//Extern variables
extern int TimeFrame = 0;
extern int FastEMA = 3;
extern int SlowEMA = 6;
extern int SignalSMA = 3;
extern int applied_price = 0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int init()
{
//---- indicator line
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_HISTOGRAM);
SetIndexStyle(3, DRAW_HISTOGRAM);
SetIndexDrawBegin(1, SignalSMA);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1);

SetIndexBuffer(0, ExtMapBuffer1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexBuffer(3, ExtMapBuffer4);

//Name for DataWindow and indicator subwindow label
switch(TimeFrame)
{
case 1 : string TimeFrameStr = "Period_M1"; break;
case 5 : TimeFrameStr = "Period_M5"; break;
case 15 : TimeFrameStr = "Period_M15"; break;
case 30 : TimeFrameStr = "Period_M30"; break;
case 60 : TimeFrameStr = "Period_H1"; break;
case 240 : TimeFrameStr = "Period_H4"; break;
case 1440 : TimeFrameStr = "Period_D1"; break;
case 10080 : TimeFrameStr = "Period_W1"; break;
case 43200 : TimeFrameStr = "Period_MN1"; break;
default : TimeFrameStr = "ChartTimeframe";
}

IndicatorShortName("MACD_inColor("+FastEMA+", "+SlowEMA+", "+SignalSMA+") ("+TimeFrameStr+")");

return(0);

}

int start()
{
datetime TimeArray[];
int i;
int limit;
int y = 0;
int counted_bars = IndicatorCounted();

//Plot defined time frame on to current time frame
ArrayCopySeries(TimeArray, MODE_TIME, Symbol(), TimeFrame);
limit = Bars - counted_bars;

for(i = 0, y = 0; i < limit; i++)
{
if (Time[i] < TimeArray[y]) y++;

ExtMapBuffer1[i] = iMACD(NULL, TimeFrame, FastEMA, SlowEMA, SignalSMA, applied_price, 0, y);
ExtMapBuffer2[i] = iMACD(NULL, TimeFrame, FastEMA, SlowEMA, SignalSMA, applied_price, 1, y);
ExtMapBuffer3[i] = ExtMapBuffer1[i] - ExtMapBuffer2[i];
ExtMapBuffer4[i] = ExtMapBuffer1[i] - ExtMapBuffer2[i];

if (ExtMapBuffer1[i] <= ExtMapBuffer2[i])
{
ExtMapBuffer3[i] = 0;
}
else
{
ExtMapBuffer4[i] = 0;
}

}

return(0);
}

 
chaffinsjc wrote >>

The following MACD indicator code displays a MACD histogram with Red and Blue bars above and below the centerline.

QUESTION: How do I discover the color of the recent bars?

QUESTION: What actually causes the color change?

// MACD_inColor_Alert.mq4 |

#property indicator_separate_window
#property indicator_buffers 4
#property indicator_color1 Lime
#property indicator_width1 1
#property indicator_color2 Yellow
#property indicator_width2 1
#property indicator_color3 DodgerBlue
#property indicator_width3 3
#property indicator_color4 Red
#property indicator_width4 3

//Extern variables
extern int TimeFrame = 0;
extern int FastEMA = 3;
extern int SlowEMA = 6;
extern int SignalSMA = 3;
extern int applied_price = 0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];

int init()
{
//---- indicator line
SetIndexStyle(0, DRAW_LINE);
SetIndexStyle(1, DRAW_LINE);
SetIndexStyle(2, DRAW_HISTOGRAM);
SetIndexStyle(3, DRAW_HISTOGRAM);
SetIndexDrawBegin(1, SignalSMA);
IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1);

SetIndexBuffer(0, ExtMapBuffer1);
SetIndexBuffer(1, ExtMapBuffer2);
SetIndexBuffer(2, ExtMapBuffer3);
SetIndexBuffer(3, ExtMapBuffer4);

//Name for DataWindow and indicator subwindow label
switch(TimeFrame)
{
case 1 : string TimeFrameStr = "Period_M1"; break;
case 5 : TimeFrameStr = "Period_M5"; break;
case 15 : TimeFrameStr = "Period_M15"; break;
case 30 : TimeFrameStr = "Period_M30"; break;
case 60 : TimeFrameStr = "Period_H1"; break;
case 240 : TimeFrameStr = "Period_H4"; break;
case 1440 : TimeFrameStr = "Period_D1"; break;
case 10080 : TimeFrameStr = "Period_W1"; break;
case 43200 : TimeFrameStr = "Period_MN1"; break;
default : TimeFrameStr = "ChartTimeframe";
}

IndicatorShortName("MACD_inColor("+FastEMA+", "+SlowEMA+", "+SignalSMA+") ("+TimeFrameStr+")");

return(0);

}

int start()
{
datetime TimeArray[];
int i;
int limit;
int y = 0;
int counted_bars = IndicatorCounted();

//Plot defined time frame on to current time frame
ArrayCopySeries(TimeArray, MODE_TIME, Symbol(), TimeFrame);
limit = Bars - counted_bars;

for(i = 0, y = 0; i < limit; i++)
{
if (Time[i] < TimeArray[y]) y++;

ExtMapBuffer1[i] = iMACD(NULL, TimeFrame, FastEMA, SlowEMA, SignalSMA, applied_price, 0, y);
ExtMapBuffer2[i] = iMACD(NULL, TimeFrame, FastEMA, SlowEMA, SignalSMA, applied_price, 1, y);
ExtMapBuffer3[i] = ExtMapBuffer1[i] - ExtMapBuffer2[i];
ExtMapBuffer4[i] = ExtMapBuffer1[i] - ExtMapBuffer2[i];

if (ExtMapBuffer1[i] <= ExtMapBuffer2[i])
{
ExtMapBuffer3[i] = 0;
}
else
{
ExtMapBuffer4[i] = 0;
}

}

return(0);
}

Is there anybody who can help? I really don't understand why the Red or Blue color is "chosen" for a bar. And I need to know what the last few colors were. Thank you.

Reason: