how to code a label object to stay on top of another label objects as will? Please

 

hello everyone! &

How to code a label object to stay on top of another label objects as will? Please

Im new to mql4. Recently, I read alot of object properties in mql articles & searched for solutions on google. unfortunately, I cant find out how to code a label object to stay on top of another label objects as will :/

I found some indis out there & the coders did it very well :)

Could anyone give me some idea? please

Have a good weekend & Thanks in advance!

//--

What I want is 
1. my label object always stays on some another labels which may belong to other ex4.indicators?
2.to kown the rules/functions... for priority displaying (label)objects on chart?

....my broblem : I want my label object (SOME TEXT) to stay on top of a lable object of another indicator (white lable).


attached is my code:

#property strict 
#property indicator_chart_window
//--- description 
input string            InpName="Label";         // Label name 
input int               InpX=150;                // X-axis distance 
input int               InpY=0;                // Y-axis distance 
input string            InpFont="Arial";         // Font 
input int               InpFontSize=14;          // Font size 
input color             InpColor=clrRed;         // Color 
input double            InpAngle=0.0;            // Slope angle in degrees 
input ENUM_BASE_CORNER  Incorner=CORNER_LEFT_LOWER; // chart corner for anchoring 
input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_LEFT_LOWER; // Anchor type 
input bool              InpBack=false;           // Background object 
input bool              InpSelection=false;       // Highlight to move 
input bool              InpHidden=false;          // Hidden in the object list 
input long              InpZOrder=0;             // Priority for mouse click 
extern string           words ="SOME TEXT";
//+------------------------------------------------------------------+ 

int OnInit()
  {
   EventSetTimer(1);
   return(INIT_SUCCEEDED);
  }
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime& time[],
                const double& open[],
                const double& high[],
                const double& low[],
                const double& close[],
                const long& tick_volume[],
                const long& volume[],
                const int& spread[])
  {
   
   return(rates_total);
  }
  void OnDeinit(const int reason)
    {
     if (reason!=REASON_CHARTCHANGE)   ObjectDelete(InpName);
    }
void OnTimer()
 { 
//--- store the label's coordinates in the local variables 
   int x=InpX; 
   int y=InpY; 
//--- create a text label on the chart
if (ObjectFind(InpName) == -1) 
   {LabelCreate(0,InpName,0,x,y,Incorner,words,InpFont,InpFontSize,InpColor,InpAngle,InpAnchor,InpBack,InpSelection,InpHidden,InpZOrder);} 
 } 
//+------------------------------------------------------------------+    
bool LabelCreate(const long              chart_ID=0,               // chart's ID 
                 const string            name="Label",             // label name 
                 const int               sub_window=0,             // subwindow index 
                 const int               x=0,                      // X coordinate 
                 const int               y=0,                      // Y coordinate 
                 const ENUM_BASE_CORNER  corner=CORNER_LEFT_UPPER, // chart corner for anchoring 
                 const string            text="Label",             // text 
                 const string            font="Arial",             // font 
                 const int               font_size=10,             // font size 
                 const color             clr=clrRed,               // color 
                 const double            angle=0.0,                // text slope 
                 const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor type 
                 const bool              back=false,               // in the background 
                 const bool              selection=false,          // highlight to move 
                 const bool              hidden=true,              // hidden in the object list 
                 const long              z_order=0)                // priority for mouse click 
  { 
//--- reset the error value 
   ResetLastError(); 
//--- create a text label 
   if(!ObjectCreate(chart_ID,name,OBJ_LABEL,sub_window,0,0))

     { 
      Print(__FUNCTION__, 
            ": failed to create text label! Error code = ",GetLastError()); 
      return(false); 
     } 
//--- set label coordinates 
   ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x); 
   ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y); 
//--- set the chart's corner, relative to which point coordinates are defined 
   ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner); 
//--- set the text 
   ObjectSetString(chart_ID,name,OBJPROP_TEXT,text); 
//--- set text font 
   ObjectSetString(chart_ID,name,OBJPROP_FONT,font); 
//--- set font size 
   ObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size); 
//--- set the slope angle of the text 
   ObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle); 
//--- set anchor type 
   ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor); 
//--- set color 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- display in the foreground (false) or background (true) 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- enable (true) or disable (false) the mode of moving the label by mouse 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- hide (true) or display (false) graphical object name in the object list 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- set the priority for receiving the event of a mouse click in the chart 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- successful execution 
   return(true); 
  }  
Files:
ask_mql5.png  26 kb
 

They are layered in the order they are created. So if you need to bring an object to the top then you need to destroy and recreate it or check the creation order from the start. Here is a quick demo script. 

#property strict


#include <ChartObjects\ChartObjectsShapes.mqh>
#include <ChartObjects\ChartObjectsTxtControls.mqh>

class MyRect : public CChartObjectRectLabel
{
   public: bool Create(){
      return(
         CChartObjectRectLabel::Create(0, "rect", 0, 0, 0, 50, 50)
         && this.Color(clrWhiteSmoke)
      );
   }
};
class MyLabel : public CChartObjectLabel
{
   public: bool Create(){
      return(
         CChartObjectLabel::Create(0, "label", 0, 0, 0)
         && this.Description("Created behind")
         && this.FontSize(15)
         && this.Color(clrYellow)
      );
   }
   bool bring_to_top(){
      this.Delete();
      return this.Create();
   }
};

void OnStart()
{
   MyLabel label;
   MyRect rect;
   label.Create();
   rect.Create();
   ChartRedraw();
   Sleep(3000);
   label.bring_to_top();
   label.Description("Brought to top");
   ChartRedraw();
   Sleep(3000);
 
nicholi shen:

They are layered in the order they are created. So if you need to bring an object to the top then you need to destroy and recreate it or check the creation order from the start. Here is a quick demo script. 

Thanks for your help! :) & knowledge of CObject class you gave me!

Finally, I made it myself ... haha!

have a good day Friend.

regard,

Reason: