Order send error 2

 

I am using the same code with two brokers, one broker things are working fine,

but with other brokers, it places 2 or 3 orders and then this error comes up Order send error 2


This is the function i use for defining lots , Ordersend, can any one figure it out please

double GetLots()
  {
  
  if (check()==false){ExpertRemove();}
   double lot;
   double minlot=NormalizeDouble(MarketInfo(Symbol(),MODE_MINLOT),2);
   double maxlot=NormalizeDouble(MarketInfo(Symbol(),MODE_MAXLOT),2);
   if(risk!=0)
     {
      lot=NormalizeDouble(AccountBalance()*risk/100/1000,2);
      //lot = NormalizeDouble(0.25*AccountFreeMargin() / MarketInfo(Symbol(),MODE_MARGINREQUIRED),2);
      
      //lot=NormalizeDouble(AccountBalance()*risk/100/10000,2);
      if(lot<minlot)
         lot=minlot;
      if(lot>maxlot)
         lot=maxlot;
     }
   else
      lot=LOTS;
   return(lot);
  }




      if((TTL_Buy+TTL_Sell)<Max_Orders && TradingHours()==true)
        {
        //Print("Max Order - ArrowUp: "+ArrowUp+", ArrowDown: "+ArrowDown+", Time: "+TimeToStr(Time[1])); 
        if(AccountFreeMarginCheck(Symbol(),OP_BUY,GetLots())>0 )
          {
          if (check()==false){ExpertRemove();}
          if (comment==true) {comm="";}else{comm=NamaEA;}    
          if (Time[0] != lastOrderSend) 
             {
             //Print("Buy - TrendUp: "+ArrowUp+", TrendDown: "+ArrowDown+", Time: "+TimeToStr(Time[1])); 
             if (buy == true) //2147483647    
                {  
                ticket=OrderSend(Symbol(),OP_BUY,GetLots(),Ask,Slippage,0,0,comm,MagicID,0,clrGreen);
                if (ticket < 0) Print("Order Failed with "+ GetLastError());
                //Print("ArrowUp: "+ArrowUp+", Time: "+TimeToStr(Time[1]));
                    //CloseSell();
                  
                }
             if (sell == true)//2147483647
                {
                
                ticket=OrderSend(Symbol(),OP_SELL,GetLots(),Bid,Slippage,0,0,comm,MagicID,0,clrGreen);
                if (ticket < 0) Print("Order Failed with "+ GetLastError());
                   //Print(" ArrowDown: "+ArrowDown+", Time: "+TimeToStr(Time[1]));
                   // CloseBuy();
                }
             lastOrderSend = Time[0]; // Send no more this bar
             }
           }
        }
 
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
 
Keith Watford:
In future please post in the correct section
I will move your topic to the MQL4 and Metatrader 4 section.
Ok
 
Vijay Akash T P:

I am using the same code with two brokers, one broker things are working fine,

but with other brokers, it places 2 or 3 orders and then this error comes up Order send error 2


This is the function i use for defining lots , Ordersend, can any one figure it out please


I would suggest that in the event of an error you print out all the variables in the order to ensure that they meet the symbol specification, for price and lots.

Most likely you are presenting an invalid price or lot size. Difficult to tell unless you print out the values.

regards

 
Paul Anscombe:


I would suggest that in the event of an error you print out all the variables in the order to ensure that they meet the symbol specification, for price and lots.

Most likely you are presenting an invalid price or lot size. Difficult to tell unless you print out the values.

regards

Ok