Labels updating problem

 

As a newcomer to the forum and also to MT4 and to MQL I would first like to thank you all for sharing your knowledge and experience, your trading tools and ideas.
This first post of mine is a question about text labels. What I am trying to do is to have a table with indicator values regarding multiple currency pairs. The table could be displayed either on the main chart or in a sub-window and would look like this:
EURUSD 0.3108
GBPJPY   2.1723
USDCHF -0.3326
……………………….  
While I have managed to make the table and display it my problem is that, as new values keep coming in, the table doesn’t seem to refresh correctly. So, new values do not visually “replace” existing ones but they are rather written over the existing ones rendering the text unreadable. I am obviously missing something that has to do with proper redrawing, or refreshing, or something like that. There is also something else that I can’t explain: If I have only one pair displayed, the corresponding indicator’s values are correctly updated/displayed. The problem appears when I have more than one pair, even if each of them is displayed in a different place! Any suggestions please?

 
  1. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

  3. You should only create one set and then change the their text.
 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 Indicators section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. Do you really expect an answer? We can't see your broken code. There are no mind readers here and our crystal balls are cracked.

  3. You should only create one set and then change the their text.

1. Obviously because I am new and I missed the correct section. Sorry, about that. Yes, I will be a good boy next time! But:

     a) is https://www.mql5.com/en/forum/mql4 the correct place? Because I don't want to upset you again.

     b)  Should I repeat my question by opening a new topic there, or wait for the moderators to move it instead, as you said? I don't want to make things difficult for anyone.

2. Yes, I was expecting an answer, silly me..! The reason I did not bother you with my code is simply because I suspected that this is a typical, well-known problem, with a typical solution, easy to deal with and so there would be no need to show any code. I have no objection to do so, though. So, please find my code below.

3. If you are referring to my code, this is exactly what I tried to do, but I obviously failed. What I actually tried was to transform a similar code, namely "keep_rules_list.mq4" according to my needs. Thank you for the suggestion, but if it does not contain the correct way to do what you suggest then it it's not helpful. So, after seeing my code I would highly appreciate a few clear remarks on what exactly is wrong with it and why, and what I should do instead.Thanks! Here we go:

#property indicator_separate_window
#property indicator_buffers 0

string Text_0 = " ";
string Text_1 = " ";
string Text_2 = " ";
string Text_3 = " ";
string Text_4 = " ";
string Text_5 = " ";
string Text_6 = " ";
string Text_7 = " "; 
extern int x_coord = 200;

extern color colour_Text  = clrWhite;
extern string fontname    = "Arial";
extern int fontsize = 9;
//+------------------------------------------------------------------+
int init(){
IndicatorShortName("Trends_A");

   return(0);
}
//+------------------------------------------------------------------+
int deinit(){
ObjectDelete(Text_0);
ObjectDelete(Text_1);
ObjectDelete(Text_2);
ObjectDelete(Text_3);
ObjectDelete(Text_4);
ObjectDelete(Text_5);
ObjectDelete(Text_6);
ObjectDelete(Text_7);
}

//+------------------------------------------------------------------+
int start()  {
   setLabel(Text_0,Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);
   double EURUSD_t_q = iCustom("EURUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_0 = StringConcatenate("EURUSD: ",DoubleToStr(EURUSD_t_q,4));
   setLabel(Text_1,Text_1,colour_Text,0,x_coord,30,false,fontsize,fontname);
   double EURGBP_t_q = iCustom("EURGBP",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_1 = StringConcatenate("EURGBP: ",DoubleToStr(EURGBP_t_q,4));
   setLabel(Text_2,Text_2,colour_Text,0,x_coord,50,false,fontsize,fontname);
   double EURJPY_t_q = iCustom("EURJPY",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_2 = StringConcatenate("EURJPY: ",DoubleToStr(EURJPY_t_q,4));
   setLabel(Text_3,Text_3,colour_Text,0,x_coord,70,false,fontsize,fontname);
   double GBPUSD_t_q = iCustom("GBPUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_3 = StringConcatenate("GBPUSD: ",DoubleToStr(GBPUSD_t_q,4));
   setLabel(Text_4,Text_4,colour_Text,0,x_coord,90,false,fontsize,fontname);
   double NZDUSD_t_q = iCustom("NZDUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_4 = StringConcatenate("NZDUSD: ",DoubleToStr(NZDUSD_t_q,4));
   setLabel(Text_5,Text_5,colour_Text,0,x_coord,110,false,fontsize,fontname);
   double AUDUSD_t_q = iCustom("AUDUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_5 = StringConcatenate("AUDUSD: ",DoubleToStr(AUDUSD_t_q,4));
   setLabel(Text_6,Text_6,colour_Text,0,x_coord,130,false,fontsize,fontname);
   double USDCAD_t_q = iCustom("USDCAD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_6 = StringConcatenate("USDCAD: ",DoubleToStr(USDCAD_t_q,4));
   setLabel(Text_7,Text_7,colour_Text,0,x_coord,150,false,fontsize,fontname);
   double USDCHF_t_q = iCustom("USDCHF",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_7 = StringConcatenate("USDCHF: ",DoubleToStr(USDCHF_t_q,4));
   
     
}
//+------------------------------------------------------------------+
void setLabel(string name, string text, color col, int corner,
            int x, int y, bool back = false, int myfontsize = 9, 
            string myfontname = "MS Sans Serif") {
   if (ObjectFind(name)==-1){
      // aaa
      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1, 0, 0);
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y);          
   }else{
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y); 
   }  
}
 
//setLabel(Text_0,Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);
setLabel("Text_0",Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);

1. You should adopt fixed name as a object name.

//setLabel(Text_0,Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);
double EURUSD_t_q = iCustom("EURUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
Text_0 = StringConcatenate("EURUSD: ",DoubleToStr(EURUSD_t_q,4));
setLabel("Text_0",Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);

2. Set data to the variable before calling function "setLabel".

 
Naguisa Unada:

1. You should adopt fixed name as a object name.

2. Set data to the variable before calling function "setLabel".

Thanks very much Naguisa! Clear explanation and effective solution. No more digits-over-digits mess.

However I have a new problem now. I have made two almost identical indicators, both with the corrected code as per your instructions, one of them called "Table A" and containing a group of 8 currency pairs

and a second one called "Table B" and containing a different group of 8 currency pairs. I did that in order to have more available indicator buffers. Each of the tables performs great but only if the other one is not used at the same time!
Meaning that you can use either Table A or Table B, but not both of them at the same time, even if each group of 8 pairs is displayed in its own (different) place and even in different sub-windows! So, what happens is that when I drop Table A in a new sub-window it displays the first group of 8 currencies on the left side of the sub-window, as programmed. But as soon as I drop Table B in a new sub-window, then only the pairs of Table B stay on sight, but on the right side of sub-window A! (not B) while the first 8 pairs of Table A disappear and sub-window B gets empty!

Attached are the images and the two codes:

#property indicator_separate_window
#property indicator_buffers 0

string Text_0 = " ";
string Text_1 = " ";
string Text_2 = " ";
string Text_3 = " ";
string Text_4 = " ";
string Text_5 = " ";
string Text_6 = " ";
string Text_7 = " "; 
extern int x_coord = 200;

extern color colour_Text  = clrWhite;
extern string fontname    = "Arial";
extern int fontsize = 9;
//+------------------------------------------------------------------+
int init(){
IndicatorShortName("Trends_A");

   return(0);
}
//+------------------------------------------------------------------+
int deinit(){
ObjectDelete(Text_0);
ObjectDelete(Text_1);
ObjectDelete(Text_2);
ObjectDelete(Text_3);
ObjectDelete(Text_4);
ObjectDelete(Text_5);
ObjectDelete(Text_6);
ObjectDelete(Text_7);
}

//+------------------------------------------------------------------+
int start()  {
   
   double EURUSD_t_q = iCustom("EURUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_0 = StringConcatenate("EURUSD: ",DoubleToStr(EURUSD_t_q,4));
   setLabel("Text_0",Text_0,colour_Text,0,x_coord,10,false,fontsize,fontname);
   
   double EURGBP_t_q = iCustom("EURGBP",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_1 = StringConcatenate("EURGBP: ",DoubleToStr(EURGBP_t_q,4));
   setLabel("Text_1",Text_1,colour_Text,0,x_coord,30,false,fontsize,fontname);
   
   double EURJPY_t_q = iCustom("EURJPY",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_2 = StringConcatenate("EURJPY: ",DoubleToStr(EURJPY_t_q,4));
   setLabel("Text_2",Text_2,colour_Text,0,x_coord,50,false,fontsize,fontname);
  
   double GBPUSD_t_q = iCustom("GBPUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_3 = StringConcatenate("GBPUSD: ",DoubleToStr(GBPUSD_t_q,4));
   setLabel("Text_3",Text_3,colour_Text,0,x_coord,70,false,fontsize,fontname);
   
   double NZDUSD_t_q = iCustom("NZDUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_4 = StringConcatenate("NZDUSD: ",DoubleToStr(NZDUSD_t_q,4));
   setLabel("Text_4",Text_4,colour_Text,0,x_coord,90,false,fontsize,fontname);
   
   double AUDUSD_t_q = iCustom("AUDUSD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_5 = StringConcatenate("AUDUSD: ",DoubleToStr(AUDUSD_t_q,4));
   setLabel("Text_5",Text_5,colour_Text,0,x_coord,110,false,fontsize,fontname);
   
   double USDCAD_t_q = iCustom("USDCAD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_6 = StringConcatenate("USDCAD: ",DoubleToStr(USDCAD_t_q,4));
   setLabel("Text_6",Text_6,colour_Text,0,x_coord,130,false,fontsize,fontname);
   
   double USDCHF_t_q = iCustom("USDCHF",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_7 = StringConcatenate("USDCHF: ",DoubleToStr(USDCHF_t_q,4));
   setLabel("Text_7",Text_7,colour_Text,0,x_coord,150,false,fontsize,fontname);
     
}
//+------------------------------------------------------------------+
void setLabel(string name, string text, color col, int corner,
            int x, int y, bool back = false, int myfontsize = 9, 
            string myfontname = "MS Sans Serif") {
   if (ObjectFind(name)==-1){
      // aaa
      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1, 0, 0);
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y);          
   }else{
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y); 
   }  
}
#property indicator_separate_window
#property indicator_buffers 0

string Text_0 = " ";
string Text_1 = " ";
string Text_2 = " ";
string Text_3 = " ";
string Text_4 = " ";
string Text_5 = " ";
string Text_6 = " ";
string Text_7 = " "; 
extern int x_coord = 200;
string shortname = "";

extern color colour_Rule  = clrWhite;
extern string fontname    = "Arial";
extern int fontsize = 9;
//+------------------------------------------------------------------+
int init(){
IndicatorShortName("sr_Trends_B");

   return(0);
}
//+------------------------------------------------------------------+
int deinit(){
ObjectDelete(Text_0);
ObjectDelete(Text_1);
ObjectDelete(Text_2);
ObjectDelete(Text_3);
ObjectDelete(Text_4);
ObjectDelete(Text_5);
ObjectDelete(Text_6);
ObjectDelete(Text_7);
}

//+------------------------------------------------------------------+

int start()  {

   
   double AUDCAD_t_q = iCustom("AUDCAD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_0 = StringConcatenate("AUDCAD: ",DoubleToStr(AUDCAD_t_q,4));
   setLabel("Text_0",Text_0,colour_Rule,1,x_coord,10,false,fontsize,fontname);
   
   double AUDNZD_t_q = iCustom("AUDNZD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_1 = StringConcatenate("AUDNZD: ",DoubleToStr(AUDNZD_t_q,4)); 
   setLabel("Text_1",Text_1,colour_Rule,1,x_coord,30,false,fontsize,fontname);
   
   double CADJPY_t_q = iCustom("CADJPY",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_2 = StringConcatenate("CADJPY: ",DoubleToStr(CADJPY_t_q,4));
   setLabel("Text_2",Text_2,colour_Rule,1,x_coord,50,false,fontsize,fontname);
   ;
   double EURCHF_t_q = iCustom("EURCHF",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_3 = StringConcatenate("EURCHF: ",DoubleToStr(EURCHF_t_q,4));
   setLabel("Text_3",Text_3,colour_Rule,1,x_coord,70,false,fontsize,fontname);
   
   double EURNZD_t_q = iCustom("EURNZD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_4 = StringConcatenate("EURNZD: ",DoubleToStr(EURNZD_t_q,4));
   setLabel("Text_4",Text_4,colour_Rule,1,x_coord,90,false,fontsize,fontname);
   
   double GBPJPY_t_q = iCustom("GBPJPY",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_5 = StringConcatenate("GBPJPY: ",DoubleToStr(GBPJPY_t_q,4));  
   setLabel("Text_5",Text_5,colour_Rule,1,x_coord,110,false,fontsize,fontname);
  
   setLabel("Text_6",Text_6,colour_Rule,1,x_coord,130,false,fontsize,fontname);
   double GBPNZD_t_q = iCustom("GBPNZD",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_6 = StringConcatenate("GBPNZD: ",DoubleToStr(GBPNZD_t_q,4));
   
   double NZDJPY_t_q = iCustom("NZDJPY",0,"trend_quality_q_indicator",4, 250, 2.0,7,15,0,1.0,2.0,5.0,2,0);
   Text_7 = StringConcatenate("NZDJPY: ",DoubleToStr(NZDJPY_t_q,4));
   setLabel("Text_7",Text_7,colour_Rule,1,x_coord,150,false,fontsize,fontname);
}
//+------------------------------------------------------------------+
void setLabel(string name, string text, color col, int corner,
            int x, int y, bool back = false, int myfontsize = 9, 
            string myfontname = "MS Sans Serif") {
   if (ObjectFind(name)==-1){
      // aaa
      ObjectCreate(name, OBJ_LABEL, WindowOnDropped(),1, 0, 0);
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y);          
   }else{
      ObjectSetText(name, text, myfontsize, myfontname, col);
      ObjectSet(name, OBJPROP_CORNER, corner);
      ObjectSet(name, OBJPROP_BACK,back);
      ObjectSet(name, OBJPROP_XDISTANCE, x);
      ObjectSet(name, OBJPROP_YDISTANCE, y); 
   }  
}

Files:
Table_A.jpg  26 kb
Table_B.jpg  35 kb
 

It is because you use same object names for group A and group B.

Change names of group B to another, for example Text_8 ~ Text_15, and try it.

One more advice,

//ObjectDelete(Text_0);
ObjectDelete("Text_0");

 
Naguisa Unada:

It is because you use same object names for group A and group B.

Change names of group B to another, for example Text_8 ~ Text_15, and try it.

One more advice,

On the spot! And both your corrections well-written and -aimed.. Again!

I am learning from you. Thank you so much Naguisa!

 
Naguisa Unada:

It is because you use same object names for group A and group B.

Change names of group B to another, for example Text_8 ~ Text_15, and try it.

One more advice,

ObjectDelete("Text_0");
+1
Reason: