As i said I am new to MT4 software. I dont know if " I am looking to change the color of the indicator's buffers"
At this moment the color of the indicator is blue on chart.
As I said in my first post I want to change indicator color if certain condition is met.
Perhaps if you posted some code, people would be better placed to help you.
"The color of the indicator"... what does the indicator do? Draw rectangles, plot arrows, mark text, draw a wiggly line, make you a cup of tea.
Perhaps if you posted some code, people would be better placed to help you.
"The color of the indicator"... what does the indicator do? Draw rectangles, plot arrows, mark text, draw a wiggly line, make you a cup of tea.
Draw a line. It is similar with a moving average. I simply want to be blue on uptrend and red on downtrend but I do not think this is important. As I initial posted the general behavior has to be like:
if condition==true
indicator color=blue
else
indicator color=red
endif
I can answer your general question with a general answer, but I don't think it will help you.
if condition==true
indicator color=blue
else
indicator color=red
endif
Please give me some instructions how to code this in MT4 language.
if(condition) {ind_color=clrBlue;} else {ind_color=clrRed;}
But as I said, this most likely will not help you. That is not how most line-based indicators work.
A line indicator will generally be using at least one buffer to which you can assign a color. But the entirety of that line has to use the same color. If you want different colors, you need to use multiple buffers. Which then means your question is not how do I change the color, but how do I decide when to draw each buffer.
You need to get an understanding of how custom indicators work, either by reading the documentation or looking at other indicators and figuring out how they work.
I can answer your general question with a general answer, but I don't think it will help you.
But as I said, this most likely will not help you. That is not how most line-based indicators work.
A line indicator will generally be using at least one buffer to which you can assign a color. But the entirety of that line has to use the same color. If you want different colors, you need to use multiple buffers. Which then means your question is not how do I change the color, but how do I decide when to draw each buffer.
You need to get an understanding of how custom indicators work, either by reading the documentation or looking at other indicators and figuring out how they work.
Ok I tried to code. It is almost good except it has gaps on transition from one color to the other. Cannot understand why.
Please help with this code:
#property indicator_buffers 2 #property indicator_color1 Orange #property indicator_color2 DodgerBlue extern int Lb=3; double sslup[],ssldn[],Hld,Hlv; int dir[2]; #property indicator_chart_window //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexBuffer(0,sslup); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0); SetIndexBuffer(1,ssldn); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,0); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- for(int i=Bars-Lb;i>=0;i--) { dir[0]=dir[1]; if(Close[i]>iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1)) {dir[0]=1;} if(Close[i]<iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1)) {dir[0]=-1;} if(dir[0]==-1) sslup[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_HIGH,i+1); else { if(dir[0]==1) ssldn[i]=iMA(Symbol(),0,Lb,0,MODE_SMA,PRICE_LOW,i+1); } dir[1]=dir[0]; } //---- return(0); } //+------------------------------------------------------------------+
tenlau: it has gaps on transition from one color to the other. Cannot understand why.
| At a change in color, both buffers must have the same value. |
tenlau: it has gaps on transition from one color to the other. Cannot understand why. | At a change in color, both buffers must have the same value. |
Sorry, don't know how to "translate" in code your advice: "At a change in color, both buffers must have the same value."
Please show in the code I've posted.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I am newbie on MT4 coding. I am sure it is very simple to code what I want but for me is very complicated.
So I want to modify to the code of a custom indicator like this:
if condition==true
indicator color=blue
else
indicator color=red
endif
Please give me some instructions how to code this in MT4 language.
Thanks in advance !