My OrderSend function doesn't work

 

I am migrating from MQL4 to 5 and having a bump ride.

This order placement function I wrote isn't working.

I get this error message: '61059710': failed market buy 0.01 BTCUSD [Unsupported filling mode]

Can someone please help me get it right?


void orderOpen(string action) {
   if (!AccountInfoInteger(ACCOUNT_TRADE_EXPERT))       {return;}

   #define EXPERT_MAGIC 12345678   // MagicNumber of the expert

   MqlTradeRequest request={};
   MqlTradeResult  result={};
   ZeroMemory(request);
   ZeroMemory(result);
   request.action   = TRADE_ACTION_DEAL;
   request.symbol   = Symbol();
   request.volume   = 0.01;
   if (action == "buy")    {request.type = ORDER_TYPE_BUY;}
   if (action == "sell")   {request.type = ORDER_TYPE_SELL;}
   request.price = SymbolInfoDouble(Symbol(),SYMBOL_ASK);
   request.deviation = 1;                                
   request.magic = EXPERT_MAGIC;                         
   if(OrderSend(request,result))        {
       orderTicket    = result.order;
       isTradeRunning = true;
       priceEnter     = result.price;
       //StopLoss     = OrderStopLoss(); //How do I get this in MQL5?
   }
   if (result.retcode == TRADE_RETCODE_PLACED)     {
       if (action == "buy")    {orderRunning = "buy";}
       if (action == "sell")   {orderRunning = "sell";}
   } else {Print("Last error on " + _Symbol + ": " + IntegerToString(GetLastError()));}
}
Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • www.mql5.com
This article is a quick guide to MQL4 language functions, it will help you to migrate your programs from MQL4 to MQL5. For each MQL4 function (except trading functions) the description and MQL5 implementation are presented, it allows you to reduce the conversion time significantly. For convenience, the MQL4 functions are divided into groups, similar to MQL4 Reference.
 
whoowl:

I am migrating from MQL4 to 5 and having a bump ride.

This order placement function I wrote isn't working.

I get this error message: '61059710': failed market buy 0.01 BTCUSD [Unsupported filling mode]

Can someone please help me get it right?


Why not to google before submitting a new topic?!


Btw Your code is not correct. Read the Documentation.

   if (action == "buy")  {request.type = ORDER_TYPE_BUY;   request.price = SymbolInfoDouble(Symbol(),SYMBOL_ASK);}
   if (action == "sell") {request.type = ORDER_TYPE_SELL;  request.price = SymbolInfoDouble(Symbol(),SYMBOL_BID);}


There are other successful retcodes

Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
Documentation on MQL5: Constants, Enumerations and Structures / Data Structures / Trade Request Structure
  • www.mql5.com
Trade Request Structure - Data Structures - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
whoowl:

I am migrating from MQL4 to 5 and having a bump ride.
This order placement function I wrote isn't working.
I get this error message: '61059710': failed market buy 0.01 BTCUSD [Unsupported filling mode] 

Can someone please help me get it right?


Hello,

you may use this way :

   ENUM_ORDER_TYPE_FILLING fillMode = (ENUM_ORDER_TYPE_FILLING)
                                      SymbolInfoInteger(_Symbol,SYMBOL_FILLING_MODE);
   fillMode-=1;

   ...
   request.type_filling=fillMode;
   ...

Kind regards.

 

My works:


   MqlTradeRequest Zlecenie;


   if(TypZlec=="K"){

      Zlecenie.action=TRADE_ACTION_DEAL;              // Trade operation type 

      Zlecenie.magic=0;                               // ulong Expert Advisor ID (magic number) 

      Zlecenie.order=0;                               // ulong Order ticket 

      Zlecenie.symbol=Symbol();                       // string Trade symbol 

      Zlecenie.volume=IleLotow;                       // double Requested volume in lots 

      Zlecenie.price=0;                               // double Price 

      Zlecenie.stoplimit=0;                           // double StopLimit level of the order 

      Zlecenie.sl=CenaSL;                             // double Stop Loss level of the order 

      Zlecenie.tp=CenaTP;                             // double Take Profit level of the order 

      Zlecenie.deviation=10;                          // ulong Max possible deviation in Points

      Zlecenie.type=ORDER_TYPE_BUY;                   // ENUM Order type

      Zlecenie.type_filling=ORDER_FILLING_FOK;        // ENUM Order execution type 

      Zlecenie.type_time=ORDER_TIME_GTC;              // ENUM Order expiration type

      Zlecenie.expiration=0;                          // datetime Order expiration time 

      Zlecenie.comment=Komentarz;                     // string Order comment 

      Zlecenie.position=0;                            // Position ticket

      Zlecenie.position_by=0;}                        // The ticket of an opposite position

   

   if(TypZlec=="S"){

      Zlecenie.action=TRADE_ACTION_DEAL;              // Trade operation type 

      Zlecenie.magic=0;                               // ulong Expert Advisor ID (magic number) 

      Zlecenie.order=0;                               // ulong Order ticket 

      Zlecenie.symbol=Symbol();                       // string Trade symbol 

      Zlecenie.volume=IleLotow;                       // double Requested volume in lots 

      Zlecenie.price=0;                               // double Price 

      Zlecenie.stoplimit=0;                           // double StopLimit level of the order 

      Zlecenie.sl=CenaSL;                             // double Stop Loss level of the order 

      Zlecenie.tp=CenaTP;                             // double Take Profit level of the order 

      Zlecenie.deviation=10;                          // ulong Max possible deviation in Points

      Zlecenie.type=ORDER_TYPE_SELL;                  // ENUM Order type

      Zlecenie.type_filling=ORDER_FILLING_FOK;        // ENUM Order execution type 

      Zlecenie.type_time=ORDER_TIME_GTC;              // ENUM Order expiration type

      Zlecenie.expiration=0;                          // datetime Order expiration time 

      Zlecenie.comment=Komentarz;                     // string Order comment 

      Zlecenie.position=0;                            // Position ticket

      Zlecenie.position_by=0;}                        // The ticket of an opposite position

      

   MqlTradeResult Zwrot;

      Zwrot.retcode=0;           // uint Operation return code 

      Zwrot.deal=0;              // ulong Deal ticket, if it is performed 

      Zwrot.order=0;             // ulong Order ticket, if it is placed 

      Zwrot.volume=0;            // double Deal volume, confirmed by broker 

      Zwrot.price=0;             // double Deal price, confirmed by broker 

      Zwrot.bid=0;               // double Current Bid price 

      Zwrot.ask=0;               // double Current Ask price 

      Zwrot.comment="";          // string Broker comment to operation (dft. server return code) 

      Zwrot.request_id=0;        // uint Request ID set by the terminal during the dispatch

      Zwrot.retcode_external=0;  // Return code of an external trading system 


   Wynik=OrderSend(Zlecenie,Zwrot);

   OdpSerw=Zwrot.retcode;


   if(Wynik==true){

      if(OdpSerw==TRADE_RETCODE_DONE){

         ObjectDelete(0,"sl");

         MessageBox(Komentarz,NULL,MB_ICONASTERISK);

         return;}}

Reason: