i have an issue with this function code. Please any help will be greatly appreciated.
No. 1: it doesnt close breakeven when it partially closes the trade. states "OrderModify error 4108 unknown ticket 1 for OrderModify function" and i have tried my best but still dont get/understand it.
No. 2: it tries to partially close a trade it has partially close cos of the pips, is there a way i can mark those trade it already partially closed it? or another way out of it....Thanks so much
No. 1: it doesnt close breakeven when it partially closes the trade. states "OrderModify error 4108 unknown ticket 1 for OrderModify function" and i have tried my best but still dont get/understand it.
No. 2: it tries to partially close a trade it has partially close cos of the pips, is there a way i can mark those trade it already partially closed it? or another way out of it....Thanks so much
MQL4:
//+------------------------------------------------------------------+ //| Function to manage partial close and adjust stop loss to breakeven | //+------------------------------------------------------------------+ void ManagePartialClose() { for (int i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { double orderOpenPrice = OrderOpenPrice(); double currentPrice = (OrderType() == OP_BUY) ? Bid : Ask; double distance = (OrderType() == OP_BUY) ? currentPrice - orderOpenPrice : orderOpenPrice - currentPrice; if (distance >= partialClosePips * Point()) { double lotSizeToClose = OrderLots() * (partialClosePercent / 100.0); double lotSizeRemaining = OrderLots() - lotSizeToClose; int closeType = (OrderType() == OP_BUY) ? OP_SELL : OP_BUY; double closePrice = (OrderType() == OP_BUY) ? Bid : Ask; // Perform partial close if (OrderClose(OrderTicket(), lotSizeToClose, closePrice, slippage, clrNONE)) { // Adjust stop loss to breakeven double newSL = (OrderType() == OP_BUY) ? orderOpenPrice : orderOpenPrice; double newTP = (OrderType() == OP_BUY) ? (orderOpenPrice + takeprice * Point()) : (orderOpenPrice - takeprice * Point()); // Modify the remaining order to update stop loss to breakeven OrderModify(OrderTicket(), orderOpenPrice, newSL, newTP, 0, clrNONE); } } } } } }