- how can change color for indicator line & an object and they must have same color ?
- Requests & Ideas
- Jurik
HI, Is it possible to draw a line in the indicator box, and have it change colors when a condition changes. Please show an example..thx..
I just made one cutom indicator that is "one" line with two colors. In fact, they are two lines (two drawing buffers). Example: you have to do two things. Create two plot buffers (property and Set.....) and set the line break where you want. I look at an example of the Awesome indicator in my navigation window and open it with meta edit. (in your too).
Set property buff1 to Red;
set proerty buff2 to Green;
if (a>1.0) buff1 = iMA(......);
else buff2 = iMA(....);
your plot will look single line with the color change around ima=1.0.
As it understand(correct me if i am wrong) but using setindexbuffer doesnt work, you have to use icustom for this ptoblem.
kervin, ummm, you are wrong. But don't worry - it's how we learn! I expect that I've made more coding errors than most on this forum (I've been coding *gulp* 40 years ... and still learning).
SetIndexBuffer works just fine for 2 (or 3) colour lines. You need 2 (or 3) of them to do it.
All iCustom does is 'get value from another indicator module' . Should that indicator itself have 2 or 3 colours for a line, then you'll need to call iCustom 2 or 3 times
If its confortable for you i suggest to not use lines for coloring, you will always have some issues with redrawing/not drawing. I have not yet found a way to code around this problem. (Lines must have always at least to following non empty values to be drawn)
If you want lines. i suggest to use 3 buffers: Buf1 for the main line, that is draw always, buf2 and buf3 for the coloring.
The better thing (form my point of view) is to use arrows (arrowcode 108 is a dot) to make the coloring, might be not look that good as a colored line, but at least it is drawn correctly.
add: see this example of a colored MA. You can switch between dot and line style drawing...
//+------------------------------------------------------------------+ //| WMMM-ColoredMA.mq4 | //| when-money-makes-money.com | //| when-money-makes-money.com | //+------------------------------------------------------------------+ #property copyright "when-money-makes-money.com" #property link "when-money-makes-money.com" #property indicator_chart_window #property indicator_buffers 3 #property indicator_color1 Yellow #property indicator_color2 Blue #property indicator_color3 Red //---- buffers double MA[]; double MA.up[]; double MA.do[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ extern int MA.Period=14; extern int MA.Type=MODE_SMA; extern int MA.Price=PRICE_CLOSE; extern int MA.Shift=0; extern bool DrawDots=true; extern int SignalSize=3; int init() { //---- indicators SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,SignalSize); SetIndexBuffer(0,MA); if(DrawDots){ SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,SignalSize); SetIndexArrow(1,108); SetIndexBuffer(1,MA.up); SetIndexEmptyValue(1,0.0); SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,SignalSize); SetIndexArrow(2,108); SetIndexBuffer(2,MA.do); SetIndexEmptyValue(2,0.0); }else{ SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,SignalSize); SetIndexBuffer(1,MA.up); SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,SignalSize); SetIndexBuffer(2,MA.do); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- for(int i=Bars-counted_bars-1;i>=0;i--){ MA[i]=iMA(Symbol(),Period(),MA.Period,MA.Shift,MA.Type,MA.Price,i); if(MA[i]>MA[i+1]){ MA.up[i]=MA[i]; MA.do[i]=0; }else{ MA.up[i]=0; MA.do[i]=MA[i]; } } //---- Comment("when-money-makes-money.com"); return(0); } //+------------------------------------------------------------------+
add: see this example of a colored MA. You can switch between dot and line style drawing...
Thank you very much

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use