当前位置: 首页>>代码示例>>Java>>正文


Java UnderIndicatorRule类代码示例

本文整理汇总了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;
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:25,代码来源:CCICorrectionStrategy.java

示例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);
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:29,代码来源:GlobalExtremaStrategy.java

示例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);
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:20,代码来源:CCICorrectionStrategy.java

示例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;
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:22,代码来源:TradingBotOnMovingTimeSeries.java

示例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;
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:25,代码来源:CCICorrectionStrategy.java

示例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);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:29,代码来源:GlobalExtremaStrategy.java

示例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);
}
 
开发者ID:romatroskin,项目名称:altrader,代码行数:34,代码来源:MovingMomentumStrategy.java

示例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);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:34,代码来源:MovingMomentumStrategy.java

示例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);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:34,代码来源:RSI2Strategy.java

示例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));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:41,代码来源:CachedIndicatorTest.java

示例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));
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:6,代码来源:UnderIndicatorRuleTest.java


注:本文中的eu.verdelhan.ta4j.trading.rules.UnderIndicatorRule类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。