End of the day, I has been found " OBJ_RECTANGLE and OBJ_TEXT ", which one I am thinking I can use both of them instead of " OBJ_LABEL and OBJ_RECTANGLE_LABEL " that both of them moves together Bid line.
Q: So, which objects very useful for moves together Bid lines, please?
I am really need informative comment. Have a nice weekend.
Unless you are testing sparam further up, that code triggers when any object is dragged.
My original code:
voidOnChartEvent(constint id, constlong& lparam, constdouble& dparam, conststring& sparam) { if(id==CHARTEVENT_OBJECT_DRAG&& sparam=="line") // the chart event of dragging the line
I already know / read your one of great example CrossHair.mq4. But I am struggling to give Bid price to Label, RectLabel Objects. Which is I am trying to Label, RectLabel Objects moves with Bid Line together.
I just need like image, please find attachment file.
For the fixed-sized objects: OBJ_BUTTON, OBJ_RECTANGLE_LABEL and OBJ_EDIT, properties OBJPROP_XDISTANCE and OBJPROP_YDISTANCE set the position of the top left point of the object relative to the chart corner (OBJPROP_CORNER), from which the X and Y coordinates will be counted in pixels.
} //+------------------------------------------------------------------+ //| Create rectangle by the given coordinates | //+------------------------------------------------------------------+ bool RectangleCreate(constlong chart_ID=0, // chart's ID conststring name="Rectangle", // rectangle name constint sub_window=0, // subwindow index datetime time1=0, // first point time double price1=0, // first point price datetime time2=0, // second point time double price2=0, // second point price constcolor clr=clrRed, // rectangle color constENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines constint width=1, // width of rectangle lines constbool fill=false, // filling rectangle with color constbool back=false, // in the background constbool selection=true, // highlight to move constbool hidden=true, // hidden in the object list constlong z_order=0) // priority for mouse click { //--- set anchor points' coordinates if they are not set ChangeRectangleEmptyPoints(time1,price1,time2,price2); //--- reset the error value ResetLastError(); //--- create a rectangle by the given coordinates if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2)) { Print(__FUNCTION__, ": failed to create a rectangle! Error code = ",GetLastError()); return(false); } //--- set rectangle color ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); //--- set the style of rectangle lines ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); //--- set width of the rectangle lines ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); //--- display in the foreground (false) or background (true) ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); //--- enable (true) or disable (false) the mode of highlighting the rectangle for moving //--- when creating a graphical object using ObjectCreate function, the object cannot be //--- highlighted and moved by default. Inside this method, selection parameter //--- is true by default making it possible to highlight and move the object 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); } //+------------------------------------------------------------------+ //| Move the rectangle anchor point | //+------------------------------------------------------------------+ bool RectanglePointChange(constlong chart_ID=0, // chart's ID conststring name="Rectangle", // rectangle name constint point_index=0, // anchor point index datetime time=0, // anchor point time coordinate double price=0) // anchor point price coordinate { //--- if point position is not set, move it to the current bar having Bid price if(!time) time=TimeCurrent(); if(!price) price=SymbolInfoDouble(Symbol(),SYMBOL_BID); //--- reset the error value ResetLastError(); //--- move the anchor point if(!ObjectMove(chart_ID,name,point_index,time,price)) { Print(__FUNCTION__, ": failed to move the anchor point! Error code = ",GetLastError()); return(false); } //--- successful execution return(true); } //+------------------------------------------------------------------+ //| Check the values of rectangle's anchor points and set default | //| values for empty ones | //+------------------------------------------------------------------+ void ChangeRectangleEmptyPoints(datetime &time1,double &price1, datetime &time2,double &price2) { //--- if the first point's time is not set, it will be on the current bar if(!time1) time1=TimeCurrent(); //--- if the first point's price is not set, it will have Bid value if(!price1) price1=SymbolInfoDouble(Symbol(),SYMBOL_BID); //--- if the second point's time is not set, it is located 9 bars left from the second one if(!time2) { //--- array for receiving the open time of the last 10 bars datetime temp[10]; CopyTime(Symbol(),Period(),time1,10,temp); //--- set the second point 9 bars left from the first one time2=temp[0]; } //--- if the second point's price is not set, move it 300 points lower than the first one if(!price2) price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT); } //+------------------------------------------------------------------+
Unless you are testing sparam further up, that code triggers when any object is dragged. My original code:
voidOnChartEvent(constint id, constlong& lparam, constdouble& dparam, conststring& sparam) { if(id==CHARTEVENT_OBJECT_DRAG&& sparam=="line") // the chart event of dragging the line
I already tried like below code.
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="#"+IntegerToString(OrderTicket())+"-TP") { // here was my functions }
That was not response to me.
---
But I use like below code which is I little change your code for me - and it works perfectly for me which one I want. So far I did not faced any problem. Am I doing wrong, please?
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 try to after drags finished OBJPROP_SELECTED could be " false " with below code, no effects.
How can I solve it, please?
{
SL_TPdrags();
Sleep(1000);
drag_onoff=false; // OBJPROP_SELECTED
}
Thanks in advance.
Im sorry i never use CHARTEVENT_OBJECT_DRAG.
End of the day, I has been found " OBJ_RECTANGLE and OBJ_TEXT ", which one I am thinking I can use both of them instead of " OBJ_LABEL and OBJ_RECTANGLE_LABEL " that both of them moves together Bid line.
Q: So, which objects very useful for moves together Bid lines, please?
I am really need informative comment.
Have a nice weekend.
ID
Description
OBJ_VLINE
Vertical Line
OBJ_HLINE
Horizontal Line
OBJ_TREND
Trend Line
OBJ_TRENDBYANGLE
Trend Line By Angle
OBJ_CYCLES
Cycle Lines
OBJ_ARROWED_LINE
Arrowed Line
OBJ_CHANNEL
Equidistant Channel
OBJ_STDDEVCHANNEL
Standard Deviation Channel
OBJ_REGRESSION
Linear Regression Channel
OBJ_PITCHFORK
Andrews Pitchfork
OBJ_GANNLINE
Gann Line
OBJ_GANNFAN
Gann Fan
OBJ_GANNGRID
Gann Grid
OBJ_FIBO
Fibonacci Retracement
OBJ_FIBOTIMES
Fibonacci Time Zones
OBJ_FIBOFAN
Fibonacci Fan
OBJ_FIBOARC
Fibonacci Arcs
OBJ_FIBOCHANNEL
Fibonacci Channel
OBJ_EXPANSION
Fibonacci Expansion
OBJ_ELLIOTWAVE5
Elliott Motive Wave
OBJ_ELLIOTWAVE3
Elliott Correction Wave
OBJ_RECTANGLE
Rectangle
OBJ_TRIANGLE
Triangle
OBJ_ELLIPSE
Ellipse
OBJ_ARROW_THUMB_UP
Thumbs Up
OBJ_ARROW_THUMB_DOWN
Thumbs Down
OBJ_ARROW_UP
Arrow Up
OBJ_ARROW_DOWN
Arrow Down
OBJ_ARROW_STOP
Stop Sign
OBJ_ARROW_CHECK
Check Sign
OBJ_ARROW_LEFT_PRICE
Left Price Label
OBJ_ARROW_RIGHT_PRICE
Right Price Label
OBJ_ARROW_BUY
Buy Sign
OBJ_ARROW_SELL
Sell Sign
OBJ_ARROW
Arrow
OBJ_TEXT
Text
OBJ_LABEL
Label
OBJ_BUTTON
Button
OBJ_CHART
Chart
OBJ_BITMAP
Bitmap
OBJ_BITMAP_LABEL
Bitmap Label
OBJ_EDIT
Edit
OBJ_EVENT
The "Event" object corresponding to an event in the economic calendar
OBJ_RECTANGLE_LABEL
The "Rectangle label" object for creating and designing the custom graphical interface.
What did you mean by move together ?
I try to after drags finished OBJPROP_SELECTED could be " false " with below code, no effects.
How can I solve it, please?
{
SL_TPdrags();
Sleep(1000);
drag_onoff=false; // OBJPROP_SELECTED
}
Thanks in advance.
Unless you are testing sparam further up, that code triggers when any object is dragged.
My original code:
{
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
I already know / read your one of great example CrossHair.mq4.
But I am struggling to give Bid price to Label, RectLabel Objects. Which is I am trying to Label, RectLabel Objects moves with Bid Line together.
I just need like image, please find attachment file.
All the best.
For the fixed-sized objects: OBJ_BUTTON, OBJ_RECTANGLE_LABEL and OBJ_EDIT, properties OBJPROP_XDISTANCE and OBJPROP_YDISTANCE set the position of the top left point of the object relative to the chart corner (OBJPROP_CORNER), from which the X and Y coordinates will be counted in pixels.
//| rectangle.mq4 |
//| Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Marco vd Heijden, MetaQuotes Software Corp."
#property link "https://www.mql5.com"
#property version "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//--- create timer
EventSetTimer(1);
//--- create rectangle
RectangleCreate(0,"Rectangle",0,0,0);
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
//---
RectanglePointChange(0,"Rectangle",0,TimeCurrent(),Ask);
}
//+------------------------------------------------------------------+
//| Timer function |
//+------------------------------------------------------------------+
void OnTimer()
{
//---
}
//+------------------------------------------------------------------+
//| Create rectangle by the given coordinates |
//+------------------------------------------------------------------+
bool RectangleCreate(const long chart_ID=0, // chart's ID
const string name="Rectangle", // rectangle name
const int sub_window=0, // subwindow index
datetime time1=0, // first point time
double price1=0, // first point price
datetime time2=0, // second point time
double price2=0, // second point price
const color clr=clrRed, // rectangle color
const ENUM_LINE_STYLE style=STYLE_SOLID, // style of rectangle lines
const int width=1, // width of rectangle lines
const bool fill=false, // filling rectangle with color
const bool back=false, // in the background
const bool selection=true, // highlight to move
const bool hidden=true, // hidden in the object list
const long z_order=0) // priority for mouse click
{
//--- set anchor points' coordinates if they are not set
ChangeRectangleEmptyPoints(time1,price1,time2,price2);
//--- reset the error value
ResetLastError();
//--- create a rectangle by the given coordinates
if(!ObjectCreate(chart_ID,name,OBJ_RECTANGLE,sub_window,time1,price1,time2,price2))
{
Print(__FUNCTION__,
": failed to create a rectangle! Error code = ",GetLastError());
return(false);
}
//--- set rectangle color
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- set the style of rectangle lines
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- set width of the rectangle lines
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width);
//--- display in the foreground (false) or background (true)
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- enable (true) or disable (false) the mode of highlighting the rectangle for moving
//--- when creating a graphical object using ObjectCreate function, the object cannot be
//--- highlighted and moved by default. Inside this method, selection parameter
//--- is true by default making it possible to highlight and move the object
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);
}
//+------------------------------------------------------------------+
//| Move the rectangle anchor point |
//+------------------------------------------------------------------+
bool RectanglePointChange(const long chart_ID=0, // chart's ID
const string name="Rectangle", // rectangle name
const int point_index=0, // anchor point index
datetime time=0, // anchor point time coordinate
double price=0) // anchor point price coordinate
{
//--- if point position is not set, move it to the current bar having Bid price
if(!time)
time=TimeCurrent();
if(!price)
price=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- reset the error value
ResetLastError();
//--- move the anchor point
if(!ObjectMove(chart_ID,name,point_index,time,price))
{
Print(__FUNCTION__,
": failed to move the anchor point! Error code = ",GetLastError());
return(false);
}
//--- successful execution
return(true);
}
//+------------------------------------------------------------------+
//| Check the values of rectangle's anchor points and set default |
//| values for empty ones |
//+------------------------------------------------------------------+
void ChangeRectangleEmptyPoints(datetime &time1,double &price1,
datetime &time2,double &price2)
{
//--- if the first point's time is not set, it will be on the current bar
if(!time1)
time1=TimeCurrent();
//--- if the first point's price is not set, it will have Bid value
if(!price1)
price1=SymbolInfoDouble(Symbol(),SYMBOL_BID);
//--- if the second point's time is not set, it is located 9 bars left from the second one
if(!time2)
{
//--- array for receiving the open time of the last 10 bars
datetime temp[10];
CopyTime(Symbol(),Period(),time1,10,temp);
//--- set the second point 9 bars left from the first one
time2=temp[0];
}
//--- if the second point's price is not set, move it 300 points lower than the first one
if(!price2)
price2=price1-300*SymbolInfoDouble(Symbol(),SYMBOL_POINT);
}
//+------------------------------------------------------------------+
Unless you are testing sparam further up, that code triggers when any object is dragged.
My original code:
{
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="line") // the chart event of dragging the line
{
// here was my functions
}
That was not response to me.
---
But I use like below code which is I little change your code for me - and it works perfectly for me which one I want. So far I did not faced any problem.
Am I doing wrong, please?
All the best.
Perhaps this will help.
Add this to a chart and you will see:
#property indicator_chart_window
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
ObjectCreate(0,"MyLine",OBJ_HLINE,0,0,Bid);
ObjectSetInteger(0,"MyLine",OBJPROP_SELECTED,true);
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
ObjectDelete(0,"MyLine");
}
//+------------------------------------------------------------------+
//| OnChartEvent() |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
const long& lparam,
const double& dparam,
const string& sparam)
{
if(id==CHARTEVENT_OBJECT_DRAG && sparam=="MyLine")
{
double price=ObjectGetDouble(0,"MyLine",OBJPROP_PRICE,0);
Alert("MyLine moved! New price is " + DoubleToStr(price,_Digits));
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
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);
}