How to create a pending order

 

Hello everyone, I am making my own robot according to my strategy.

Do I want to know how to make the bot make a pending order? What is the function?

Greetings.

 
Alfredo García :

Hello everyone, I am making my own robot according to my strategy.

Do I want to know how to make the bot make a pending order ? What is the function?

Greetings.

It is convenient to place a pending order using the trading class CTrade (this trading class is included in the standard delivery of the MetaTrader 5 terminal).

Example for placing a pending Buy stop order. This is an example script (this is not an adviser):

1.Check Volume Value 

2. Place Buy Stop

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   if(!m_symbol.Name(Symbol())) // sets symbol name
      return;
   if(!RefreshRates())
      return;

   string err_text="";
   if(!CheckVolumeValue(InpLots,err_text))
     {
      Print(err_text);
      return;
     }
//---
   m_trade.SetExpertMagicNumber(m_magic);
   m_trade.SetMarginMode();
   m_trade.SetTypeFillingBySymbol(m_symbol.Name());
   m_trade.SetDeviationInPoints(m_slippage);
//--- start work
   bool buy_stop=m_trade.BuyStop(InpLots,m_symbol.NormalizePrice(InpPrice),m_symbol.Name());
   uint result_retcode=m_trade.ResultRetcode();
   string result_retcode_description=m_trade.ResultRetcodeDescription();
   Print("Buy stop: ",buy_stop,", Result Retcode: ",result_retcode);
   Print("Result retcode description: ",result_retcode_description);
  }
Documentation on MQL5: Standard Library / Trade Classes / CTrade
Documentation on MQL5: Standard Library / Trade Classes / CTrade
  • www.mql5.com
Standard Library / Trade Classes / CTrade - Reference on algorithmic/automated trading language for MetaTrader 5