error 4756 - page 2

 
angevoyageur:
What function, classes/method are you using to send/modify your orders ?
OrderSend() after setting up the MqlTradeRequest
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Trade Request Structure - Documentation on MQL5
 
RaptorUK:
OrderSend() after setting up the MqlTradeRequest

Have you see this (from OrderSend doc) ?

It should be noted that the successful completion of the OrderSend() method operation does not always mean a successful deal completion when placing a market order. Check the retcode value containing trade server return code, and values of deal or order field depending on the type of operation  in the returned result.


It would be easier to help in seeing the code.

 
angevoyageur:

Have you see this (from OrderSend doc) ?


It would be easier to help in seeing the code.

I check the returned result and only try to place the SL & TP if it returns  TRADE_RETCODE_PLACED  or  TRADE_RETCODE_DONE

         if( result.retcode != TRADE_RETCODE_PLACED && result.retcode != TRADE_RETCODE_DONE ) 
            {
            SetTPandSL = false;
            Print("Return code # ", result.retcode, " Bid ", result.bid, " Ask ", result.ask, " Deal price ", result.price);
            }
         else SetTPandSL = true;

 

         if(SetTPandSL && ECN)
            {
            // now modify Position to add SL & TP
            ZeroMemory(request);
            ZeroMemory(result);
            request.action = TRADE_ACTION_SLTP;                   // setting the TP & SL
            request.symbol = _Symbol;                             // symbol
            request.sl = lastTick.ask - SL_Size * _Point;        // Stop Loss
            request.tp = lastTick.ask + TP_Size * _Point;        // Take Profit  
            
            //--- send a trade request
            OrderSend(request,result);
            
            //--- write the server reply to log  
            Print(__FUNCTION__,": Placeing SL & TP ",result.comment, " Return code # ", result.retcode);  
            if( result.retcode != TRADE_RETCODE_PLACED && result.retcode != TRADE_RETCODE_DONE ) 
               Print("Return code # ", result.retcode, " Bid ", lastTick.bid, " Ask ", lastTick.ask, " Deal price ", 
                  result.price, " SL: ", request.sl, " TP: ", request.tp, " Freeze: ", Freeze, " Stoplevel: ", Stop );
            }
 
RaptorUK:

I check the returned result and only try to place the SL & TP if it returns  TRADE_RETCODE_PLACED  or  TRADE_RETCODE_DONE

 


It should be noted that the successful completion of the OrderSend() method operation does not always mean a successful deal completion when placing a market order. Check the retcode value containing trade server return code, and values of deal or order field depending on the type of operation  in the returned result.

You have to check deal ticket number :

  if( (result.retcode != TRADE_RETCODE_PLACED && result.retcode != TRADE_RETCODE_DONE) || result.deal == 0) 

This isn't last word, if your deal ticket is 0, your modification of SL/TP will not execute anyway. Still searching...


 
angevoyageur:

You have to check deal ticket number :

This isn't last word, if your deal ticket is 0, your modification of SL/TP will not execute anyway. Still searching...

I can do that but the issue is that the trade was successful and the position was opened . . yet when I tried to add the SL & TP it failed with Invalid Stops even though they weren't invalid.  It seems that I have to wait for something to happen before I can send the request to set the TP & SL . . .  but I don't really know what is the official, documented thing that I should be waiting for. 

 

Thanks for the reply :-) 

 
RaptorUK:

I can do that but the issue is that the trade was successful and the position was opened . . yet when I tried to add the SL & TP it failed with Invalid Stops even though they weren't invalid.  It seems that I have to wait for something to happen before I can send the request to set the TP & SL . . .  but I don't really know what is the official, documented thing that I should be waiting for. 

 

Thanks for the reply :-) 

I know. I am checking all mql5 site to find a response :-D

Edit:

There is absolutely nothing on this site showing how to put a sl / tp with a trade execution type of market.

Actually I have same problem but using PositionOpen in place of OrderSend, I can also do it manually.

 
angevoyageur:

I know. I am checking all mql5 site to find a response :-D

Edit:

There is absolutely nothing on this site showing how to put a sl / tp with a trade execution type of market.

Actually I have same problem but using PositionOpen in place of OrderSend, I can also do it manually.

I have found. It's a problem of synchronisation between your EA and trade server. You have to use event handler OnTradeTransaction().

The result of executing the trade request on a server sent by OrderSend() function can be tracked by OnTradeTransaction handler. It should be noted that OnTradeTransaction handler will be called several times when executing one trade request.

For example, when sending a market buy order, it is handled, an appropriate buy order is created for the account, the order is then executed and removed from the list of the open ones, then it is added to the orders history, an appropriate deal is added to the history and a new position is created. OnTradeTransaction function will be called for each of these events.

RTFM ;-) Give it a try...tomorow for me.
 
angevoyageur:

I have found. It's a problem of synchronisation between your EA and trade server. You have to use event handler OnTradeTransaction().

RTFM ;-) Give it a try...tomorow for me.
Ahhhh,  thanks,  will have a look.  :-)
 
RaptorUK:
Ahhhh,  thanks,  will have a look.  :-)
Was this the thread you found ?  https://www.mql5.com/en/forum/10850  it reports the same issue as I am having
 

 My EA is bringing u weird errors with build 778. The volume of 0.1 is normalized and clearly not invalid.

 

 2013.03.12 07:29:57 pivots (SILVER,M5) SILVER failed ORDER_TYPE_SELL_STOP with volume 0.10; err# 4756 check code: 10014 comments: Invalid volume

 2013.03.12 07:20:00 pivots (SILVER,M5) SILVER failed ORDER_TYPE_SELL_STOP with volume 0.10; err# 4756 returned code: 10014, broker comments: Invalid volume

 

 Here is the code that brings it up

 

      ResetLastError();
      if(OrderCheck(_request,_check)){
         if(!OrderSend(_request,_result)){
            Print(TradeSymbol," failed ",EnumToString(OrderType)," with volume ",DoubleToString(OrderVolume,2),"; err# ",GetLastError()," returned code: ",_result.retcode,", broker comments: ",_result.comment);
            return(false);}
         else{
            if(_result.retcode!=(0||TRADE_RETCODE_PLACED||TRADE_RETCODE_DONE)){
               Print(TradeSymbol," failed ",EnumToString(OrderType)," with volume ",DoubleToString(OrderVolume,2),"; err# ",GetLastError()," returned code: ",_result.retcode,", broker comments: ",_result.comment);}}}
      else{
         Print(TradeSymbol," failed ",EnumToString(OrderType)," with volume ",DoubleToString(OrderVolume,2),"; err# ",GetLastError()," check code: ",_check.retcode," comments: ",_check.comment);
         return(false); }

 


Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Standard Constants, Enumerations and Structures / Trade Constants / Order Properties - Documentation on MQL5
Reason: