You may have to play around with the button code to get result you want .
This link is also good — Graphical Interfaces III: Simple and Multi-Functional Buttons (Chapter 1)
Simple Button / Panel in Mql5 articles. if you search is also good.

- www.mql5.com
Dear experts,
How can I position my BUTTON object dynamically on chart in a way that when chart size changes or MT5 window is resized I can still see the buttons at the left most side of my chart (st like like Aligned left compared to chart window).
I create my BUTTON object with below code now and I give static x, y coordinates :
When I reduce MT5 screen size or chart window size, then they get disappear. I want to dynamically set their coordinates like "Aligden Left" compared to chart window
Thank you
Robobiee
You can monitor the chart event CHARTEVENT_CHART_CHANGE
Event of change of the chart size or modification of chart properties through the Properties dialog | CHARTEVENT_CHART_CHANGE |
In the OnChartEvent() function which fires when the chart is changed.
Then you recalculate the buttons position and then set the new positions for the button object and then you call ChartRedraw(); to update the chart.
//+------------------------------------------------------------------+ //| ChartEvent function | //+------------------------------------------------------------------+ void OnChartEvent(const int id, // Event identifier const long& lparam, // Event parameter of long type const double& dparam, // Event parameter of double type const string& sparam // Event parameter of string type ) { //--- Change of the chart size or modification of chart properties through the Properties dialog if(id==CHARTEVENT_CHART_CHANGE) { printf("CHARTEVENT_CHART_CHANGE"); } /* //--- the left mouse button has been pressed on the chart if(id==CHARTEVENT_CLICK) { Print("The coordinates of the mouse click on the chart are: x = ",lparam," y = ",dparam); } //--- the mouse has been clicked on the graphic object if(id==CHARTEVENT_OBJECT_CLICK) { Print("The mouse has been clicked on the object with name '"+sparam+"'"); } //--- the key has been pressed if(id==CHARTEVENT_KEYDOWN) { switch(lparam) { case KEY_NUMLOCK_LEFT: Print("The KEY_NUMLOCK_LEFT has been pressed"); break; case KEY_LEFT: Print("The KEY_LEFT has been pressed"); break; case KEY_NUMLOCK_UP: Print("The KEY_NUMLOCK_UP has been pressed"); break; case KEY_UP: Print("The KEY_UP has been pressed"); break; case KEY_NUMLOCK_RIGHT: Print("The KEY_NUMLOCK_RIGHT has been pressed"); break; case KEY_RIGHT: Print("The KEY_RIGHT has been pressed"); break; case KEY_NUMLOCK_DOWN: Print("The KEY_NUMLOCK_DOWN has been pressed"); break; case KEY_DOWN: Print("The KEY_DOWN has been pressed"); break; case KEY_NUMPAD_5: Print("The KEY_NUMPAD_5 has been pressed"); break; case KEY_NUMLOCK_5: Print("The KEY_NUMLOCK_5 has been pressed"); break; default: Print("Some not listed key has been pressed"); } ChartRedraw(); } //--- the object has been deleted if(id==CHARTEVENT_OBJECT_DELETE) { Print("The object with name ",sparam," has been deleted"); } //--- the object has been created if(id==CHARTEVENT_OBJECT_CREATE) { Print("The object with name ",sparam," has been created"); } //--- the object has been moved or its anchor point coordinates has been changed if(id==CHARTEVENT_OBJECT_DRAG) { Print("The anchor point coordinates of the object with name ",sparam," has been changed"); } //--- the text in the Edit of object has been changed if(id==CHARTEVENT_OBJECT_ENDEDIT) { Print("The text in the Edit field of the object with name ",sparam," has been changed"); } */ }
Alternatively you could also monitor CHART_HEIGHT_IN_PIXELS and CHART_WIDTH_IN_PIXELS in a timer event in case you want to create your own function of repositioning the chart objects.
int height=ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0); int width=ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0); Print("CHART_HEIGHT_IN_PIXELS =",height,"pixels"); Print("CHART_WIDTH_IN_PIXELS =",width,"pixels");
But this requires you to constantly monitor the chart which results in a performance hit.
You can monitor the chart event CHARTEVENT_CHART_CHANGE
Event of change of the chart size or modification of chart properties through the Properties dialog | CHARTEVENT_CHART_CHANGE |
In the OnChartEvent() function which fires when the chart is changed.
Then you recalculate the buttons position and then set the new positions for the button object and then you call ChartRedraw(); to update the chart.
Alternatively you could also monitor CHART_HEIGHT_IN_PIXELS and CHART_WIDTH_IN_PIXELS in a timer event in case you want to create your own function of repositioning the chart objects.
But this requires you to constantly monitor the chart which results in a performance hit.
Thank you very much !
You can monitor the chart event CHARTEVENT_CHART_CHANGE
Event of change of the chart size or modification of chart properties through the Properties dialog | CHARTEVENT_CHART_CHANGE |
In the OnChartEvent() function which fires when the chart is changed.
Then you recalculate the buttons position and then set the new positions for the button object and then you call ChartRedraw(); to update the chart.
Alternatively you could also monitor CHART_HEIGHT_IN_PIXELS and CHART_WIDTH_IN_PIXELS in a timer event in case you want to create your own function of repositioning the chart objects.
But this requires you to constantly monitor the chart which results in a performance hit.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear experts,
How can I position my BUTTON object dynamically on chart in a way that when chart size changes or MT5 window is resized I can still see the buttons at the left most side of my chart (st like like Aligned left compared to chart window).
I create my BUTTON object with below code now and I give static x, y coordinates :
When I reduce MT5 screen size or chart window size, then they get disappear. I want to dynamically set their coordinates like "Aligden Left" compared to chart window
Thank you
Robobiee