本文整理汇总了Java中org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator类的典型用法代码示例。如果您正苦于以下问题:Java BollingerBandsMiddleIndicator类的具体用法?Java BollingerBandsMiddleIndicator怎么用?Java BollingerBandsMiddleIndicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BollingerBandsMiddleIndicator类属于org.ta4j.core.indicators.bollinger包,在下文中一共展示了BollingerBandsMiddleIndicator类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator; //导入依赖的package包/类
public static void main(String[] args) {
/**
* Getting time series
*/
TimeSeries series = CsvTicksLoader.loadAppleIncSeries();
/**
* Creating indicators
*/
// Close price
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
EMAIndicator avg14 = new EMAIndicator(closePrice, 14);
StandardDeviationIndicator sd14 = new StandardDeviationIndicator(closePrice, 14);
// Bollinger bands
BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(avg14);
BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, sd14);
BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, sd14);
/**
* Building chart dataset
*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));
/**
* Creating the chart
*/
JFreeChart chart = ChartFactory.createTimeSeriesChart(
"Apple Inc. 2013 Close Prices", // title
"Date", // x-axis label
"Price Per Unit", // y-axis label
dataset, // data
true, // create legend?
true, // generate tooltips?
false // generate URLs?
);
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("yyyy-MM-dd"));
/**
* Displaying the chart
*/
displayChart(chart);
}
示例2: getStrategy
import org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator; //导入依赖的package包/类
public Strategy getStrategy() {
final ClosePriceIndicator closePrice = new ClosePriceIndicator(timeSeries);
final SMAIndicator sma = new SMAIndicator(closePrice, bbPeriod);
final BollingerBandsMiddleIndicator bbmiddle = new BollingerBandsMiddleIndicator(sma);
final StandardDeviationIndicator sd = new StandardDeviationIndicator(closePrice, bbPeriod);
final BollingerBandsUpperIndicator bbup = new BollingerBandsUpperIndicator(bbmiddle, sd, Decimal.valueOf(deviationUp));
final BollingerBandsUpperIndicator bbdown = new BollingerBandsUpperIndicator(bbmiddle, sd, Decimal.valueOf(deviationDown));
final Rule buyingRule = new UnderIndicatorRule(closePrice, bbdown);
final Rule sellingRule = new OverIndicatorRule(closePrice, bbup).or(new StopLossRule(closePrice, Decimal.valueOf(2)));
final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
return strategy;
}