error 134

 

Hi, I'm new to metadrader so excuse my language.

My problem is, when I test an EA, some trades are made but not all of them as I often get the error 134 "not enough money". I've read somewhere and think that my problem comes from that the lots are in EUR while my balance is in USD so the margin calculation is not good or something. Could you please help and tell me what I have to edit in the script ?



Thanks

 

I'm sorry but once again I'm a very young beginner at mql4 (and also english is not my first language to complicate things even more) so could you please explain what I have to do with the scripts you posted above. Which one should I copy/paste and where in the script ?

 

Just use CalculateVolume function from first link as is

//--- extern variables
extern double ExtMaximumRisk=0.05;             // 5% by default

//--- calculate current volume
double CalculateVolume()
  {
   double lot_min =MarketInfo(Symbol(),MODE_MINLOT);
   double lot_max =MarketInfo(Symbol(),MODE_MAXLOT);
   double lot_step=MarketInfo(Symbol(),MODE_LOTSTEP);
   double contract=MarketInfo(Symbol(),MODE_LOTSIZE);
   double vol;
//--- check data
   if(lot_min<0 || lot_max<=0.0 || lot_step<=0.0) 
     {
      Print("CalculateVolume: invalid MarketInfo() results [",lot_min,",",lot_max,",",lot_step,"]");
      return(0);
     }
   if(AccountLeverage()<=0)
     {
      Print("CalculateVolume: invalid AccountLeverage() [",AccountLeverage(),"]");
      return(0);
     }
//--- basic formula
   vol=NormalizeDouble(AccountFreeMargin()*ExtMaximumRisk*AccountLeverage()/contract,2);
//--- additional calculation
//   ...
//--- check min, max and step
   vol=NormalizeDouble(vol/lot_step,0)*lot_step;
   if(vol<lot_min) vol=lot_min;
   if(vol>lot_max) vol=lot_max;
//---
   return(vol);
  }
Reason: