Download MetaTrader 5
To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
siddesh
207
siddesh 2010.11.11 08:37 
Please any one give an example to check the trade request before sending with the function OrderCheck().
Rashid Umarov
Admin
11560
Rashid Umarov 2010.11.11 08:52  

From class CTrade:

bool CTrade::PositionOpen(const string symbol,ENUM_ORDER_TYPE order_type,double volume,
                          double price,double sl,double tp,const string comment)
  {
   string action,result;
//---
   ClearStructures();
//--- checking
   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;
   m_request.type_filling=m_type_filling;
   m_request.comment     =comment;
//--- order check
   if(!OrderCheck(m_request,m_check_result))
     {
      m_result.retcode=m_check_result.retcode;
      printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
      //--- copy return code
      return(false);
     }
//--- order send
   if(!OrderSend(m_request,m_result))
     {
      printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
      return(false);
     }
   printf(__FUNCTION__+": %s [%s]",FormatRequest(action,m_request),FormatRequestResult(result,m_request,m_result));
//--- ok
   return(true);
  }

Rogerio Figurelli
Moderator
37577
Rogerio Figurelli 2011.08.10 18:47  

Remember also to declare independent check structures, as bellow for the nice Rosh example:


MqlTradeRequest m_request;
MqlTradeResult m_result;
MqlTradeCheckResult m_check_result;

/
To add comments, please log in or register