OrderSend wrong parameters count

 



//CAN SOMEONE ASSIST ME TO SOLVE THIS   ORDERSEND WRONG PARAMETERS COUNT//


#include <Trade/Trade.mqh> // include Trade library for OrderSend function

#define OP_BUY 0
#define Ask SymbolInfoDouble(NULL, SYMBOL_ASK)

input double TradeSize = 1.0; // input parameter for trade size
input double StopLoss = 20.0; // input parameter for stop loss level
input double TakeProfit = 40.0; // input parameter for take profit level

int TradeTicket; // variable to store trade ticket
int TradeResult; // variable to store trade result

// function to open a trade
void OpenTrade()
{
  // open a trade with the specified parameters
  TradeResult = OrderSend(NULL, OP_BUY, TradeSize, Ask, 3, StopLoss, TakeProfit, "My EA", 0, 0, clrRed);

  // check if the trade was successful
  if (TradeResult > 0)
  {
    // store the trade ticket
    TradeTicket = TradeResult;
  }
}

// main function to run the EA
void OnTick()
{
  // get the current time and the number of bars on the current chart
  datetime CurrentTime = TimeCurrent();
  int BarsOnChart = Bars(NULL, PERIOD_CURRENT);

  // calculate the time remaining for the current candle to close
  datetime TimeRemaining = TimeCurrent() - iClose(NULL, PERIOD_CURRENT, BarsOnChart - 1);

  // check if the time remaining is 5 minutes or less
  if (TimeRemaining <= 5 * 60)
  {
    // open a trade if the condition is met
    OpenTrade();
  }
}
 
28846173:

I am assuming this is supposed to be MQL5 code - in which case I suggest you read the documentation on the MT5 version of the OrderSend function as it is nothing like the MT4 version you have used here.

#include <Trade/Trade.mqh> // include Trade library for OrderSend function

this line currently does nothing, it would only be useful if you are using the Standard Library Trade Classes. Once again see the MQL5 documentation.

 

You are mixing MQL5 and MQL4 code! Which one is it — 4 or 5?

  1. "Trade.mqh" is part of the MQL5 Standard Library, but it is NOT necessary for using OrderSend.
  2. The OrderSend function is present in both MQL4 and MQL5, but its use and parameters are completely different:
    for MQL5 — Documentation on MQL5: Trade Functions / OrderSend
    for MQL4 — OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
OrderSend - Trade Functions - MQL4 Reference
 
Fernando Carreiro #:

You are mixing MQL5 and MQL4 code! Which one is it — 4 or 5?

  1. "Trade.mqh" is part of the MQL5 Standard Library, but it is NOT necessary for using OrderSend.
  2. The OrderSend function is present in both MQL4 and MQL5, but its use and parameters are completely different:
    for MQL5 — Documentation on MQL5: Trade Functions / OrderSend
    for MQL4 — OrderSend - Trade Functions - MQL4 Reference

mt5

 
28846173 #: mt5

If you are using MT5, then you have two options ...

  • an object oriented programming approach by using the Trade Classes of the MQL5 Standard Library.
  • a imperative procedural programming approach by using the MQL5 version of OrderSend.
It is best not to mix the two types unless you fully understand both well.
 
Fernando Carreiro #:

If you are using MT5, then you have two options ...

  • an object oriented programming approach by using the Trade Classes of the MQL5 Standard Library.
  • a imperative procedural programming approach by using the MQL5 version of OrderSend.
It is best not to mix the two types unless you fully understand both well.

thanks guys

 
28846173 #: thanks guys
You are welcome!
 

HI TEAM, i am facing almost the same challenge, I'm using MT5 platform, kindly assist.

1) 'OP_SELL' - undeclared identifier

2) 'OrderSend' - wrong parameters count -    built-in: bool OrderSend(const MqlTradeRequest&,MqlTradeResult&)


input double LotSize = 0.2;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   Print("Arif EA initiated");
   return(INIT_SUCCEEDED);
  }

//+------------------------------------------------------------------+
//| Expert tick function                                            |
//+------------------------------------------------------------------+
void OnTick()
  {
   double entryPrice = SymbolInfoDouble(_Symbol, SYMBOL_ASK);
   double takeProfit = entryPrice - 90 * _Point;
   double stopLoss = entryPrice + 9 * _Point;
   
   // Open a sell order
   ulong ticket = OrderSend(_Symbol, OP_SELL, LotSize, entryPrice, 3, stopLoss, takeProfit, "Arif EA", 0, 0, clrRed);
   
   if(ticket > 0) // OrderSend successful
     {
      Print("Sell order opened successfully at price ", entryPrice);
     }
   else
     {
      Print("Error opening sell order. Error code: ", GetLastError());
     }
  }

 
Arif9696 #:


Post your code properly, use the code button. Edit your post, do not repost, please.


 

@Arif9696 Your code is for MT4 but seems you want to use it on MT5.

I strongly suggest to use CTrade  classes and their semplified commands, documentation always help. At the moment it seems you only declared it but not used.

https://www.mql5.com/en/docs/standardlibrary/tradeclasses/ctrade

Reason: