Chris Pinter:
request.sl = SymbolInfoDouble(_Symbol,SYMBOL_BID);
I am puzzled why you would use a SL instead of a price when you are trying to close an order.
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hello,
I created an EA and I need to close a position by the ticket number. I am loading the EA into the VPS and for some reason I cannot close my positions.
I get this error message 10027
My close position code looks like this.
void close_position(long ticket) // --> MQL5 Refereances , Constants Emulations and Structures, Trade Constants, Trade Operation types { PositionSelectByTicket(ticket); // get the right ticket, PositionGetInteger, PositionGetDouble and PositionGetString can now be used. ENUM_POSITION_TYPE type = (ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE); string position_symbol = PositionGetString(POSITION_SYMBOL); double volume = PositionGetDouble(POSITION_VOLUME); double SL = PositionGetDouble(POSITION_SL); double open_price = PositionGetDouble(POSITION_PRICE_OPEN); MqlTradeRequest request; MqlTradeResult result; ZeroMemory(request); ZeroMemory(result); request.action =TRADE_ACTION_DEAL; // type of trade operation request.type_filling = ORDER_FILLING_IOC; // Order execution type request.position= ticket; // ticket of the position // request.magic = EA_Magic; request.volume = volume; request.deviation = 5; if(type ==POSITION_TYPE_BUY) // && position_symbol == ChartSymbol() { request.sl = SymbolInfoDouble(_Symbol,SYMBOL_BID); request.type = ORDER_TYPE_SELL; } if(type == POSITION_TYPE_SELL) // && position_symbol == ChartSymbol() { request.sl = SymbolInfoDouble(_Symbol,SYMBOL_ASK); request.type = ORDER_TYPE_BUY; } //--- send the request if(!OrderSend(request,result)) { string sb_time = TimeToString(TimeCurrent()); string scc_ticket = IntegerToString(ticket); string error = IntegerToString(result.retcode); string Chart = ChartSymbol(); string message = "Chart - | Ticket: " + scc_ticket + " Force Close failed | " + error + " | - retry with 20 div | Server Time: " + sb_time; Print(message); sendnotify = SendNotification(message); request.deviation = 20; if(!OrderSend(request,result)) { sb_time = TimeToString(TimeCurrent()); scc_ticket = IntegerToString(ticket); error = IntegerToString(result.retcode); Chart = ChartSymbol(); message = "!!!! Chart - | Ticket: " + scc_ticket + " Force Close failed 2nd attempt | " + error + " | Server Time: " + sb_time; Print(message); sendnotify = SendNotification(message); } } else { string sb_time = TimeToString(TimeCurrent()); string scc_ticket = IntegerToString(ticket); string Chart = ChartSymbol(); string message = "Chart - | Ticket: " + scc_ticket + " Force Close PASSED | Server Time: " + sb_time; Print(message); sendnotify = SendNotification(message); } return; }
I double check to make sure the order was still active and of course it was not closed. This is a very weird issue. I even put a second stage on the close position with a deviation of 20 and it did not help to force a close.
Why am I not able to close a position? Again, I have migrated the software to the VPS. Everything else in my code works. I can create and modify a position with a new stoploss, But I cannot CLOSE a position.
Thanks,
Chris