MQL4 to MQL5

Alain Verleyen  
Migrating from MQL4 to MQL5
Migrating from MQL4 to MQL5
  • 2010.05.17
  • Sergey Pavlov
  • 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.
johnnybegoode77  
Alain Verleyen:
See these articles : Orders, Positions and Deals in MetaTrader 5


//********************************************  Emulation *******************************************

//--- Declaration of constants
#define OP_BUY 0           //Buy
#define OP_SELL 1          //Sell
#define OP_BUYLIMIT 2      //Pending order of BUY LIMIT type
#define OP_SELLLIMIT 3     //Pending order of SELL LIMIT type
#define OP_BUYSTOP 4       //Pending order of BUY STOP type
#define OP_SELLSTOP 5      //Pending order of SELL STOP type


Still get

Error: 'OrderSend' - wrong parameters count  

for

int ticket=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,0,"My EA",12345,0,Green);


What did I missed in the Emulation?

Dimitr Trifonov  

Please check https://www.mql5.com/en/docs/trading/ordersend

There's an example of opening a random pending order using OrderSend(), as you see the structure of 'mql5 OrderSend()' is not the same as 'mql4 OrderSend()'

//+------------------------------------------------------------------+ 
//| Sets a pending order in a random way                             | 
//+------------------------------------------------------------------+ 
uint SendRandomPendingOrder(long const magic_number) 
  { 
//--- prepare a request 
   MqlTradeRequest request={0}; 
   request.action=TRADE_ACTION_PENDING;         // setting a pending order 
   request.magic=magic_number;                  // ORDER_MAGIC 
   request.symbol=_Symbol;                      // symbol 
   request.volume=0.1;                          // volume in 0.1 lots 
   request.sl=0;                                // Stop Loss is not specified 
   request.tp=0;                                // Take Profit is not specified      
//--- form the order type 
   request.type=GetRandomType();                // order type 
//--- form the price for the pending order 
   request.price=GetRandomPrice(request.type);  // open price 
//--- send a trade request 
   MqlTradeResult result={0}; 
   OrderSend(request,result); 
//--- write the server reply to log   
   Print(__FUNCTION__,":",result.comment); 
   if(result.retcode==10016) Print(result.bid,result.ask,result.price); 
//--- return code of the trade server reply 
   return result.retcode; 
  } 
Documentation on MQL5: Trade Functions / OrderSend
Documentation on MQL5: Trade Functions / OrderSend
  • www.mql5.com
Trade Functions / OrderSend - Reference on algorithmic/automated trading language for MetaTrader 5
johnnybegoode77  
Dimitr Trifonov:

Please check https://www.mql5.com/en/docs/trading/ordersend

There's an example of opening a random pending order using OrderSend(), as you see the structure of 'mql5 OrderSend()' is not the same as 'mql4 OrderSend()'

how do i rewrite

int ticket=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,0,"My EA",12345,0,Green);

in mql5?

johnnybegoode77  
johnnybegoode77:

how do i rewrite

int ticket=OrderSend("EURUSD",OP_BUY,Lots,Ask,3,0,0,"My EA",12345,0,Green);

in mql5?



Do you have a universal emulation scripts?

(Those that could cut and paste?)

Thank you!

JEEBSOFT  

1) asking1 =SymbolInfoDouble( "GBPUSD" , SYMBOL_ASK ));


2) #define Ask (SymbolInfoDouble(_Symbol, SYMBOL_ASK))

ulong ticket=OrderSend( "EURUSD" ,ORDER_TYPE_BUY, Lots,Ask,3,0,0,"My EA",12345,0,Green) );

ulong  OrderSend(string Symb,const ENUM_ORDER_TYPE order_type,double volume,double price,ulong Slippage,double SL,double TP,string comment=NULL,int Magic=0,

   datetime expiration=0,color arrow_color=clrNONE )
   {
       MqlTradeRequest Request;MqlTradeResult Result;ZeroMemory(Request);
       const int curDigits=(int)SymbolInfoInteger(Request.symbol,SYMBOL_DIGITS);
       if(SL>0){ SL=NormalizeDouble(SL,curDigits);}
       if(TP>0){TP=NormalizeDouble(TP,curDigits);}
       if(price>0){price=NormalizeDouble(price,curDigits);} else {Print("---- ERROR PRICE ZERO IN ORDER SEND -----");return(-1);}//price=SymbolInfoDouble(Symbol(),SYMBOL_ASK);}
      
       if(order_type==ORDER_TYPE_BUY || order_type==ORDER_TYPE_SELL ){
       Request.action=TRADE_ACTION_DEAL;
       Request.magic = Magic;
       Request.symbol = ((Symb == NULL) ? ::Symbol() : Symb);
       Request.volume = volume;
       Request.price=price;
       Request.tp = TP;
       Request.sl = SL;
       Request.deviation=Slippage;
       Request.type=order_type;
       Request.type_filling=ORDER_FILLING_IOC;
       if(expiration>0)
        {
         Request.type_time=ORDER_TIME_SPECIFIED;
         Request.expiration=expiration;
        }
        
       Request.comment=comment;
       if(OrderSend(Request,Result)){
         if(Result.retcode==10009 || Result.retcode==10008){return(Result.deal);} else{ Print("---- ERROR IN ORDER SEND -----");return(-1);}
       }
      
      }
    return(-1);
 }

Reason: