Qjol, drawing of one histogram requires two consecutive index buffers. You need to flip-flop their values to change colors. Good luck.
#property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Green #property indicator_color2 Blue #property indicator_minimum 0 #property indicator_maximum 1 double ExtMapBufGreen[]; double ExtMapBufRed[]; int init() { SetIndexBuffer(0,ExtMapBufGreen); SetIndexBuffer(1,ExtMapBufRed); SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3,Green); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3,Red); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); return(0); } int start() { int limit,Counted_bars; Counted_bars=IndicatorCounted(); limit=Bars-Counted_bars-1; for(int k = 0; k < limit; k++) { ExtMapBufGreen[k] = EMPTY_VALUE; ExtMapBufRed[k] = EMPTY_VALUE; if (Close[k] > Open[k]) { ExtMapBufGreen[k] = 1.0; ExtMapBufRed[k] = 0.0; } else { ExtMapBufGreen[k] = 0.0; ExtMapBufRed[k] = 1.0; } } return; }
thanks a lot here is the code
legend:
green = above 0 & above signal
blue = above 0 but below signal
orange = below 0 but above signal
red = below 0 & below signal
//+------------------------------------------------------------------+ //| Macd_Histogram.mq4 | //| Copyright © 2010, NADAV. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2010, NADAV." #property indicator_separate_window #property indicator_buffers 4 #property indicator_color1 Green #property indicator_color2 Blue #property indicator_color3 Orange #property indicator_color4 Red string indName="Macd_Hitogram"; //---- buffers double ExtMapBufGreen[]; double ExtMapBufBlue[]; double ExtMapBufOrange[]; double ExtMapBufRed[]; extern double FastEma = 12; extern double SlowEma = 26; extern double Signal = 9; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3,Green); SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,3,Blue); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,3,Orange); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,3,Red); SetIndexBuffer(0,ExtMapBufGreen); SetIndexBuffer(1,ExtMapBufBlue); SetIndexBuffer(2,ExtMapBufOrange); SetIndexBuffer(3,ExtMapBufRed); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit,Counted_bars; Counted_bars=IndicatorCounted(); limit=Bars-Counted_bars-1; //------- for(int k = 0; k < limit; k++) { ExtMapBufGreen[k] = EMPTY_VALUE; ExtMapBufBlue[k] = EMPTY_VALUE; ExtMapBufOrange[k] = EMPTY_VALUE; ExtMapBufRed[k] = EMPTY_VALUE; if (iMACD(NULL, 0, FastEma, SlowEma, Signal,PRICE_CLOSE, MODE_MAIN,k) > iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) && iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) > 0) { ExtMapBufGreen[k] = 1.0; ExtMapBufBlue[k] = 0.0; ExtMapBufOrange[k] = 0.0; ExtMapBufRed[k] = 0.0; } else if (iMACD(NULL, 0, FastEma, SlowEma, Signal,PRICE_CLOSE, MODE_MAIN,k) < iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) && iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) > 0) { ExtMapBufGreen[k] = 0.0; ExtMapBufBlue[k] = 1.0; ExtMapBufOrange[k] = 0.0; ExtMapBufRed[k] = 0.0; } else if (iMACD(NULL, 0, FastEma, SlowEma, Signal,PRICE_CLOSE, MODE_MAIN,k) > iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) && iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) < 0) { ExtMapBufGreen[k] = 0.0; ExtMapBufBlue[k] = 0.0; ExtMapBufOrange[k] = 1.0; ExtMapBufRed[k] = 0.0; } else if (iMACD(NULL, 0, FastEma, SlowEma, Signal,PRICE_CLOSE, MODE_MAIN,k) < iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) && iMACD (NULL, 0, FastEma, SlowEma, Signal, PRICE_CLOSE, MODE_SIGNAL,k) < 0) { ExtMapBufGreen[k] = 0.0; ExtMapBufBlue[k] = 0.0; ExtMapBufOrange[k] = 0.0; ExtMapBufRed[k] = 1.0; } } //-------------------------------------------------------------------- return; }
Files:
macd_histogram.mq4
5 kb
Thanks
Helped me 11 years after release :)
thanks. It helped me a lot too
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
if some one can help me out with this
i'm trying to draw an histogram like this
& so far without succes
legend:
green = above 0 & above signal
blue = above 0 but below signal
orange = below 0 but above signal
red = below 0 & below signal
can someone tell me how to go on from here ?
thanks