Forex trailing stop error message

 

My cashmarket trailing stop applied to Forex is failing, sending this error code:

10036 - Invalid return code of the trade server

Anybody with some clue?

Thank you.

Daniel

 
Daniel Arges:

My cashmarket trailing stop applied to Forex is failing, sending this error code:

10036 - Invalid return code of the trade server

Anybody with some clue?

Thank you.

Daniel

10036

TRADE_RETCODE_POSITION_CLOSED

Position with the specified POSITION_IDENTIFIER has already been closed


https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes - Reference on algorithmic/automated trading language for MetaTrader 5
 
Daniel Arges:

My cashmarket trailing stop applied to Forex is failing,

Anybody with some clue?

  1. Can't trail positions that are closed.
  2. Apparently the coder doesn't.
 
Roberto Jacobs:

10036

TRADE_RETCODE_POSITION_CLOSED

Position with the specified POSITION_IDENTIFIER has already been closed


https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes

Thanks. This info will help.
 

Hi everyone. I have just come across this thread in my search for a solution to the error code 10036. [The https://www.mql5.com/en/docs/constants/errorswarnings/enum_trade_return_codes] referred to above points to error constants that will aid in understanding the errors output by the system, but it does not explain the reason for its occurrence in cases where one can see that there is an open order as in my case.  The code below shows a snippet from my EA to open a long position. Opens an order, then modifies it for stop and profit target.

void open_long()
  {
   buy_placed=_trade.buy(_Symbol,lot_size());

   if(buy_placed==true)
     {
      do(Sleep(100));
      while(PositionSelect(_Symbol)==false);
      double open_price=position_open_price(_Symbol);

      Print("open price: ",open_price);

      double buy_stop=buy_stop_loss(_Symbol,StopLoss,open_price);
      if(buy_stop>0) adjust_below_stop_level(_Symbol,buy_stop);

      double buy_profit=buy_take_profit(_Symbol,TakeProfit,open_price);
      if(buy_profit>0) adjust_above_stop_level(_Symbol,buy_profit);

      if(buy_stop>0 || buy_profit>0)
         _trade.modify_market(_Symbol,buy_stop,buy_profit);
     }
  }

Due to the delay between order placement and response from the server, and the update of positions, I make use of the while statement. On running the back tester bar by bar, I can see the order opened by first line in above function, but the error code 10036 soon shows it's ugly head. As you can see in the log snippet below, there are no messages of the order being closed from its opening, confirmation and to the modification attempt.   

2017.05.20 15:15:55.686 2017.01.02 09:15:00   exchange sell 0.53 EURUSD at 1.05214 (1.05214 / 1.05230 / 1.05214)
2017.05.20 15:15:55.686 2017.01.02 09:15:00   deal #2 sell 0.53 EURUSD at 1.05214 done (based on order #2)
2017.05.20 15:15:55.686 2017.01.02 09:15:00   deal performed [#2 sell 0.53 EURUSD at 1.05214]
2017.05.20 15:15:55.686 2017.01.02 09:15:00   order performed sell 0.53 at 1.05214 [#2 sell 0.53 EURUSD at 1.05214]
2017.05.20 15:15:55.688 2017.01.02 09:15:00   Open sell order #2: 10009 - Request is completed, Volume: 0.53, Price: 1.05214, Bid: 1.05214, Ask: 1.0523
2017.05.20 15:15:55.843 2017.01.02 09:15:00   failed modify #2 sell 0.53 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.05684, tp: 1.03694 [Position doesn't exist]
2017.05.20 15:15:55.843 2017.01.02 09:15:00   Alert: Modify position: Error 10036 - Invalid return code of the trade server
2017.05.20 15:15:55.843 2017.01.02 09:15:00   Modify position: 10036 - Invalid return code of the trade server, SL: 1.05684, TP: 1.03694, Bid: 1.05214, Ask: 1.0523, Stop Level: 0
2017.05.20 15:15:57.873 2017.01.02 11:05:00   failed modify #2 sell 0.53 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.05064, tp: 0.00000 [Position doesn't exist]
2017.05.20 15:15:57.873 2017.01.02 11:05:00   Order just closed: Error 10036
2017.05.20 15:15:57.873 2017.01.02 11:05:00   Break even stop: 10036 - Invalid return code of the trade server, SL: 1.05064, Bid: 0.0, Ask: 1.0478, Stop Level: 0
2017.05.20 15:15:57.873 2017.01.02 11:05:00   failed modify #2 sell 0.53 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.04910, tp: 0.00000 [Position doesn't exist]
2017.05.20 15:15:57.873 2017.01.02 11:05:00   Order already closed: Error 10036
2017.05.20 15:15:57.873 2017.01.02 11:05:00   Trailing stop: 10036 - Invalid return code of the trade server, Old SL: 0.0, New SL: 1.0491, Bid: 1.04767, Ask: 1.0478, Stop Level: 0
2017.05.20 15:15:57.969 2017.01.02 11:10:00   failed modify #2 sell 0.53 EURUSD sl: 0.00000, tp: 0.00000 -> sl: 1.05064, tp: 0.00000 [Position doesn't exist]

I am sure as you can see, there is nowhere in the log where the order is closed, and as of this instance, I am looking at the backtest screen the order is most definitely still open. Please see the screen shot image;Order #2 (Error 10036)

I have gone round with this issue and I am just baffled.  Where am I going wrong. As you can see,the error is systemic, since I cannot act on an order unless if I cannot find it. Here, it's leaving the position exposed without a stop or profit target. I can trail or anything related to order management.  Please help!

Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
Documentation on MQL5: Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes
  • www.mql5.com
Standard Constants, Enumerations and Structures / Codes of Errors and Warnings / Trade Server Return Codes - Reference on algorithmic/automated trading language for MetaTrader 5
 

You are probably using an hedge account with a code done for netting account only.

Show all relevant code if you need help.

 
Alain Verleyen:

You are probably using an hedge account with a code done for netting account only.

Show all relevant code if you need help.


Thanks Alain for your response and advice. Attached are two files, MfsSARMAExpert.mq5 and supporting file MfsTrade.mqh. I have also just checked on whether the account is a hedging account, YES it is. So what does this mean, with regards to my problem please. Thanks
Files:
 
I think I understand why having a hedge account is a problem with my current code.  I have just read this article: https://www.mql5.com/en/articles/2299, and now need to start working on making the changes to my code or switch to the MQL5 Trade Library.
MetaTrader 5 features hedging position accounting system
MetaTrader 5 features hedging position accounting system
  • 2016.03.21
  • MetaQuotes Software Corp.
  • www.mql5.com
In order to expand possibilities of retail Forex traders, we have added the second accounting system — hedging. Now, it is possible to have multiple positions per symbol, including oppositely directed ones. This paves the way to implementing trading strategies based on the so-called "locking" — if the price moves against a trader, they can open a position in the opposite direction.
 
Shephard Mukachi:

Thanks Alain for your response and advice. Attached are two files, MfsSARMAExpert.mq5 and supporting file MfsTrade.mqh. I have also just checked on whether the account is a hedging account, YES it is. So what does this mean, with regards to my problem please. Thanks
On an hedge account, if you want to modify or close an existing position you always have to specify a ticket number.
 
Alain Verleyen:
On an hedge account, if you want to modify or close an existing position you always have to specify a ticket number.

Thanks for that Alain. I have been reading a few from here that have helped. Thanks once again.
Reason: