Search
Products
Community
Markets
News
Brokers
More
EN
Get started
Nifty 50 Index
Short
Jan 21, 2023
import java.util.ArrayList; public class MovingAverage { p
0
Grab this chart
Grab this chart
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();
}
}
vinugv4
Follow
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
.