Thread: MQL4 Guide
View Single Post
  #15 (permalink)  
Old 01-24-2008, 08:18 PM
RickD's Avatar
RickD RickD is offline
Member
 
Join Date: Jan 2006
Location: Eastern Europe
Posts: 52
RickD is on a distinguished road
Quote:
Originally Posted by golden188
Could someone please help me with some language to make my Expert Advisor trade a percentage of my balance? For example, I would like each trade, instead of being x number of lots, to be 10% of my current balance. Does anyone know how to do this? The more explicit the details the more helpful it would be.

thanks.
I suggest to use the following function:
Code:
extern double Lots = 0.1;
extern double MinLot = 0.1;
extern double MaxLot = 5.0;
extern int LotPrec = 1;
extern bool DynamicLot = false;
extern double LotStep = 0.1;
extern double BalanceStep = 500;
 
double GetLots() 
{
  double lots = Lots;
 
  if (DynamicLot)
  {
    lots = NormalizeDouble(LotStep*AccountBalance()/BalanceStep, LotPrec);  
  }
 
  lots = MathMax(lots, MinLot);
  lots = MathMin(lots, MaxLot);
  return (lots);
}
Reply With Quote