OrderClose error 4051

 
{
      int OSS,OTS;
      bool OCS;
      OSS=OrderSelect(NULL,SELECT_BY_POS,MODE_TRADES);
      OTS=OrderType();
      if(CC1>iMA(NULL,0,48,0,MODE_LWMA,PRICE_HIGH,1))
      if(OTS==OP_SELL)
      {
      OCS=OrderClose(OrderTicket(),OrderLots(),Ask,3,clrRed)&&PlaySound ("alert2.wav");
      }
}
{
      int OSL,OTL;
      bool OCL;
      OSL=OrderSelect(NULL,SELECT_BY_POS,MODE_TRADES);
      OTL=OrderType();
      if(CC1<iMA(NULL,0,48,0,MODE_LWMA,PRICE_LOW,1))
      if(OTL==OP_BUY)
      {
      OCL=OrderClose(OrderTicket(),OrderLots(),Bid,3,clrRed)&&PlaySound ("alert2.wav");
      }
}

 OrderClose error 4051

Hi Again!

The EA works in testing and on real chart, it does closes the order but still getting this error.

What i'm doing wrong here please help and thanks

 
 OSS=OrderSelect(NULL,SELECT_BY_POS,MODE_TRADES);

 What does NULL equate to? That is probably the incorrect parameter

 
pieronetto:

 OrderClose error 4051

Hi Again!

The EA works in testing and on real chart, it does closes the order but still getting this error.

What i'm doing wrong here please help and thanks

Hey pieronetto please try to ask questions here where you cannot find the answer yourself!

1) Error 4051 means: "Invalid function parameter value" (Just a little look in the reference!!)

2) Then you have to find out why what function has wrong values:

   a) First look at your code and control the variables and their assignments and then

   b) (if necessary) print all values of the function and compare what you see with the requirements you find in the reference.

D-

 
pieronetto: OrderClose error 4051
OSS=OrderSelect(NULL,SELECT_BY_POS,MODE_TRADES);
  1. NULL is not an integer position.
  2. Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Reason: