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


Java CrossedDownIndicatorRule类代码示例

本文整理汇总了Java中eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule的典型用法代码示例。如果您正苦于以下问题:Java CrossedDownIndicatorRule类的具体用法?Java CrossedDownIndicatorRule怎么用?Java CrossedDownIndicatorRule使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CrossedDownIndicatorRule类属于eu.verdelhan.ta4j.trading.rules包,在下文中一共展示了CrossedDownIndicatorRule类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testStrategies

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的package包/类
@Test
public void testStrategies() { 
    
    PeriodicalGrowthRateIndicator gri = new PeriodicalGrowthRateIndicator(this.closePrice,5);

    // Rules
    Rule buyingRule = new CrossedUpIndicatorRule(gri, Decimal.ZERO); 
    Rule sellingRule = new CrossedDownIndicatorRule(gri, Decimal.ZERO);     
    
    Strategy strategy = new BaseStrategy(buyingRule, sellingRule);
            
    // Check trades
    int result = seriesManager.run(strategy).getTradeCount();             
    int expResult = 3;
    
    assertEquals(expResult, result);
}
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:18,代码来源:PeriodicalGrowthRateIndicatorTest.java

示例2: buildStrategy

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的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

示例3: SMAStrategy

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的package包/类
public SMAStrategy(final TimeSeries series, final ClosePriceIndicator closePriceIndicator) {
  super(series, SMAStrategy.class.getSimpleName(), closePriceIndicator);

  // setup this strategy...
  sma = new SMAIndicator(closePriceIndicator, 12);
  this.strategy = new Strategy(
      new CrossedUpIndicatorRule(sma, closePriceIndicator),
      new CrossedDownIndicatorRule(sma, closePriceIndicator));
}
 
开发者ID:the-james-burton,项目名称:the-turbine,代码行数:10,代码来源:SMAStrategy.java

示例4: buildStrategy

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的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

示例5: buildStrategy

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的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

示例6: main

import eu.verdelhan.ta4j.trading.rules.CrossedDownIndicatorRule; //导入依赖的package包/类
public static void main(String[] args) {

        // Getting a time series (from any provider: CSV, web service, etc.)
        TimeSeries series = CsvTradesLoader.loadBitstampSeries();


        // Getting the close price of the ticks
        Decimal firstClosePrice = series.getTick(0).getClosePrice();
        System.out.println("First close price: " + firstClosePrice.toDouble());
        // Or within an indicator:
        ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
        // Here is the same close price:
        System.out.println(firstClosePrice.isEqual(closePrice.getValue(0))); // equal to firstClosePrice

        // Getting the simple moving average (SMA) of the close price over the last 5 ticks
        SMAIndicator shortSma = new SMAIndicator(closePrice, 5);
        // Here is the 5-ticks-SMA value at the 42nd index
        System.out.println("5-ticks-SMA value at the 42nd index: " + shortSma.getValue(42).toDouble());

        // Getting a longer SMA (e.g. over the 30 last ticks)
        SMAIndicator longSma = new SMAIndicator(closePrice, 30);


        // Ok, now let's building our trading rules!

        // Buying rules
        // We want to buy:
        //  - if the 5-ticks SMA crosses over 30-ticks SMA
        //  - or if the price goes below a defined price (e.g $800.00)
        Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma)
                .or(new CrossedDownIndicatorRule(closePrice, Decimal.valueOf("800")));
        
        // Selling rules
        // We want to sell:
        //  - if the 5-ticks SMA crosses under 30-ticks SMA
        //  - or if if the price looses more than 3%
        //  - or if the price earns more than 2%
        Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma)
                .or(new StopLossRule(closePrice, Decimal.valueOf("3")))
                .or(new StopGainRule(closePrice, Decimal.valueOf("2")));
        
        // Running our juicy trading strategy...
        TimeSeriesManager seriesManager = new TimeSeriesManager(series);
        TradingRecord tradingRecord = seriesManager.run(new BaseStrategy(buyingRule, sellingRule));
        System.out.println("Number of trades for our strategy: " + tradingRecord.getTradeCount());


        // Analysis

        // Getting the cash flow of the resulting trades
        CashFlow cashFlow = new CashFlow(series, tradingRecord);

        // Getting the profitable trades ratio
        AnalysisCriterion profitTradesRatio = new AverageProfitableTradesCriterion();
        System.out.println("Profitable trades ratio: " + profitTradesRatio.calculate(series, tradingRecord));
        // Getting the reward-risk ratio
        AnalysisCriterion rewardRiskRatio = new RewardRiskRatioCriterion();
        System.out.println("Reward-risk ratio: " + rewardRiskRatio.calculate(series, tradingRecord));

        // Total profit of our strategy
        // vs total profit of a buy-and-hold strategy
        AnalysisCriterion vsBuyAndHold = new VersusBuyAndHoldCriterion(new TotalProfitCriterion());
        System.out.println("Our profit vs buy-and-hold profit: " + vsBuyAndHold.calculate(series, tradingRecord));

        // Your turn!
    }
 
开发者ID:mdeverdelhan,项目名称:ta4j-origins,代码行数:67,代码来源:Quickstart.java


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