Can a BuyLimit be closed instead of cancelling it?

 

My EA opened a BuyLimit with an SL and TP as shown in the image below. The order is not considered a position, which can be verified by doing a "PositionsTotal", that means I cannot use the PositionClose method to lock-in the profit. I understand why there are instances the order is not closed even when the TP is hit due to the spread. I run my EA and there are instances like this. So I added a logic where if I detect the price pulled back from my TP, I will close the position. However, I cannot find the correct way of closing the order. So instead of losing from that order, I just delete it for now by calling the OrderDelete method. In summary...

I want to have this:
WhatMethodToCall? - close the position with a smaller profit than the TP

instead of:
OrderDelete - cancelling the order before it hits the SL so there's no gain or loss


 
dinotrader15: My EA opened a BuyLimit with an SL and TP as shown in the image below. The order is not considered a position, which can be verified by doing a "PositionsTotal", that means I cannot use the PositionClose method to lock-in the profit. I understand why there are instances the order is not closed even when the TP is hit due to the spread. I run my EA and there are instances like this. So I added a logic where if I detect the price pulled back from my TP, I will close the position. However, I cannot find the correct way of closing the order. So instead of losing from that order, I just delete it for now by calling the OrderDelete method. In summary...


I want to have this:
WhatMethodToCall? - close the position with a smaller profit than the TP

instead of:
OrderDelete - cancelling the order before it hits the SL so there's no gain or loss

No, you cannot close an Order if it has not been filled. It has to be deleted/removed/cancelled.

A Position is an Order that has been filled and entered the market, but an Order that has not yet been filled has no "value". It is just a "request" waiting in the queue. It does not affect profit or loss.

Please take some time to learn the basics of trading. Otherwise you will just end up losing your money.

 
Fernando Carreiro #:

No, you cannot close an Order if it has not been filled. It has to be deleted/removed/cancelled.

A Position is an Order that has been filled and entered the market, but an Order that has not yet been filled has no "value". It is just a "request" waiting in the queue. It does not affect profit or loss.

Alright that makes sense. Thank you!
Reason: