Help with ordersend 4051 and 131 errors

 

Hi friends.

I developed an EA similar to Semi Martingale style. I am getting good results. I am trying to put this EA in the market.

Unfortunately, Ordersend always has errors 4051 and 131.

Please help me. How can I eliminate these errors.

Please check the codes and tell me what to do.

//===============1
  if(  buy_signal &&buy_order==0 && emirvarmi(Symbol(),Ask) == false &&(ask<buy_last_price || buy_last_price == 0) &&   last_signal < Time[1] ){
       dlot = (max_lot<NormalizeDouble(Lots*MathPow(Multipler,buy_counter),2) ? max_lot :NormalizeDouble(Lots*MathPow(Multipler,buy_counter),2) );
      order_id = OrderSend(symbol,OP_BUY,dlot,Ask,0,0,0,IntegerToString(buy_counter+1),magic,0,clrBlue);
       last_signal = Time[0];
      }
       
       if(  buy_order>=1    && (ask<buy_last_price || buy_last_price == 0)&&  emirvarmi(Symbol(),Ask) == false  && buy_last_price-Distance*10*Point>=Close[1]){
       dlot = (max_lot<NormalizeDouble(Lots*MathPow(Multipler,buy_counter),2) ? max_lot :NormalizeDouble(Lots*MathPow(Multipler,buy_counter),2) );
     order_id = OrderSend(symbol,OP_BUY,dlot,Ask,0,0,0,IntegerToString(buy_counter+1),magic,1,clrBlue);
    last_signal = Time[0];    }
    
    
    
    
    
 //==================2            
      if(  sell_signal && sell_order==0 &&  emirvarmi(Symbol(),Bid) == false && (bid>sell_last_price || sell_last_price== 0) && last_signal < Time[1]){
      dlot = (max_lot<NormalizeDouble(Lots*MathPow(Multipler,sell_counter),2) ? max_lot :NormalizeDouble(Lots*MathPow(Multipler,sell_counter),2) );
      order_id = OrderSend(symbol,OP_SELL,dlot,Bid,0,0,0,IntegerToString(sell_counter+1),magic,0,clrRed);
     last_signal = Time[0]; 
   }              
    
   if(A sell_order>=1 &&  (bid>sell_last_price || sell_last_price == 0)&& emirvarmi(Symbol(),Bid) == false && sell_last_price+Distance*10*Point<=Close[1] ){
      dlot = (max_lot<NormalizeDouble(Lots*MathPow(Multipler,sell_counter),2) ? max_lot :NormalizeDouble(Lots*MathPow(Multipler,sell_counter),2) );
      order_id = OrderSend(symbol,OP_SELL,dlot,Bid,0,0,0,IntegerToString(sell_counter+1),magic,1,clrRed);
       last_signal = Time[0];  }  
      
 

       
 GetLotSize();

Lot code here

void GetLotSize(){
 double eq,kol; 
         double eq1; 
        if(Lot>0  ) {
                
          int digits1 = 0;
    if(LOTSTEP <= 0.01){
        digits1 = 2;
         eq1=NormalizeDouble(Lot,digits1);  
        
         Lots=eq1;
         }  
    else if(LOTSTEP <= 0.1){
        digits1 = 1;
        eq1=NormalizeDouble(Lot,digits1);  
        
         Lots=eq1;
        }
    
        
         return;
        } else {
         eq = ( AccountBalance()*Start_Lot ) / Start_Money;
          
               
                int digits = 0;
    if(LOTSTEP <= 0.01)
        digits = 2;
    else if(LOTSTEP <= 0.1)
        digits = 1;
        
    kol = NormalizeDouble(eq, digits);
                  dLot=kol;
               
                if(dLot<=MINLOT)    dLot=MINLOT; 
                
                if(dLot>=MAXLOT) dLot=MAXLOT;

                Lots=dLot;
        }
        if(Lots>MAXLOT) Lots=MAXLOT;

  
   
  

}
 
Topics concerning MT4 and MQL4 have their own section.
In future please post in the correct section.
I will move your topic to the MQL4 and Metatrader 4 section.
Reason: