Download MetaTrader 5

Returned value of ordersend check

To add comments, please log in or register
Ne
13
Ne  

Can anyone help me with this code as the warning is coming up as "Returned value of 'OrderSend' should be checked,


//+------------------------------------------------------------------+
//|                                                           MA.mq4 |
//|                                                          The One |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "The One"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int TakeProfit = 200;
extern int StopLoss = 50;
extern int FastMa = 8;
extern int SlowMa = 21;
extern int RSI = 10;
extern int LotSize = 0.05;

int OnInit()
  {
//---
//---
  return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
  }
   
void OnTick()
  {
double PreviousSlowMA = iMA (NULL, 0, SlowMa, 0, MODE_EMA, PRICE_CLOSE, 2);
double CurrentSlowMA = iMA (NULL, 0, SlowMa, 0, MODE_EMA, PRICE_CLOSE, 1);
double PreviousFastMA = iMA (NULL, 0, FastMa, 0, MODE_EMA, PRICE_CLOSE, 2);
double CurrentFastMA = iMA (NULL, 0, FastMa, 0, MODE_EMA, PRICE_CLOSE, 1);
double PreviousRSI = iRSI (NULL, 0, RSI, PRICE_MEDIAN, 2);
double CurrentRSI = iRSI (NULL, 0, RSI, PRICE_MEDIAN, 1);

if(PreviousFastMA < PreviousSlowMA && CurrentFastMA > CurrentSlowMA)
{
if(PreviousRSI < 50.0 && CurrentRSI > 50.00)
{
OrderSend(Symbol(), OP_BUY, LotSize, Ask, 5, Ask-(StopLoss*Point), Ask + (TakeProfit*Point), NULL);
}}


if(PreviousFastMA > PreviousSlowMA && CurrentFastMA < CurrentSlowMA)
{
if(PreviousRSI > 50.0 && CurrentRSI < 50.00)
{
OrderSend(Symbol(), OP_SELL, LotSize, Bid, 5, Bid + (StopLoss*Point), Bid-(TakeProfit*Point), NULL);
}}

  }
//-----------------------------------------------------------+   
Keith Watford
Moderator
10651
Keith Watford  

OrderSend from the documentation

Returned value

Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function.

   int ticket=OrderSend(Symbol(),OP_BUY,1,price,3,stoploss,takeprofit,"My order",16384,0,clrGreen); 
   if(ticket<0) 
     { 
      Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully"); 


To add comments, please log in or register