The function you're looking for is ChartTimePriceToXY.
bool ChartTimePriceToXY( long chart_id, // Chart ID int sub_window, // The number of the subwindow datetime time, // Time on the chart double price, // Price on the chart int& x, // The X coordinate for the time on the chart int& y // The Y coordinates for the price on the chart );
If you need help with the function, just ask, but basically you plug in the date and price on the chart, along with two variables (int x, y), and when it's done, the x and y variables will contain the x and y coordinates on the chart of the date and price you plugged in.
Another solution would be to enable "Show Object Description" for the chart and set the text to the object's description, but that can get messy when other objects have a description. Still, worth knowing and mentioning.
Side note: consider learning how to use the Standard Library, more specifically in your case, CChartObjectLabel.
All you need to be aware of is to call the Attach function if the object exists (it will return a bool value of true if it does) and Detach on DeInit so the object doesn't get deleted (usual reasons to detach are REASON_CHARTCHANGE, REASON_ACCOUNT, REASON_CLOSE, and maybe REASON_RECOMPILE and REASON_PARAMETERS, depending on your situation).

- docs.mql4.com
The function you're looking for is ChartTimePriceToXY
Another solution would be to enable "Show Object Description" for the chart and set the text to the object's description, but that can get messy when other objects have a description. Still, worth knowing and mentioning.
Side note: consider learning how to use the Standard Library, more specifically in your case, CChartObjectLabel.
All you need to be aware of is to call the Attach function if the object exists (it will return a bool value of true if it does) and Detach on DeInit so the object doesn't get deleted (usual reasons to detach are REASON_CHARTCHANGE, REASON_ACCOUNT, REASON_CLOSE, and maybe REASON_RECOMPILE and REASON_PARAMETERS, depending on your situation).
Thanks for leading me in the right direction! I have been searching the library but could not figure out which function to use.
The function you're looking for is ChartTimePriceToXY.
If you need help with the function, just ask, but basically you plug in the date and price on the chart, along with two variables (int x, y), and when it's done, the x and y variables will contain the x and y coordinates on the chart of the date and price you plugged in.
Another solution would be to enable "Show Object Description" for the chart and set the text to the object's description, but that can get messy when other objects have a description. Still, worth knowing and mentioning.
Side note: consider learning how to use the Standard Library, more specifically in your case, CChartObjectLabel.
All you need to be aware of is to call the Attach function if the object exists (it will return a bool value of true if it does) and Detach on DeInit so the object doesn't get deleted (usual reasons to detach are REASON_CHARTCHANGE, REASON_ACCOUNT, REASON_CLOSE, and maybe REASON_RECOMPILE and REASON_PARAMETERS, depending on your situation).
Hi.
I try to update x,y values in the Ontick function, but the x,y values are not updating. If I change the trendline, the text does not follow :(
Can you help me?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I cannot figure out how to add text just above the horizontal line drawn on the chart and centered in the chart window. The following is the code I have written so far:
///////////////////////////////////////////////////////////////////////////
ObjectCreate(0,"PrevDayHigh",OBJ_HLINE,0,TimeCurrent(),iHigh(Symbol(),1440,1));
ObjectSet("PrevDayHigh",OBJPROP_COLOR,Blue);
ObjectSet("PrevDayHigh",OBJPROP_WIDTH,1);
ObjectSet("PrevDayHigh",OBJPROP_STYLE,STYLE_SOLID);
ObjectSet("PrevDayHigh",OBJPROP_SELECTABLE,false);
ObjectSet("PrevDayHigh",OBJPROP_HIDDEN,true);
ObjectSet("PrevDayHigh",OBJPROP_BACK,true);
//ObjectDelete(0,"PrevDayHigh");
// Create Text just above horizonal line and centered in window
ObjectCreate("ObjName", OBJ_LABEL, 0, 0, 0);
ObjectSetText("ObjName","Testing Text just above Horizontal Line and centered in window",7, "Verdana", Red);
ObjectSet("ObjName",OBJPROP_YDISTANCE,50); // I don't know how to do this with price
///////////////////////////////////////////////////////////////////////////