You do a partial close. From my code:
//+------------------------------------------------------------------+ //| Partial order close. | //+------------------------------------------------------------------+ bool CloseOrder(int ticket=EMPTY, double size=INF){ // INF == entire. /**/ if (ticket == EMPTY) ticket = OrderTicket(); else if (!OrderSelect(ticket, SELECT_BY_TICKET)){ Alert("OrderSelect(",ticket,",ticket) failed: "+GetLastError()); return(false); } double minLot = MarketInfo(Symbol(), MODE_MINLOT), lotStep = MarketInfo(Symbol(), MODE_LOTSTEP), sizeCurr = OrderLots(), sizeClose = MathFloor(size/lotStep)*lotStep, sizeRem = sizeCurr - sizeClose; if (sizeClose < minLot) return(false); if (sizeRem < minLot){ sizeClose = sizeCurr; // Close all color op.color = IfI(Color.Buy, Color.Sell); } else op.color = Aqua; if (GetTradeContext() < TC_LOCKED) return(false); if (OrderClose( ticket, sizeClose, now.close, Slippage.Pips*pips2points , op.color )){ RelTradeContext(); return(true); } Alert("OrderClose(ticket=", ticket, ", ...) [1] failed: ", GetLastError()); RelTradeContext(); // After GetLastError return(false); }
Hi,
I submit a OP_BUY order with 2 lots and profit target price A
Once opened order is confirmed, I would like to modify the open position in the following way:
Keep one lot for target A
Get out with the second lot at target A/2 (50% of target)
To resume: Get out from an open position with 50% of lots at 50% of target.
Any idea how to split a open position in 2 independent orders/tickets ?
I would suggest using OrderClose() and specify the number of lots you wish to liquidate once price is at A/2 (50% to target). So, your EA would monitor price, and when price gets to A/2, then the EA would call OrderClose() to close half the position. The other half of the open position would (hopefully) continue onto the takeprofit price originally set.
I would suggest using OrderClose() and specify the number of lots you wish to liquidate once price is at A/2 (50% to target). So, your EA would monitor price, and when price gets to A/2, then the EA would call OrderClose() to close half the position. The other half of the open position would (hopefully) continue onto the takeprofit price originally set.
Thank you Thirteen and WHRoeder. I will modify and check in the comming weeks this change. Thank you again.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi,
I submit a OP_BUY order with 2 lots and profit target price A
Once opened order is confirmed, I would like to modify the open position in the following way:
Keep one lot for target A
Get out with the second lot at target A/2 (50% of target)
To resume: Get out from an open position with 50% of lots at 50% of target.
I can submit initially 2 orders but for a scalping operation, the bid/ask is changing, few lap of time (one second ?) might be need it between the 2 orders. Otherwise the server might not understand (error return) the second order.
Sometime the second order is not opened (my internal EA constraint) as because spread becomes too big and it is non-sense for a low target profit. This is how today my EA is working: I submit 2 independent orders but sometimes seconds order is not opened.
Any idea how to split a open position in 2 independent orders/tickets ?
Thanks,
Dani