Modifying filled order

 

Hi,

I can't seem to be able to modify an order. Example below.

Put in a pending Buy Limit order 

Buy order is filled

Next I want to modify the TP/SL based on more recent price movement using OrderModify but this didn't work.


Am I allowed to use OrderModify on filled orders with open positions?

I don't want to use PositionModify for other reasons. Example being I want to hold both long and short positions.

Thanks.

 

Show your code.

 

Hi Alain

CTrade trade;
bool orderstructure_result=trade.BuyLimit(1,1.14592, NULL, 0,0,ORDER_TIME_GTC,0,"");
ulong ticket= trade.ResultOrder();

The buy order gets filled some time later so I am holding a long position. Then I want to modify the TP based on price movements. I used the following:

bool  orderstructure_result2=trade.OrderModify(ticket,1.14592,0,1.14610,ORDER_TIME_GTC,0,0);

orderstructure_result2 gave a false result.

 
dakr2019:

I don't want to use PositionModify for other reasons. Example being I want to hold both long and short positions.

bool              PositionModify(const ulong ticket,const double sl,const double tp);
 
dakr2019:

Hi Alain

The buy order gets filled some time later so I am holding a long position. Then I want to modify the TP based on price movements. I used the following:

orderstructure_result2 gave a false result.

Hard coding prices is not a good idea.

If the pending was triggered it's no more an "order", it's a position, you MUST use PositionModify().

 
Thanks Alain this makes sense now. The hardcoded price was to simplify the code. Cheers.
Reason: