Download MetaTrader 5

Average account balance

To add comments, please log in or register
cris224
17
cris224  

Hello,


Is there a way of calculating an average balance over the past lets say 100 trades. My EA adjusts the ammount of lots to be traded based on the current balance (AccountBalance()) and after a big win the number of lots traded increases quite a bit. I want to keep the lots being traded at an average level because few consecutive losses will erase the big win.


Thank you

double LotsOptimized()
{
  dLots=Lots;
   MinLots = MarketInfo(Symbol(), MODE_MINLOT);
   MaxLots = MarketInfo(Symbol(), MODE_MAXLOT);
   LotStep = MarketInfo(Symbol(), MODE_LOTSTEP);
      double StopLossPoint = 50;
      double RiskEquity = AccountBalance() * (PctToRisk/100);
      double eRiskEquity = AccountBalance() * (MaxPctToRisk/100);
      double PipValue = MarketInfo(Symbol(), MODE_TICKVALUE) * (pointvalue / MarketInfo(Symbol(), MODE_TICKSIZE));
      double eLots = eRiskEquity / (StopLossPoint * PipValue);
  if(MM){dLots = RiskEquity / (StopLossPoint * PipValue);}
  if(eLots < dLots){dLots = eLots;}  
  if (dLots < MinLots){dLots = MinLots;}
  dLots = MinLots + NormalizeDouble(((dLots - MinLots) / LotStep),0) * LotStep;
  if (dLots > MaxLots){dLots = MaxLots;}              
  dLots = MinLots + NormalizeDouble(((dLots - MinLots) / LotStep),0) * LotStep;  
  if (dLots < MinLots){dLots = MinLots;}                      
  return (dLots);
}
whroeder1
15934
whroeder1  
Compute the balances Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum then compute the average.
To add comments, please log in or register