MQL4 - automated forex trading   /  

Forum

error 134

Back to topics list To post a new topic, please log in or register

avatar
2
karmela 2008.05.07 23:49 

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

article

Report: The Championship Started

The Automated Trading Championship 2006 started two days ago. 258 Expert Advisors are now competing for prizes. Unfortunately, not everything went like clockwork.


avatar
Moderator
5089
stringo 2008.05.08 11:27 

avatar
2
karmela 2008.05.08 18:34 

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 ?


avatar
Moderator
5089
stringo 2008.05.12 12:10 

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);
  }

Back to topics list  

To add comments, please log in or register