Text Object in the same color as the line

 

Dear Community,

how can I change automaticaly the text object color in the same color as the line? I have in my code the folowing lines:

#property indicator_color1 Green
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 LawnGreen      
#property indicator_color5 LightPink

int start(){
   ObjectCreate("High", OBJ_TEXT, 0, 0, 0);
   ObjectSetText("High", "High",fontsize,fontName, indicator_color1);
}

But if I change the color of my line in this inputbox, the color of the text object is still the same (see the second screenshot). I want that the color of my text label is always the same as of the line?

Thank you very much for your help in advance!


 
user_123:

Dear Community,

how can I change automaticaly the text object color in the same color as the line? I have in my code the folowing lines:

But if I change the color of my line in this inputbox, the color of the text object is still the same (see the second screenshot). I want that the color of my text label is always the same as of the line?

Thank you very much for your help in advance!


Can't you use SetIndexStyle() to set the colour of your Indicator buffers/indexes and then use an extern to set the colour and use the same exten variable for the colour of your Objects ?
 
user_123:

Dear Community,

how can I change automaticaly the text object color in the same color as the line? I have in my code the folowing lines:

But if I change the color of my line in this inputbox, the color of the text object is still the same (see the second screenshot). I want that the color of my text label is always the same as of the line?

Thank you very much for your help in advance!

Hi user_123,

Already asked before and answered. Hope you don't mind long reading https://www.mql5.com/en/forum/139079

 

Thank you very much for the answers! I use now an external variable and SetIndexStyle() for my colors of the line and the Label. Unfortunately if I change the color in the input window the color of the label changes immediately but the one of the line does not change (If I want that the line change its color I have to switch the time period). If I switch the time period, than the line color changes too. Is this a problem of the MetaTrader?

Thank you very much for your help!

 
user_123:

Thank you very much for the answers! I use now an external variable and SetIndexStyle() for my colors of the line and the Label. Unfortunately if I change the color in the input window the color of the label changes immediately but the one of the line does not change (If I want that the line change its color I have to switch the time period). If I switch the time period, than the line color changes too. Is this a problem of the MetaTrader?

Thank you very much for your help!


If you try to create an Object with the same name as one that already exists you will get an error . . . and if you test the reurn value from ObjectCreate you can use it to trigger a Print that shows you the error. For example: What are Function return values ? How do I use them ?

First test if the Object exists with ObjectFind, if not then create it . . if it does use ObjectSet to set it's attributes including colour.

 
user_123:

how can I change automaticaly the text object color in the same color as the line? I have in my code the folowing lines:

But if I change the color of my line in this inputbox, the color of the text object is still the same (see the second screenshot). I want that the color of my text label is always the same as of the line?

Since there is no way to find out what color has been selected for an indicator buffer. Ignore the option box.

Add an external color variable. Override the color with SetIndexStyle() and set your object the same.

 
RaptorUK:


If you try to create an Object with the same name as one that already exists you will get an error . . . and if you test the reurn value from ObjectCreate you can use it to trigger a Print that shows you the error. For example: What are Function return values ? How do I use them ?

First test if the Object exists with ObjectFind, if not then create it . . if it does use ObjectSet to set it's attributes including colour.

Dear RaptorUK,

Thank you for your advice, the check if the label exists is already in my code. My problem is not the label, but the color of the indicator line. If I change my color in the following input window, then the color of my label changes immediately but often (not always) the indicator line does not change its color. I have to change the time period, then are the label and the indicator line in the same color, which I chosen in the following input box:




I have already use the folowing code in my indicator:

extern color   Color1 = LightCoral;
extern color   Color2 = LimeGreen;
extern color   Color3 = Red;



int init(){
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1,Color1);
   SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1,Color2);
   SetIndexStyle(2,DRAW_LINE,STYLE_SOLID,1,Color3);

}
 
user_123:

Dear RaptorUK,

Thank you for your advice, the check if the label exists is already in my code. My problem is not the label, but the color of the indicator line. If I change my color in the following input window, then the color of my label changes immediately but often (not always) the indicator line does not change its color. I have to change the time period, then are the label and the indicator line in the same color, which I chosen in the following input box:

I have already use the folowing code in my indicator:

Hi user_123,

Try this, I think you have comment out the property

//#property indicator_color1 Green
//#property indicator_color2 Red
//#property indicator_color3 Blue
//#property indicator_color4 LawnGreen      
//#property indicator_color5 LightPink

It will be black on colors tab, see if that works