本文整理汇总了Java中eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule类的典型用法代码示例。如果您正苦于以下问题:Java UnderIndicatorRule类的具体用法?Java UnderIndicatorRule怎么用?Java UnderIndicatorRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UnderIndicatorRule类属于eu.verdelhan.ta4j.trading.rules包,在下文中一共展示了UnderIndicatorRule类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a CCI correction strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
CCIIndicator longCci = new CCIIndicator(series, 200);
CCIIndicator shortCci = new CCIIndicator(series, 5);
Decimal plus100 = Decimal.HUNDRED;
Decimal minus100 = Decimal.valueOf(-100);
Rule entryRule = new OverIndicatorRule(longCci, plus100) // Bull trend
.and(new UnderIndicatorRule(shortCci, minus100)); // Signal
Rule exitRule = new UnderIndicatorRule(longCci, minus100) // Bear trend
.and(new OverIndicatorRule(shortCci, plus100)); // Signal
Strategy strategy = new Strategy(entryRule, exitRule);
strategy.setUnstablePeriod(5);
return strategy;
}
示例2: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a global extrema strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrices = new ClosePriceIndicator(series);
// Getting the max price over the past week
MaxPriceIndicator maxPrices = new MaxPriceIndicator(series);
HighestValueIndicator weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK);
// Getting the min price over the past week
MinPriceIndicator minPrices = new MinPriceIndicator(series);
LowestValueIndicator weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK);
// Going long if the close price goes below the min price
MultiplierIndicator downWeek = new MultiplierIndicator(weekMinPrice, Decimal.valueOf("1.004"));
Rule buyingRule = new UnderIndicatorRule(closePrices, downWeek);
// Going short if the close price goes above the max price
MultiplierIndicator upWeek = new MultiplierIndicator(weekMaxPrice, Decimal.valueOf("0.996"));
Rule sellingRule = new OverIndicatorRule(closePrices, upWeek);
return new Strategy(buyingRule, sellingRule);
}
示例3: CCICorrectionStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
public CCICorrectionStrategy(TimeSeries series, ClosePriceIndicator closePriceIndicator) {
super(series, CCICorrectionStrategy.class.getSimpleName(), closePriceIndicator);
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
CCIIndicator longCci = new CCIIndicator(series, 200);
CCIIndicator shortCci = new CCIIndicator(series, 5);
Decimal plus100 = Decimal.HUNDRED;
Decimal minus100 = Decimal.valueOf(-100);
Rule entryRule = new OverIndicatorRule(longCci, plus100) // Bull trend
.and(new UnderIndicatorRule(shortCci, minus100)); // Signal
Rule exitRule = new UnderIndicatorRule(longCci, minus100) // Bear trend
.and(new OverIndicatorRule(shortCci, plus100)); // Signal
this.strategy = new Strategy(entryRule, exitRule);
}
示例4: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a dummy strategy
*/
private static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
SMAIndicator sma = new SMAIndicator(closePrice, 12);
// Signals
// Buy when SMA goes over close price
// Sell when close price goes over SMA
Strategy buySellSignals = new BaseStrategy(
new OverIndicatorRule(sma, closePrice),
new UnderIndicatorRule(sma, closePrice)
);
return buySellSignals;
}
示例5: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a CCI correction strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
CCIIndicator longCci = new CCIIndicator(series, 200);
CCIIndicator shortCci = new CCIIndicator(series, 5);
Decimal plus100 = Decimal.HUNDRED;
Decimal minus100 = Decimal.valueOf(-100);
Rule entryRule = new OverIndicatorRule(longCci, plus100) // Bull trend
.and(new UnderIndicatorRule(shortCci, minus100)); // Signal
Rule exitRule = new UnderIndicatorRule(longCci, minus100) // Bear trend
.and(new OverIndicatorRule(shortCci, plus100)); // Signal
Strategy strategy = new BaseStrategy(entryRule, exitRule);
strategy.setUnstablePeriod(5);
return strategy;
}
示例6: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a global extrema strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrices = new ClosePriceIndicator(series);
// Getting the max price over the past week
MaxPriceIndicator maxPrices = new MaxPriceIndicator(series);
HighestValueIndicator weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK);
// Getting the min price over the past week
MinPriceIndicator minPrices = new MinPriceIndicator(series);
LowestValueIndicator weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK);
// Going long if the close price goes below the min price
MultiplierIndicator downWeek = new MultiplierIndicator(weekMinPrice, Decimal.valueOf("1.004"));
Rule buyingRule = new UnderIndicatorRule(closePrices, downWeek);
// Going short if the close price goes above the max price
MultiplierIndicator upWeek = new MultiplierIndicator(weekMaxPrice, Decimal.valueOf("0.996"));
Rule sellingRule = new OverIndicatorRule(closePrices, upWeek);
return new BaseStrategy(buyingRule, sellingRule);
}
示例7: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的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);
}
示例8: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的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 BaseStrategy(entryRule, exitRule);
}
示例9: buildStrategy
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
/**
* @param series a time series
* @return a 2-period RSI strategy
*/
public static Strategy buildStrategy(TimeSeries series) {
if (series == null) {
throw new IllegalArgumentException("Series cannot be null");
}
ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
SMAIndicator shortSma = new SMAIndicator(closePrice, 5);
SMAIndicator longSma = new SMAIndicator(closePrice, 200);
// We use a 2-period RSI indicator to identify buying
// or selling opportunities within the bigger trend.
RSIIndicator rsi = new RSIIndicator(closePrice, 2);
// Entry rule
// The long-term trend is up when a security is above its 200-period SMA.
Rule entryRule = new OverIndicatorRule(shortSma, longSma) // Trend
.and(new CrossedDownIndicatorRule(rsi, Decimal.valueOf(5))) // Signal 1
.and(new OverIndicatorRule(shortSma, closePrice)); // Signal 2
// Exit rule
// The long-term trend is down when a security is below its 200-period SMA.
Rule exitRule = new UnderIndicatorRule(shortSma, longSma) // Trend
.and(new CrossedUpIndicatorRule(rsi, Decimal.valueOf(95))) // Signal 1
.and(new UnderIndicatorRule(shortSma, closePrice)); // Signal 2
// TODO: Finalize the strategy
return new BaseStrategy(entryRule, exitRule);
}
示例10: strategyExecutionOnCachedIndicatorAndLimitedTimeSeries
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
@Test
public void strategyExecutionOnCachedIndicatorAndLimitedTimeSeries() {
TimeSeries timeSeries = new MockTimeSeries(0, 1, 2, 3, 4, 5, 6, 7);
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(timeSeries), 2);
// Theoretical values for SMA(2) cache: 0, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5
timeSeries.setMaximumTickCount(6);
// Theoretical values for SMA(2) cache: null, null, 2, 2.5, 3.5, 4.5, 5.5, 6.5
Strategy strategy = new BaseStrategy(
new OverIndicatorRule(sma, Decimal.THREE),
new UnderIndicatorRule(sma, Decimal.THREE)
);
// Theoretical shouldEnter results: false, false, false, false, true, true, true, true
// Theoretical shouldExit results: false, false, true, true, false, false, false, false
// As we return the first tick/result found for the removed ticks:
// -> Approximated values for ClosePrice cache: 2, 2, 2, 3, 4, 5, 6, 7
// -> Approximated values for SMA(2) cache: 2, 2, 2, 2.5, 3.5, 4.5, 5.5, 6.5
// Then enters/exits are also approximated:
// -> shouldEnter results: false, false, false, false, true, true, true, true
// -> shouldExit results: true, true, true, true, false, false, false, false
assertFalse(strategy.shouldEnter(0));
assertTrue(strategy.shouldExit(0));
assertFalse(strategy.shouldEnter(1));
assertTrue(strategy.shouldExit(1));
assertFalse(strategy.shouldEnter(2));
assertTrue(strategy.shouldExit(2));
assertFalse(strategy.shouldEnter(3));
assertTrue(strategy.shouldExit(3));
assertTrue(strategy.shouldEnter(4));
assertFalse(strategy.shouldExit(4));
assertTrue(strategy.shouldEnter(5));
assertFalse(strategy.shouldExit(5));
assertTrue(strategy.shouldEnter(6));
assertFalse(strategy.shouldExit(6));
assertTrue(strategy.shouldEnter(7));
assertFalse(strategy.shouldExit(7));
}
示例11: setUp
import eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule; //导入依赖的package包/类
@Before
public void setUp() {
indicator = new FixedDecimalIndicator(0, 5, 8, 5, 1, 10, 20, 30);
rule = new UnderIndicatorRule(indicator, Decimal.valueOf(5));
}