Create a new exponential moving average which smooths over the given number of periods. if (periods < 1) { System.out.println("ExponentialMovingAverage:: ERROR: bad periods: " + periods); } this.weight = 2 / (float)(1 + periods); this.prevEMA = 0;
if (periods < 1) { System.out.println("ExponentialMovingAverage:: ERROR: bad periods: " + periods); } this.weight = 2 / (float)(1 + periods); this.prevEMA = 0;
Create a new exponential moving average, using the given smoothing rate weight. if ((weight < 0.0) || (weight > 1.0)) { System.out.println("ExponentialMovingAverage:: ERROR: bad weight: " + weight); } this.weight = weight; this.prevEMA = 0;
if ((weight < 0.0) || (weight > 1.0)) { System.out.println("ExponentialMovingAverage:: ERROR: bad weight: " + weight); } this.weight = weight; this.prevEMA = 0;
Return average-so-far. return prevEMA;
return prevEMA;
this.prevEMA = 0;
Update average and return average-so-far. prevEMA = (weight * (newValue - prevEMA)) + prevEMA; return prevEMA;
prevEMA = (weight * (newValue - prevEMA)) + prevEMA; return prevEMA;