Avoid chart objects visible in the foreground

 

As from the title, how can I prevent chart objects from being seen in foreground in MQL5?
I have also tried with OBJ_RECTANGLE_LABEL by setting different foreground properties of the chart and of the rectangle object, but without success.
As soon as I drag my EA (with the rectangle object) onto the chart it works fine but, I don't understand the logic behind it, after a few new candles the objects are seen in the foreground.

Thank you for any suggestions


 

 
Marco Dezzani:

how can I prevent chart objects from being seen in foreground in MQL5?

To prevent chart objects from being visible in the foreground, you can use the OBJPROP_BACK  property. Setting this property of the newly created objects to true will ensure that they are placed in the background of the chart.

ObjectSetInteger(chart_id,object_name,OBJPROP_BACK,true)


Marco Dezzani:

how can I prevent chart objects from being seen in foreground in MQL5?

Alternatively, if you want to bring your objects to the top of the list (foreground), you can modify their OBJPROP_TIMEFRAMES property.

ObjectSetInteger(chart_id,object_name,OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS);
ObjectSetInteger(chart_id,object_name,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);
 
MAHA #:
ObjectSetInteger(chart_id,object_name,OBJPROP_TIMEFRAMES,OBJ_NO_PERIODS); ObjectSetInteger(chart_id,object_name,OBJPROP_TIMEFRAMES,OBJ_ALL_PERIODS);

Thank you for your feedback.

Unfortunately I don't have control over the properties of the objects automatically drawn by MT5 like the ones in the image, e.g. a closure of a position and the dotted line so the objects drawn last have priority over my object which is actually a control panel with several objects but the lines drawn by MT5 overlap all the objects.

 
Marco Dezzani #:

Thank you for your feedback.

Unfortunately I don't have control over the properties of the objects automatically drawn by MT5 like the ones in the image, e.g. a closure of a position and the dotted line so the objects drawn last have priority over my object which is actually a control panel with several objects but the lines drawn by MT5 overlap all the objects.

Trade history Objects are stored in the Object List just like other Objects. Try manually enabling "Draw object as background" for a trade history Object and if that works, you can use ObjectFind() in a loop to do so programmatically. (I don't have a panel to test this).

edit_Object
 
Ryan L Johnson #:

Trade history Objects are stored in the Object List just like other Objects. Try manually enabling "Draw object as background" for a trade history Object and if that works, you can use ObjectFind() in a loop to do so programmatically. (I don't have a panel to test this).

I hadn't thought of this at all! I confirm that I have set these properties manually and they are indeed no longer displayed in the foreground on my panel. I can now do this programmatically by checking not all objects but only the last ones in order of appearance. Thank you very much for your very helpful suggestion