Download MetaTrader 5

MQL5 Place Market order with tp and sl

To add comments, please log in or register
robertbaptie
13
robertbaptie  

Running through strategy tester


I have the following snippet of code which returns 0 into ticket.       


The journal shows:

2014.05.06 19:16:48.519    2014.01.22 01:42:00   failed market sell 0.01 EURUSD sl: 1.35770 tp: 1.35570 [Unsupported filling mode]

2014.05.06 19:16:48.519    2014.01.22 01:41:00   Alert:  The sell order could not be completed 4756 = Account Error - send order?


The following is contained in my mRequest and mResult:

MqlTradeRequest mRequest;
MqlTradeResult mResult;

MqlTradeRequest{  action:TRADE_ACTION_DEAL magic:12345678 order:0 symbol:"EURUSD" volume:0.01 price:1.39296 stoplimit:0 sl:1.39396 tp:1.39196 deviation:200 type:ORDER_TYPE_SELL type_filling:ORDER_FILLING_FOK type_time:ORDER_TIME_GTC expiration… }

MqlTradeResult{  retcode:0 deal:0 order:0 volume:0 price:0 bid:0 ask:0 comment:NULL request_id:0 reserved:[128] }


Does Anyone know what Im doing wrong here - Im new to MT4 and MT5?

               ZeroMemory(mRequest);            
               mRequest.action = TRADE_ACTION_DEAL;                                // immediate order execution
               mRequest.price = NormalizeDouble(latestPrice.ask,_Digits);          // latest ask price
               mRequest.sl = NormalizeDouble(latestPrice.ask + STP*_Point,_Digits); // Stop Loss
               mRequest.tp = NormalizeDouble(latestPrice.ask - TKP*_Point,_Digits); // Take Profit
               mRequest.symbol = _Symbol;                                         // currency pair
               mRequest.volume = Lots;                                            // number of lots to trade
               mRequest.magic = EA_Magic;                                        // Order Magic Number
               mRequest.type = ORDER_TYPE_SELL;                                     // Buy Order
               mRequest.type_filling = ORDER_FILLING_FOK;                          // Order execution type
               mRequest.deviation=200; //Point size                                            // Deviation from current price
               //--- send order
               ticket = OrderSend(mRequest,mResult);
               Print("ticet: ",ticket);
               
               ZeroMemory(mResult);   
               if(mResult.retcode ==10009 || mResult.retcode == 10008){
                  Alert("Order has been placed ",mResult.order);
               } else {
                  Alert(" The sell order could not be completed ",GetLastError());
                  ResetLastError();
                  return;
               }   

Alain Verleyen
Moderator
31193
Alain Verleyen  
robertbaptie:

Running through strategy tester

I have the following snippet of code which returns 0 into ticket.        


The journal shows:

2014.05.06 19:16:48.519    2014.01.22 01:42:00   failed market sell 0.01 EURUSD sl: 1.35770 tp: 1.35570 [Unsupported filling mode]

2014.05.06 19:16:48.519    2014.01.22 01:41:00   Alert:  The sell order could not be completed 4756


The following is contained in my mRequest and mResult:

MqlTradeRequest mRequest;
MqlTradeResult mResult;

MqlTradeRequest{  action:TRADE_ACTION_DEAL magic:12345678 order:0 symbol:"EURUSD" volume:0.01 price:1.39296 stoplimit:0 sl:1.39396 tp:1.39196 deviation:200 type:ORDER_TYPE_SELL type_filling:ORDER_FILLING_FOK type_time:ORDER_TIME_GTC expiration… }

MqlTradeResult{  retcode:0 deal:0 order:0 volume:0 price:0 bid:0 ask:0 comment:NULL request_id:0 reserved:[128] }


Does Anyone know what Im doing wrong here - Im new to MT4 and MT5?


You are using ORDER_FILLING_FOK where it's not allowed apparently. But it's only seeing your code, we can be sure.
robertbaptie
13
robertbaptie  

OK - I got it to execute by using ORDER_FILLING_IOC in place of ORDER_FILLING_FOK

Can I ask how did you know that was the problem is that a known issue/experiece or did you see something in what I posted to indicate that?


I also moved the

ZeroMemory(mRequest);               
ZeroMemory(mResult); 


If anyone else reads the post!


Many Thanks

Alain Verleyen
Moderator
31193
Alain Verleyen  
robertbaptie:

OK - I got it to execute by using ORDER_FILLING_IOC in place of ORDER_FILLING_FOK

Can I ask how did you know that was the problem is that a known issue/experiece or did you see something in what I posted to indicate that?


I also moved the


If anyone else reads the post!


Many Thanks

Your log reported :

failed market sell 0.01 EURUSD sl: 1.35770 tp: 1.35570 [Unsupported filling mode]

and you show the content of your MqlTradeRequest with ORDER_FILLING_FOK. So, with my little experience

Rogerio Figurelli
Moderator
40356
Rogerio Figurelli  
robertbaptie:

OK - I got it to execute by using ORDER_FILLING_IOC in place of ORDER_FILLING_FOK

Can I ask how did you know that was the problem is that a known issue/experiece or did you see something in what I posted to indicate that?


I also moved the


If anyone else reads the post!


Many Thanks

Hi robertbaptie, as you changed your filling mode, take care about your result processing (mResult.retcode), since now you can have partial deal volume filling, for instance:

10010

TRADE_RETCODE_DONE_PARTIAL

Only part of the request was completed

Alain Verleyen
Moderator
31193
Alain Verleyen  
figurelli:

Hi robertbaptie, as you changed your filling mode, take care about your result processing (mResult.retcode), since now you can have partial deal volume filling, for instance:

10010

TRADE_RETCODE_DONE_PARTIAL

Only part of the request was completed

Rogerio Figurelli
Moderator
40356
Rogerio Figurelli  
angevoyageur:
:-)
To add comments, please log in or register