本文整理汇总了Java中eu.verdelhan.ta4j.indicators.trackers.MACDIndicator类的典型用法代码示例。如果您正苦于以下问题:Java MACDIndicator类的具体用法?Java MACDIndicator怎么用?Java MACDIndicator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MACDIndicator类属于eu.verdelhan.ta4j.indicators.trackers包,在下文中一共展示了MACDIndicator类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildStrategy
import eu.verdelhan.ta4j.indicators.trackers.MACDIndicator; //导入依赖的package包/类
/**
* @param series a time series
* @return a moving momentum strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
// The bias is bullish when the shorter-moving average moves above the longer moving average.
// The bias is bearish when the shorter-moving average moves below the longer moving average.
EMAIndicator shortEma = new EMAIndicator(closePrice, 9);
EMAIndicator longEma = new EMAIndicator(closePrice, 26);
StochasticOscillatorKIndicator stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);
MACDIndicator macd = new MACDIndicator(closePrice, 9, 26);
EMAIndicator emaMacd = new EMAIndicator(macd, 18);
// Entry rule
Rule entryRule = new OverIndicatorRule(shortEma, longEma) // Trend
.and(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20))) // Signal 1
.and(new OverIndicatorRule(macd, emaMacd)); // Signal 2
// Exit rule
Rule exitRule = new UnderIndicatorRule(shortEma, longEma) // Trend
.and(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80))) // Signal 1
.and(new UnderIndicatorRule(macd, emaMacd)); // Signal 2
return new Strategy(entryRule, exitRule);
}
示例2: buildStrategy
import eu.verdelhan.ta4j.indicators.trackers.MACDIndicator; //导入依赖的package包/类
/**
* Build the {@link eu.verdelhan.ta4j.Strategy Strategy} to use for
* trading and backtesting.
*
* @param series
* {@link eu.verdelhan.ta4j.TimeSeries TimeSeries} to use when building the {@link eu.verdelhan.ta4j.Strategy Strategy}
* @return the rules to build the
* {@link eu.verdelhan.ta4j.Strategy Strategy}.
*/
@Contract("null -> fail")
private static Tuple2<Rule, Rule> buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
SMAIndicator shortSma = new SMAIndicator(closePrice, SMA_SHORT_PERIODS);
SMAIndicator longSma = new SMAIndicator(closePrice, SMA_LONG_PERIODS);
CMOIndicator cmo = new CMOIndicator(series, CMO_PERIODS);
// The bias is bearish when the shorter-moving averagemoves below the
// longer moving average.
EMAIndicator shortEma = new EMAIndicator(closePrice, 9);
EMAIndicator longEma = new EMAIndicator(closePrice, 26);
StochasticOscillatorKIndicator stochasticOscillK = new
StochasticOscillatorKIndicator(series, 14);
MACDIndicator macd = new MACDIndicator(closePrice, MACD_SHORT_PERIODS,
MACD_LONG_PERIODS);
EMAIndicator emaMacd = new EMAIndicator(macd, 18);
Rule momentumEntry = new OverIndicatorRule(shortSma, longSma) // Trend
// Signal 1
.and(new CrossedDownIndicatorRule(cmo,
Decimal.valueOf(CMO_LOWER)))
// Signal 2
.and(new OverIndicatorRule(shortEma, closePrice));
// Entry rule
Rule entryRule = new OverIndicatorRule(shortEma, longEma) // Trend
// Signal 1
.and(new CrossedDownIndicatorRule(stochasticOscillK,
Decimal.valueOf(20)))
// Signal 2
.and(new OverIndicatorRule(macd, emaMacd))
.or(momentumEntry);
Rule momentumExit = new UnderIndicatorRule(shortSma, longSma) // Trend
// Signal 1
.and(new CrossedUpIndicatorRule(cmo,
Decimal.valueOf(CMO_UPPER)))
// Signal 2
.and(new UnderIndicatorRule(shortSma, closePrice));
// Exit rule
Rule exitRule = new UnderIndicatorRule(shortEma, longEma) // Trend
// Signal 1
.and(new CrossedUpIndicatorRule(stochasticOscillK,
Decimal.valueOf(80)))
// Signal 2
.and(new UnderIndicatorRule(macd, emaMacd))
.or(momentumExit)
// Protect against severe losses
.or(new StopLossRule(closePrice, Decimal.valueOf
(STOP_LOSS_THRESHOLD)))
// Take profits and run
.or(new StopGainRule(closePrice, Decimal.valueOf
(STOP_GAIN_THRESHOLD)));
return new Tuple2<>(entryRule, exitRule);
}
示例3: init
import eu.verdelhan.ta4j.indicators.trackers.MACDIndicator; //导入依赖的package包/类
@Override
protected void init() {
validateTwo();
indicator = new MACDIndicator(closePriceIndicator, instance.getTimeframe1(), instance.getTimeframe2());
}