Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1453

 

I don't understand why ENUM_ORDER_TYPE and not ENUM_POSITION_TYPE in PositionOpen ?

//+------------------------------------------------------------------+
//| Open position                                                    |
//+------------------------------------------------------------------+
bool CTrade::PositionOpen(const string symbol,const ENUM_ORDER_TYPE order_type,const double volume,
                          const double price,const double sl,const double tp,const string comment)
  {
//--- check stopped
   if(IsStopped(__FUNCTION__))
      return(false);
//--- clean
   ClearStructures();
//--- check
   if(order_type!=ORDER_TYPE_BUY && order_type!=ORDER_TYPE_SELL)
     {
      m_result.retcode=TRADE_RETCODE_INVALID;
      m_result.comment="Invalid order type";
      return(false);
     }
//--- setting request
   m_request.action   =TRADE_ACTION_DEAL;
   m_request.symbol   =symbol;
   m_request.magic    =m_magic;
   m_request.volume   =volume;
   m_request.type     =order_type;
   m_request.price    =price;
   m_request.sl       =sl;
   m_request.tp       =tp;
   m_request.deviation=m_deviation;
//--- check order type
   if(!OrderTypeCheck(symbol))
      return(false);
//--- check filling
   if(!FillingCheck(symbol))
      return(false);
   m_request.comment=comment;
//--- action and return the result
   return(OrderSend(m_request,m_result));
  }
 
Mikhail Toptunov ENUM_POSITION_TYPE in PositionOpen ?

Because you cannot open a position.

You send a trade order to the broker's server to execute a trade.

A position is opened only if the trade has been executed.

The fact that the order has been successfully sent(10008) does not guarantee that a trade has been executed and therefore a position is opened(10009).


If you send a trade order (order) to execute a trade operation TRADE_ACTION_DEAL - i.e. to execute a trade at the current market price, any return code (m_result.retcode) other than 10009 will indicate that the trade has not been executed.

Just in case, check the m_result.deal ticket as well.

Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений / Коды возврата торгового сервера
Документация по MQL5: Константы, перечисления и структуры / Коды ошибок и предупреждений / Коды возврата торгового сервера
  • www.mql5.com
Коды возврата торгового сервера - Коды ошибок и предупреждений - Константы, перечисления и структуры - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Aleksandr Slavskii #:

If you send a trade order (order) to make a trade operation TRADE_ACTION_DEAL - that is, to make a trade at the current market price, then any return code (m_result.retcode) other than 10009 will indicate that the trade did not take place.

Alas, not quite so. I have already shown here how I got the code 10012, zero order ticket, but the order was executed. MQs are silent on this matter.

I wrote a crutch for it, but it will be possible to check it only after receiving 10012 again ).

 
JRandomTrader #:

Alas, not quite so. I have already shown here how I received code 10012, zero order ticket, but the order was executed. MQ are silent on this matter.

I wrote a crutch for it, but it will be possible to check it only after receiving 10012 again ).

Military business. ordered, received an answer as understood. received an answer as executed, received confirmation that they executed as ordered))))) Everything is human))))))

 
Valeriy Yastremskiy #:

military business. ordered, received an answer as understood. received an answer as executed, received confirmation that they executed as ordered))))) Everything is human)))))))))))))))))))))))))))))

And the next order can be given only tomorrow. Who needs such a trade?

 

gentlemen, ministers!)

How can I organise a check on an order or position that has been placed or executed.

If the code 10008 is received, how can I further track that the order is placed in the list of orders or positions?

In order to exclude the option that the code came, but the position or order is not there.

//-------------------------------------------------------------------+
void OnTrade()
  {
//--- Фиксируем если позиция открыта
   for(int i=0; i<ArraySize(position_buff); i++)
      if(position_buff[i].timeOp>1)
         if(!match_open_orders(position_buff[i].MagicNumber,position_buff[i].type,position_buff[i].comment)) // проверяю есть ли позиция
           {
            position_buff[i].timeOp= 0;     // Фиксировать время
            Print("Метод OnTrade() по рынку не выполнен. Код возврата=",m_trade.ResultRetcode(),
                  " (",m_trade.ResultRetcodeDescription(),")"+position_buff[i].comment+" lot "+DoubleToString(position_buff[i].lot));//
           }
         else
            Print("Метод OnTrade() по рынку выполнен успешно. Код возврата=",m_trade.ResultRetcode(),
                  " (",m_trade.ResultRetcodeDescription(),")"+position_buff[i].comment+" lot "+DoubleToString(position_buff[i].lot));//

  }
//--- Соответствие открытых ордеров ---------------------------------+
bool match_open_orders(long magic,int type,string comment)
  {
//---
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i))
        {
         long f= m_position.Magic();
         if(m_position.Comment()==comment)
            if(m_position.Type()==type)
               if(m_position.Magic()==magic)
                  return(true);
        }
   for(int i=OrdersTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i))
        {
         long f= m_position.Magic();
         if(m_position.Comment()==comment)
            if(m_position.Type()==type)
               if(m_position.Magic()==magic)
                  return(true);
        }
   return(false);
  }
 
Mikhail Toptunov executed order or position.

If the code 10008 is received, how can I further trace that exactly that order is placed in the list of orders or positions?

To exclude the option that the code came but the position or order is not there

Try using OnTradeTransaction () instead of OnTrade( ).

 

Does MetaTrader 5 work on Windows 7,8 ?

 
pivomoe #:

Does MetaTrader 5 work on Windows 7,8 ?

It works, but it is better to have a 64-bit OS

 
Mikhail Toptunov #:

Gentlemen, ministers!)

Twenty-five again.

   for(int i=OrdersTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i))
        {
         long f= m_position.Magic();
         if(m_position.Comment()==comment)
            if(m_position.Type()==type)
               if(m_position.Magic()==magic)
                  return(true);
        }

A mixture of horses, people....

What the hell is this?

We're asking for the number of open orders, but we're checking positions. That's not gonna work.
Reason: