Convert OrderSend() code from mql4 to mql5

 

I want to convert this code from mql4 to mql5. Please write the code for me.


OrderSend(Symbol(),OP_BUY,0.1,Ask,5,Ask-(50*Point),Ask+(TP*Point),"My Comment",00018,0,clrGreen);

 
Farhad1:

I want to convert this code from mql4 to mql5. Please write the code for me.


OrderSend(Symbol(),OP_BUY,0.1,Ask,5,Ask-(50*Point),Ask+(TP*Point),"My Comment",00018,0,clrGreen);

Buy

Opens a long position with specified parameters

Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
Documentation on MQL5: Standard Library / Trade Classes / CTrade / Buy
  • www.mql5.com
Buy(double,const string,double,double,double,const string) - CTrade - Trade Classes - Standard Library - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Vladimir Karputov:

Buy

Opens a long position with specified parameters

this function does not have a body
 
Farhad1 :
this  function does not have a body

You haven't even opened the help :)

bool  Buy(
   double        volume,          // position volume
   const string  symbol=NULL,     // symbol
   double        price=0.0,       // execution price
   double        sl=0.0,          // stop loss price
   double        tp=0.0,          // take profit price
   const string  comment=""       // comment
   )
 

Example

//+------------------------------------------------------------------+
//|                                Buy Short code and  Full code.mq5 |
//|                              Copyright © 2020, Vladimir Karputov |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2020, Vladimir Karputov"
#property version   "1.00"
//---
#include <Trade\Trade.mqh>
CTrade         m_trade;                      // trading object
//---
#property script_show_inputs
//--- input parameters
input group             "Trading settings"
input uint     InpStopLoss          = 150;         // Stop Loss
input uint     InpTakeProfit        = 460;         // Take Profit
input group             "Additional features"
input ulong    InpDeviation         = 10;          // Deviation
input ulong    InpMagic             = 200;         // Magic number
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   m_trade.SetExpertMagicNumber(InpMagic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(Symbol());
   m_trade.SetDeviationInPoints(InpDeviation);
//--- Short code
   m_trade.Buy(0.01);
//--- Full code
   MqlTick last_tick;
   ResetLastError();
   if(SymbolInfoTick(Symbol(),last_tick))
     {
      Print(Symbol()," ",last_tick.time,": Bid = ",last_tick.bid," Ask = ",last_tick.ask);
     }
   else
     {
      Print("SymbolInfoTick() failed, error = ",GetLastError());
      return;
     }
//---
   double sl=(InpStopLoss==0)?0.0:last_tick.ask-InpStopLoss*Point();
   double tp=(InpTakeProfit==0)?0.0:last_tick.ask+InpTakeProfit*Point();
   m_trade.Buy(0.02,Symbol(),last_tick.ask,sl,tp,"Full code");
  }
//+------------------------------------------------------------------+


Result


 

THIS IS WORK PERFECTLY :

#define Bid (SymbolInfoDouble(_Symbol, SYMBOL_BID))
#define Ask (SymbolInfoDouble(_Symbol, SYMBOL_ASK))

ulong  OrderSendR(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(OrderSendAsync(Request,Result)){
         if(Result.retcode==10009 || Result.retcode==10008){return(Result.deal);} else{ Print("---- ERROR IN ORDER SEND -----");return(-1);}
       }
       
      }
    return(-1);
 }

ulong ticket=OrderSendR( "EURUSD" ,ORDER_TYPE_BUY, Lots,Ask,3,0,0,"My EA",12345,0,Green) );// CALL FUNCTION
 
jeebs #:

THIS IS WORK PERFECTLY :

It does not return the ticket. 

 
Laszlo Tormasi #:

It does not return the ticket. 

He used OrderSendASync. This means that no response is required. You should check execution result in OnTradeTransaction()

 
Ezatrimeo #: He used OrderSendASync. This means that no response is required. You should check execution result in OnTradeTransaction()
Laszlo Tormasi #: It does not return the ticket. 
You can change
OrderSendAsync(Request,Result)
to
OrderSend(Request,Result)
. But OrderSendASync is very FAST
 
if (OrderSend(Symbol, OrderType, LotSize, price, 0, 0, 0, "MT5 EezeOrder", 0, 0, CLR_NONE) == -1)

        {

kindely help me out to solve wrong parameter error

Reason: