Download MetaTrader 5

Object lable problem on indicator sub window?? MQL4 Buy or My mistake

To add comments, please log in or register
Install apps from the library right in MetaTrader. It is easy!
Young Ho Seo
15907
Young Ho Seo 2015.03.13 14:50 

Hi Fellow Traders and coders.


I have some interesting problem giving me some hard time to resolve several days. 

Recently I played with OBJ_LABEL on both MT5 and MT4. The code is shown below. The aim of this code is to write some text on indicator sub window (separate window from main window).

The funny things is this code works perfectly on Meta Trader 5 platform. Also it works well on Meta Trader 4 platform most of time.

However the problem is that I don't see the text any more when I restart Meta Trader 4 terminal (restarted after the indicator is attached on charts).

This does not happen on Meta Trader 5 terminal though.

The few clues I have found so far is:

  • While Meta Trader 4 is on and when I switch between different time frame, the text is shown as it should be. So ok.  
  • When I apply the same code to write something on Main window, it works fine. Even I restart Meta trader 4 terminal, they works as it should be.
  • The code block works perfectly on Meta Trader 5 terminal. So no issue with restarting Meta Trader 5 terminals.

Let me know if this couple of clues giving your some idea. So far, I don't find any logical ways of explaining this issue. Or this should be considered as  bugs ?

I will really appreciate your brilliant wisdom.

Kind regards.

F.E.


   //I have applied the same code for both MT5 and MT4


   //Code to write label
   ObjectCreate    (0, "label", OBJ_LABEL, subWindow, 0, 0);
   ObjectSetInteger(0, "label", OBJPROP_CORNER, 0); 
   ObjectSetInteger(0, "label", OBJPROP_BACK, false);
   ObjectSetInteger(0, "label", OBJPROP_XDISTANCE, x_pixel+4); 
   ObjectSetInteger(0, "label", OBJPROP_YDISTANCE, y_pixel+4);
   ObjectSetString (0, "label", OBJPROP_TEXT, "Test Text");
   ObjectSetInteger(0, "label", OBJPROP_FONTSIZE, 8);
   ObjectSetString (0, "label", OBJPROP_FONT, font);
   ObjectSetInteger(0, "label", OBJPROP_COLOR, colour);

   //Code to draw background 
   ObjectCreate    (0, "back", OBJ_LABEL, subWindow, 0, 0);  
   ObjectSetInteger(0, "back", OBJPROP_CORNER, 0); 
   ObjectSetInteger(0, "back", OBJPROP_BACK, false);
   ObjectSetInteger(0, "back", OBJPROP_XDISTANCE, x_pixel); 
   ObjectSetInteger(0, "back", OBJPROP_YDISTANCE, y_pixel);
   ObjectSetString (0, "back", OBJPROP_TEXT, "ggggggggggggggggg");
   ObjectSetInteger(0, "back", OBJPROP_FONTSIZE, 16);
   ObjectSetString (0, "back", OBJPROP_FONT, "Webdings");
   ObjectSetInteger(0, "back", OBJPROP_COLOR, bcl);



Alain Verleyen
Moderator
30775
Alain Verleyen 2015.03.13 14:58  
FinanceEngineer:

Hi Fellow Traders and coders.


I have some interesting problem giving me some hard time to resolve several days. 

Recently I played with OBJ_LABEL on both MT5 and MT4. The code is shown below. The aim of this code is to write some text on indicator sub window (separate window from main window).

The funny things is this code works perfectly on Meta Trader 5 platform. Also it works well on Meta Trader 4 platform most of time.

However the problem is that I don't see the text any more when I restart Meta Trader 4 terminal (restarted after the indicator is attached on charts).

This does not happen on Meta Trader 5 terminal though.

The few clues I have found so far is:

  • While Meta Trader 4 is on and when I switch between different time frame, the text is shown as it should be. So ok.  
  • When I apply the same code to write something on Main window, it works fine. Even I restart Meta trader 4 terminal, they works as it should be.
  • The code block works perfectly on Meta Trader 5 terminal. So no issue with restarting Meta Trader 5 terminals.

Let me know if this couple of clues giving your some idea. So far, I don't find any logical ways of explaining this issue. Or this should be considered as  bugs ?

I will really appreciate your brilliant wisdom.

Kind regards.

F.E.




Where is placed this code in your indicator ? OnInit() ? OnCalculate() ? other place ?
Young Ho Seo
15907
Young Ho Seo 2015.03.13 15:21  
angevoyageur:
Where is placed this code in your indicator ? OnInit() ? OnCalculate() ? other place ?

It is outside OnInit or OnCalculate. It is rather a function and called when it is necessary.

Regards.

Alain Verleyen
Moderator
30775
Alain Verleyen 2015.03.13 16:00  
FinanceEngineer:

It is outside OnInit or OnCalculate. It is rather a function and called when it is necessary.

Regards.


So when ?

Young Ho Seo
15907
Young Ho Seo 2015.03.13 16:15  
angevoyageur:


So when ?

The function will be called at least once by OnCalculate each new bar.

It will be also called by ChartEvent Handler frequently.

However when I check objects from terminal. The terminal have all the labels. It seems the terminal just mixing up its display order between the background label and text label. I have not got any clue why this is happening and what is fix.  

ObjectCreate    (0, "back", OBJ_LABEL, subWindow, 0, 0);  //background label. 

ObjectCreate    (0, "label", OBJ_LABEL, subWindow, 0, 0);  //text label 

Regards.

Young Ho Seo
15907
Young Ho Seo 2015.03.14 15:44  

In regards to this problem, I am just curious if there is a way of setting display order for each object.

This might be the solution for this problem. I am not aware that if MQL4 has such a function at the moment.

Kind regards.

To add comments, please log in or register