Normalization of the position size

People often ask (on forums or via instant messaging) why their EA doesn’t work. Then it becomes clear that their code doesn’t check if the position size calculated by its money management routine is allowed by the broker.

It is quite an easy task – you only need to pass the calculated value to the normalizing function such as this one:

double normalizeLots(double value)
  {
  double minLots=MarketInfo(Symbol(),MODE_MINLOT);
  double maxLots=MarketInfo(Symbol(),MODE_MAXLOT);

  if(value < minLots)
     value = minLots;

  if(value > maxLots)
     value = maxLots;

  int digits = 1;

  if(minLots == 0.01)
     digits = 2;
  if (minLots ==0.05)
  {
   return(NormalizeDouble(2*value,1)/2);
  }

  return(NormalizeDouble(value,digits));
}

The function will return the position size in the range allowed by the broker if the passed value exceeds this range.

 

Share with your friends:

Send us your comments

Name (required)

Email (required)

Message

  • Facebook