Error #4051 Invalid Lots Amount for OrderSend Function

 

i am getting    a   Sell/buy Failed with Error #4051

Invalid lots amount for OrderSend function.   

i am still very new to coding  and i am trying to fix these errors,  but  the ea places the buy&sell trades just fine.  so i dont know what is wrong with the Ordersend line.  could someone please give me some Help.  


//+------------------------------------------------------------------+
void SELL(double ll,int m,double ssl)
  {
   if(ssl>0)
     {
      ssl=Bid+ssl*Point;
      if(shs)
         hsb=ssl;
     }
   if(ll>maxlot1 && en && m==mag1)
      ll=maxlot1;
   else if(ll>maxlot2 && en && m==mag2)
      ll=maxlot2;
   int sell=OrderSend(Symbol(),OP_SELL,ll,Bid,0,ssl,0,EA_Name,m,0,clrNONE);
   if(sell<0)
     {
      Print("sell failed with error #",GetLastError());
     }
   else
     {
      Print("sell placed successfully ",m);
     }
  }
////////////////////////////////////////
void BUY(double ll,int m,double ssl)
  {
   if(ssl>0)
     {
      ssl=Ask-ssl*Point;
      if(shb)
         hbb=ssl;
     }
   if(ll>maxlot1 && en && m==mag1)
      ll=maxlot1;
   else if(ll>maxlot2 && en && m==mag2)
      ll=maxlot2;
   int buy=OrderSend(Symbol(),OP_BUY,ll,Ask,0,ssl,0,EA_Name,m,0,clrNONE);
   if(buy<0)
     {
      Print("buy failed with error #",GetLastError());
     }
   else
     {
      Print("buy placed successfully ",m);
     }
  }
//+------------------------------------------------------------------+
 
Richard Louis Pastor:

i am getting    a   Sell/buy Failed with Error #4051

Invalid lots amount for OrderSend function.   

i am still very new to coding  and i am trying to fix these errors,  but  the ea places the buy&sell trades just fine.  so i dont know what is wrong with the Ordersend line.  could someone please give me some Help.  

Fix Line 375 To : 

int buy=OrderSend(Symbol(),OP_BUY,ll,Ask,0,ssl,0,EA_Name,m,0,clrNONE);
 
Ugochukwu Mobi #:

Fix Line 375 To : 

same error

 
  1.   int buy=OrderSend(Symbol(),OP_BUY,ll,Ask,0,ssl,0,EA_Name,m,0,clrNONE);

    Why did you post your MT4 question in the MT5 General section instead of the MQL4 section, (bottom of the Root page)?
              General rules and best pratices of the Forum. - General - MQL5 programming forum?
    Next time, post in the correct place. The moderators will likely move this thread there soon.

  2.       ssl=Ask-ssl*Point;

    You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit and open at the Ask.

    1. Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?

    2. Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close to a specific Bid price, add the average spread.
                MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25

    3. The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
      Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes. My GBPJPY shows average spread = 26 points, but average maximum spread = 134 (your broker will be similar).

  3. Richard Louis Pastor #:

    same error

    Use the debugger or print out your variables, including _LastError and prices and

    find out why. Do you really expect us to debug your code for you?
              Code debugging - Developing programs - MetaEditor Help
              Error Handling and Logging in MQL5 - MQL5 Articles (2015)
              Tracing, Debugging and Structural Analysis of Source Code - MQL5 Articles (2011)
              Introduction to MQL5: How to write simple Expert Advisor and Custom Indicator - MQL5 Articles (2010)

 
Richard Louis Pastor #:

same error

Read the error, Your Lot is too big as It is fixed value try to use 0.01 if it worked I will show you how to check Lots value before assigning it.
Try to change your codes to 

int sell=OrderSend(Symbol(),OP_SELL,0.01,Bid,0,ssl,0,EA_Name,m,0,clrNONE);

int buy=OrderSend(Symbol(),OP_BUY,0.01,Ask,0,ssl,0,EA_Name,m,0,clrNONE);