• Home
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • User/Email: Password:
  • 11:48pm
Menu
  • Forums
  • Trades
  • News
  • Calendar
  • Market
  • Brokers
  • Login
  • Join
  • 11:48pm
Sister Sites
  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Options

Bookmark Thread

First Page First Unread Last Page Last Post

Printable Version

Similar Threads

Another Day, Another Chair, Another Day in the Office 153 replies

Help adding another line and the MA label in TMS 10 EMA dashboard 0 replies

How to manually copy one object only to another chart 0 replies

Signaling a change in "select/unselect" an Object into an Indic. code 10 replies

Left align object descriptions in MT4? 0 replies

  • Platform Tech
  • /
  • Reply to Thread
  • Subscribe
  • 1
Attachments: how to code a label object to stay on top of another label?
Exit Attachments

how to code a label object to stay on top of another label?

  • Post #1
  • Quote
  • First Post: Edited at 10:12pm Oct 14, 2018 10:46am | Edited at 10:12pm
  •  aPhong
  • Joined Sep 2017 | Status: done with FF! | 241 Posts
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 at will :/
I found some indis out there & the coders did it very well
Could anyone give me some idea? please & have a good weekends
//--
What I want is
1. my label object always stays on some another labels which may belong to other ex4.indicators?
2.to know 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 label).
Inserted Code
#property strict
#property indicator_chart_window
//--- description
//--- input parameters of the script
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)) //OBJPROP_BGCOLOR
     {
      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);
  }
Attached Image (click to enlarge)
Click to Enlarge

Name: ask mql5.png
Size: 26 KB
positive interest or negative interest?
  • Post #2
  • Quote
  • Oct 14, 2018 12:13pm Oct 14, 2018 12:13pm
  •  sakisf
  • Joined Sep 2013 | Status: boreddddd | 3,135 Posts
OBJPROP_BACK, true the first item you dont care for, OBJPROP_BACK, false the item you want always in foreground.
1
  • Post #3
  • Quote
  • Edited at 10:11pm Oct 14, 2018 8:32pm | Edited at 10:11pm
  •  aPhong
  • Joined Sep 2017 | Status: done with FF! | 241 Posts
Quoting sakisf
Disliked
OBJPROP_BACK, true the first item you dont care for, OBJPROP_BACK, false the item you want always in foreground.
Ignored
Thank you for your comment! I already know that & that is not what I want to do! :/
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?

have a good day friend!
positive interest or negative interest?
  • Post #4
  • Quote
  • Last Post: Edited at 10:26pm Oct 14, 2018 9:51pm | Edited at 10:26pm
  •  Nicholishen
  • Joined Jul 2005 | Status: zzzzzzzzzzzzzzzzzzzzzzzzz zzzzzzzzzz | 1,289 Posts
Quoting aPhong
Disliked
{quote} Thank you for your comment! I already know that & that is not what I want to do! :/ What I want is 1. my label object always stay on some another labels which may belong to other ex4.indicators? 2.to kown the rules/functions... for priority displaying (label)objects on chart? have a good day friend!
Ignored
The best way is to use the controls classes for this. Here's a super quick and dirty example.

EDIT: Better example!
Inserted Code
//EXPERT
#property strict
#include <Controls\Dialog.mqh>
#include <Controls\Label.mqh>
 
class LabelWindow : public CAppDialog
{
   CLabel m_label;
public:
   bool Create(){
      return (
         CAppDialog::Create(0, "Label Window", 0, 10, 10, 200, 100)
         && m_label.Create(m_chart_id, m_name+"_label", m_subwin, 10, 5, 0, 0)
         && m_label.Text("TEST LABEL")
         && m_label.FontSize(20)
         && m_label.Color(clrRed)
         && this.Add(m_label)
      );
   }
};
LabelWindow app;
int OnInit()
{
   if(!app.Create() || !app.Run())
      return INIT_FAILED;  
   return(INIT_SUCCEEDED);
}
void OnTick(){}
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
   app.OnEvent(id, lparam, dparam, sparam);
}
void OnDeinit(const int reason)
{
   app.Destroy(reason);
}
1
  • Platform Tech
  • /
  • how to code a label object to stay on top of another label?
  • Reply to Thread
0 traders viewing now
Top of Page
  • Facebook
  • Twitter
About FF
  • Mission
  • Products
  • User Guide
  • Media Kit
  • Blog
  • Contact
FF Products
  • Forums
  • Trades
  • Calendar
  • News
  • Market
  • Brokers
  • Trade Explorer
FF Website
  • Homepage
  • Search
  • Members
  • Report a Bug
Follow FF
  • Facebook
  • Twitter

FF Sister Sites:

  • Metals Mine
  • Energy EXCH
  • Crypto Craft

Forex Factory® is a brand of Fair Economy, Inc.

Terms of Service / ©2021