//+------------------------------------------------------------------+ //| Move horizontal line | //+------------------------------------------------------------------+ bool HLineMove(constlong chart_ID=0, // chart's ID conststring name="HLine", // line name double price=0) // line price
{
//--- if the line price is not set, move it to the current Bid price level if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value ResetLastError();
//--- move a horizontal line if(!ObjectMove(chart_ID,name,0,0,price))
{
Print(__FUNCTION__,
": failed to move the horizontal line! Error code = ",GetLastError());
return(false);
}
//--- successful execution return(true);
}
//+------------------------------------------------------------------+
Can't use move, because it's a label not a text object.
Ah ok sorry.
//+------------------------------------------------------------------+//| Move the text label |//+------------------------------------------------------------------+bool LabelMove(constlong chart_ID=0, // chart's IDconststring name="Label", // label nameconstint x=0, // X coordinateconstint y=0) // Y coordinate
{
//--- reset the error valueResetLastError();
//--- move the text labelif(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x))
{
Print(__FUNCTION__,
": failed to move X coordinate of the label! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
{
Print(__FUNCTION__,
": failed to move Y coordinate of the label! Error code = ",GetLastError());
return(false);
}
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+
If you want it to scroll with the chart you can also use:
//+------------------------------------------------------------------+//| Creating Text object |//+------------------------------------------------------------------+bool TextCreate(constlong chart_ID=0, // chart's IDconststring name="Text", // object nameconstint sub_window=0, // subwindow indexdatetime time=0, // anchor point timedouble price=0, // anchor point priceconststring text="Text", // the text itselfconststring font="Arial", // fontconstint font_size=10, // font sizeconstcolor clr=clrRed, // colorconstdouble angle=0.0, // text slopeconstENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // anchor typeconstbool back=false, // in the backgroundconstbool selection=false, // highlight to moveconstbool hidden=true, // hidden in the object listconstlong z_order=0) // priority for mouse click
{
//--- set anchor point coordinates if they are not set
ChangeTextEmptyPoint(time,price);
//--- reset the error valueResetLastError();
//--- create Text objectif(!ObjectCreate(chart_ID,name,OBJ_TEXT,sub_window,time,price))
{
Print(__FUNCTION__,
": failed to create \"Text\" object! Error code = ",GetLastError());
return(false);
}
//--- set the textObjectSetString(chart_ID,name,OBJPROP_TEXT,text);
//--- set text fontObjectSetString(chart_ID,name,OBJPROP_FONT,font);
//--- set font sizeObjectSetInteger(chart_ID,name,OBJPROP_FONTSIZE,font_size);
//--- set the slope angle of the textObjectSetDouble(chart_ID,name,OBJPROP_ANGLE,angle);
//--- set anchor typeObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- set colorObjectSetInteger(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 object by mouseObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- hide (true) or display (false) graphical object name in the object listObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- set the priority for receiving the event of a mouse click in the chartObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- successful executionreturn(true);
}
//+------------------------------------------------------------------+
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I have done that; I can retrieve y and set the starting position of the label; thank you.
But if I were to move the HLine, the label will not move with it again; could you take a look at my code?
No, I will not take a look at your code.
You are still trying to get the time from a horizontal line.
Re-write your code using TimeCurrent() and then I will take a look at any problems you may be having.
Try ObjectMove() in stead of OBJPROP_YDISTANCE
Here is an example:
Can't use move, because it's a label not a text object.
Can't use move, because it's a label not a text object.
Ah ok sorry.
If you want it to scroll with the chart you can also use:
With that ObjectMove example.