當前位置: 首頁>>代碼示例>>Java>>正文


Java CrossedDownIndicatorRule類代碼示例

本文整理匯總了Java中org.ta4j.core.trading.rules.CrossedDownIndicatorRule的典型用法代碼示例。如果您正苦於以下問題:Java CrossedDownIndicatorRule類的具體用法?Java CrossedDownIndicatorRule怎麽用?Java CrossedDownIndicatorRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CrossedDownIndicatorRule類屬於org.ta4j.core.trading.rules包,在下文中一共展示了CrossedDownIndicatorRule類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testStrategies

import org.ta4j.core.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:ta4j,項目名稱:ta4j,代碼行數:18,代碼來源:PeriodicalGrowthRateIndicatorTest.java

示例2: getStrategy

import org.ta4j.core.trading.rules.CrossedDownIndicatorRule; //導入依賴的package包/類
public Strategy getStrategy() {
	EMAIndicator sma1 = new EMAIndicator(closePriceIndicator, 5);
	EMAIndicator sma2 = new EMAIndicator(closePriceIndicator, 10);
	
	RSIIndicator rsi = new RSIIndicator(closePriceIndicator, 14);
	
	StochasticOscillatorKIndicator stochK = new StochasticOscillatorKIndicator(timeSeries, 14);
	StochasticOscillatorDIndicator stochD = new StochasticOscillatorDIndicator(stochK);
	
	Rule buyingRule = new CrossedUpIndicatorRule(sma1, sma2)
			.and(new OverIndicatorRule(rsi, Decimal.valueOf(50)))
			.and(new OverIndicatorRule(stochK, stochD))
			.and(new UnderIndicatorRule(stochD, Decimal.valueOf(80)));

	Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma2)
			.or(new CrossedDownIndicatorRule(rsi, Decimal.valueOf(50)));

	final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
	
	return strategy;
}
 
開發者ID:jnidzwetzki,項目名稱:crypto-bot,代碼行數:22,代碼來源:ForexStrategy01.java

示例3: getStrategy

import org.ta4j.core.trading.rules.CrossedDownIndicatorRule; //導入依賴的package包/類
public Strategy getStrategy() {
	ClosePriceIndicator closePrice = new ClosePriceIndicator(timeSeries);

	EMAIndicator sma1 = new EMAIndicator(closePrice, sma1Value);
	EMAIndicator sma2 = new EMAIndicator(closePrice, sma2Value);
	EMAIndicator sma3 = new EMAIndicator(closePrice, sma3Value);
	
	RSIIndicator rsi = new RSIIndicator(closePrice, 14);
	
	Rule buyingRule = new OverIndicatorRule(sma1, sma2)
			.and(new OverIndicatorRule(sma2, sma3))
			.and(new OverIndicatorRule(rsi, Decimal.valueOf(50)));

	Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma3)
			.or(new CrossedDownIndicatorRule(sma2, sma3))
			.or(new StopLossRule(closePrice, Decimal.valueOf("3")));

	final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
	
	return strategy;
}
 
開發者ID:jnidzwetzki,項目名稱:crypto-bot,代碼行數:22,代碼來源:EMAStrategy03.java

示例4: buildStrategy

import org.ta4j.core.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:ta4j,項目名稱:ta4j,代碼行數:34,代碼來源:MovingMomentumStrategy.java

示例5: buildStrategy

import org.ta4j.core.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:ta4j,項目名稱:ta4j,代碼行數:34,代碼來源:RSI2Strategy.java

示例6: getStrategy

import org.ta4j.core.trading.rules.CrossedDownIndicatorRule; //導入依賴的package包/類
public Strategy getStrategy() {
	SMAIndicator shortSma = new SMAIndicator(closePriceIndicator, 5);
	SMAIndicator longSma = new SMAIndicator(closePriceIndicator, 30);

	Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma);

	Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma)
			.or(new StopLossRule(closePriceIndicator, Decimal.valueOf("3")))
			.or(new StopGainRule(closePriceIndicator, Decimal.valueOf("2")));

	final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
	
	return strategy;
}
 
開發者ID:jnidzwetzki,項目名稱:crypto-bot,代碼行數:15,代碼來源:EMAStrategy01.java

示例7: getStrategy

import org.ta4j.core.trading.rules.CrossedDownIndicatorRule; //導入依賴的package包/類
public Strategy getStrategy() {
	EMAIndicator sma1 = new EMAIndicator(closePriceIndicator, sma1Value);
	EMAIndicator sma2 = new EMAIndicator(closePriceIndicator, sma2Value);
	EMAIndicator sma3 = new EMAIndicator(closePriceIndicator, sma3Value);
	
	Rule buyingRule = new CrossedUpIndicatorRule(sma1, sma2).and(new OverIndicatorRule(sma2, sma3));

	Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma3);
	//		.or(new CrossedDownIndicatorRule(sma2, sma3));

	final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
	
	return strategy;
}
 
開發者ID:jnidzwetzki,項目名稱:crypto-bot,代碼行數:15,代碼來源:EMAStrategy02.java

示例8: main

import org.ta4j.core.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:ta4j,項目名稱:ta4j,代碼行數:67,代碼來源:Quickstart.java


注:本文中的org.ta4j.core.trading.rules.CrossedDownIndicatorRule類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。