Failing upload to market

 

Hi 


My ea runs fine with zero errors on demo but fails uploading to market


I use 2 bools to check the correctness of volume and money for trade


I get different validation errors


If I start with 0.01 lot, the error is no trade operations but if I start with 1 lot, it opens trades but shows error not enough money 


Any help would be appreciated 

 
if(CheckVolumeValue(BuyLimit1_Lotsize)==true)
 if(CheckMoneyForTrade(Symbol(),BuyLimit1_Lotsize,OP_BUY)==true) 



bool CheckVolumeValue(double volume) {

//--- minimal allowed volume for trade operations
  double min_volume=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   if(volume < min_volume)
     {
      //description = StringFormat("Volume is less than the minimal allowed SYMBOL_VOLUME_MIN=%.2f",min_volume);
      return(false);
     }

//--- maximal allowed volume of trade operations
   double max_volume=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX);
   if(volume>max_volume)
     {
      //description = StringFormat("Volume is greater than the maximal allowed SYMBOL_VOLUME_MAX=%.2f",max_volume);
      return(false);
     }

//--- get minimal step of volume changing
   double volume_step=SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);

   int ratio = (int)MathRound(volume/volume_step);
   if(MathAbs(ratio*volume_step-volume)>0.0000001)
     {
      //description = StringFormat("Volume is not a multiple of the minimal step SYMBOL_VOLUME_STEP=%.2f, the closest correct volume is %.2f", volume_step,ratio*volume_step);
      return(false);
     }
      
   return(true);
}

bool CheckMoneyForTrade(string symb, double lots, int type) {

   double free_margin = AccountFreeMarginCheck(symb, type, lots);
   //-- if there is not enough money
   if(free_margin<0)
     {
      string oper=(type==OP_BUY)? "Buy":"Sell";
      Print("Not enough money for ", oper," ",lots, " ", symb, " Error code=",GetLastError());
      return(false);
     }
   //--- checking successful
   return(true);
}
 
Hi

If you use pending orders, you would have to check also if the lot size is correct while trade are in the market (not triggered yet) and the account size is changed. Because you can have money when you open pending order but when it’s later triggered the account can be changed already and you won’t have enough money to open this. So you should check if the pendings still have valid lot size and if not delete them before they can be triggered. This should help with this error.

Have a nice day👍📊

 
Marzena Maria Szmit #:
Hi

If you use pending orders, you would have to check also if the lot size is correct while trade are in the market (not triggered yet) and the account size is changed. Because you can have money when you open pending order but when it’s later triggered the account can be changed already and you won’t have enough money to open this. So you should check if the pendings still have valid lot size and if not delete them before they can be triggered. This should help with this error.

Have a nice day👍📊

Thank you Marzena. It makes sense. Greetings