Deleting Chart Objects with Position SL/TP Info

gaudong

Newbie
Nov 4, 2024
2
0
1
41
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

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
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