Deleting Chart Objects with Position SL/TP Info

gaudong

Newbie
Nov 4, 2024
2
0
1
40
This works great, only problem is it leaves the st and tp values on the chart as objects after the trade has closed, is it possible to update the code so it auto removes the objects after the trade has closed?

Thanks a lot
1.PNG
 

Attachments

  • slqtp_values.mq5
    30.2 KB · Views: 2

Enivid

Administrator
Staff member
Nov 30, 2008
19,210
1,504
144
Odesa
www.earnforex.com
I see you already have a piece of code at the end of the OnTimer() function that handles object deletion, however it's incorrect.

First, you need to cycle through objects backwards because you'll be deleting them.

Second, you already have a relevant ticket in each object. Just get that ticket value and check whether a respective position exists (using PositionSelectByTicket) and if not, delete the object.

PS: If you are hard set on using HistoryOrdersTotal, you need to call HistorySelect first.
 
  • 👍
Reactions: gaudong

gaudong

Newbie
Nov 4, 2024
2
0
1
40
I see you already have a piece of code at the end of the OnTimer() function that handles object deletion, however it's incorrect.

First, you need to cycle through objects backwards because you'll be deleting them.

Second, you already have a relevant ticket in each object. Just get that ticket value and check whether a respective position exists (using PositionSelectByTicket) and if not, delete the object.

PS: If you are hard set on using HistoryOrdersTotal, you need to call HistorySelect first.
I don't know the code , can you help me fix it?
thank you very much