Download MetaTrader 5

return value of 'OrderSend' should be checked ?????

To add comments, please log in or register
Gouveiaa
123
Gouveiaa 2016.07.16 04:10 
void ShortPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(!PositionSelect(_Symbol))
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Bid,_Digits);     // Lastest Bid price
      mrequest.sl = StopLoss;                                   // Stop Loss
      mrequest.tp = TakeProfit;                                   // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type= ORDER_TYPE_SELL;                    // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=1;                              // Deviation from current price
     OrderSend(mrequest,mresult);                       // Send order
     
     }
  }



I know you probably know, so can anyone help me please? Best Regards 


Ernst Van Der Merwe
4789
Ernst Van Der Merwe 2016.07.16 15:44  

Make the function boolean so it can check if the order was executed successfully or not.

bool ShortPositionOpen()
  {
   MqlTradeRequest mrequest;                             // Will be used for trade requests
   MqlTradeResult mresult;                               // Will be used for results of trade requests
   
   ZeroMemory(mrequest);
   ZeroMemory(mresult);
   
   double Ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);    // Ask price
   double Bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);    // Bid price

   if(!PositionSelect(_Symbol))
     {
      mrequest.action = TRADE_ACTION_DEAL;               // Immediate order execution
      mrequest.price = NormalizeDouble(Bid,_Digits);     // Lastest Bid price
      mrequest.sl = StopLoss;                            // Stop Loss
      mrequest.tp = TakeProfit;                          // Take Profit
      mrequest.symbol = _Symbol;                         // Symbol
      mrequest.volume = Lot;                             // Number of lots to trade
      mrequest.magic = 0;                                // Magic Number
      mrequest.type= ORDER_TYPE_SELL;                    // Sell order
      mrequest.type_filling = ORDER_FILLING_FOK;         // Order execution type
      mrequest.deviation=1;                              // Deviation from current price
      return(OrderSend(mrequest,mresult));               // Send order
     }
   return(false);
  }
Gouveiaa
123
Gouveiaa 2016.07.16 17:11  
Ernst Van Der Merwe:

Make the function boolean so it can check if the order was executed successfully or not.

Thank you very much, it worked!

Best Regards 

Jose Francisco Casado Fernandez
2747
Jose Francisco Casado Fernandez 2016.07.23 23:49  
You could use MQL5\Include\Trade\Trade.mqh library. So, you would avoid this kind of mistakes. Regards.
To add comments, please log in or register