# Average account balance

17

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

Compute the balances Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum then compute the average.