Close half a position

 

When you close out half of a postion does the rest of it retain the same ticket number and does the closed half of the position make an entry in the history pool showing a closed order with the same ticket number as the other half which is still open ?

Reason I ask, I need to keep track of positions that were half closed so the EA doesnt try to half close the same ones again because of their profit being above the half close level having said that, the added complexities of managing multiple orders in an EA which part closes positions makes me wonder if it is really worth doing it that way, vs opening two separate positions to begin with, anyone got any thoughts on this ?

 

No there will be a new ticketnumber for the rest. But if a part is closed then ordermagicnumber is still the same and the symbol also

The situation will then be OrderLots() < Lots or OrderLots() is now Lots - closed part you still can manage this

 
SDC:
Reason I ask, I need to keep track of positions that were half closed so the EA doesnt try to half close the same ones again
I move the SL to BE+1 and THEN close half. No need to keep track.
 

Hmmm ok but my EA isnt using the TP/SL levels sent with the OrderSend() it manages the levels internally. The OrderSend() SL/TP levels only take effect if terminal is disconnected

So when an order is part closed, I need to find a way to get the new ticket number, I want to add it to an array to be checked against when part closing orders, if ticket exists in the array dont half close it because it is the remaining half of a previously half close order, so let it run to the next TP level.

Do you think if I test for the newest order in the pool immediately after a successful part close, that would be the one ?

 

Getting the new ticket number is easy. OrderSelect loop and find the ticket number not already known.

I also use a moving TP for disconnection protection.

But what happens when a power glitch or BSOD reboots the system? Either you must use persistent storage (update a disk file) or have a way to recover state by the current TP/SL levels. What happen if that happens during the orderClose before you can update the disk file?

What value are you using the broker's SL? SL = Real SL - nPips or some other similar value. You can always recalculate the real SL from the brokers SL. Move the Real SL to BE before partial close.
 
Thanks WHR I've been thinking about what you said, I like your idea to use the SL difference as part of BSOD recovery, I hadn't thought of that. I'm coding it to your suggestion, yes I am using a similar SL value, mine is Broker_SL = EA_SL + nPips
Reason: