Search
Products
Community
Markets
News
Brokers
More
IN
Get started
Community
/
Ideas
/
import java.util.ArrayList; public class MovingAverage { p
Nifty 50 Index
Short
import java.util.ArrayList; public class MovingAverage { p
By vinugv4
Follow
Follow
Jan 21, 2023
0
Jan 21, 2023
import java.util.ArrayList;
public class MovingAverage {
private ArrayList<Double> data;
private int period;
public MovingAverage(int period) {
this.period = period;
this.data = new ArrayList<Double>();
}
public void addData(double value) {
this.data.add(value);
if (this.data.size() > this.period) {
this.data.remove(0);
}
}
public double calculate() {
double sum = 0;
for (double value : this.data) {
sum += value;
}
return sum / this.data.size();
}
}
Trend Analysis
vinugv4
Follow
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the
Terms of Use
.