All Projects → sirolf2009 → samurai

sirolf2009 / samurai

Licence: other
No description, website, or topics provided.

Programming Languages

Xtend
68 projects

samurai

Samurai is a GUI for TA4J. It's supposed to make it easier for you to get insights in how to improve your trading strategy. You will be able to use all the TA4J built-in and custom indicators to create your strategies. When you have written a strategy, you run it over a dataprovider to see how it would have traded. At some point, this will also support automated trading.

Note that this is still a work in progress application and it is not yet functional enough to be used.

EDIT: you know those people who start projects and never finish them? I'm one of those people. I'm not finishing this project, but you can do whatever you want with it

Installation

  1. This library requires a dependency which isn't on maven central. It's called xtendfx and you can find it here: https://github.com/svenefftinge/xtendfx
  2. You'll also need to get my forked version of ta4j. The official version will not work (yet). You can find it here: https://github.com/sirolf2009/ta4j
  3. run
git clone https://github.com/sirolf2009/samurai.git
cd samurai/samurai
mvn install

Strategies examples

class StrategySMACrossover implements IStrategy {
	
	// we keep these two indicators as variables, so we can re-use them when we're asked what indicators we'd like to show
	// Note that the type MUST be Indicator<Decimal>
	var Indicator<Decimal> shortSma
	var Indicator<Decimal> longSma
	
	// we have two parameters for this strategy. The annotation will ensure that the user can change them in the GUI
	@Param public var shortPeriod = 5
	@Param public var longPeriod = 30

	// if this confuses you, you should read the TA4J documentation. Not mine	
	override setup(TimeSeries series) {
		val closePrice = new ClosePriceIndicator(series)

        shortSma = new SMAIndicator(closePrice, shortPeriod)
        longSma = new SMAIndicator(closePrice, longPeriod)

        val buyingRule = new CrossedUpIndicatorRule(shortSma, longSma)
        val sellingRule = new CrossedDownIndicatorRule(shortSma, longSma)
        
        return new Strategy(buyingRule, sellingRule)
	}
	
	// We want to add both our indicators to the 0th panel, which is the price panel
	override indicators(TimeSeries series) {
        return #[
        	0 -> #[shortSma, longSma]
        ]
	}
	
}
class StrategyMovingMomentum implements IStrategy {
	
	// we keep these indicators as variables, so we can re-use them when we're asked what indicators we'd like to show
	// Note that the type MUST be Indicator<Decimal>
	var Indicator<Decimal> shortEma
	var Indicator<Decimal> longEma
	var Indicator<Decimal> stochasticOscillK
	var Indicator<Decimal> macd
	var Indicator<Decimal> emaMacd
	
	// we have six parameters for this strategy. The annotation will ensure that the user can change them in the GUI
	@Param public var shortPeriod = 9
	@Param public var longPeriod = 26
	@Param public var stochPeriod = 14
	@Param public var macdShortPeriod = 9
	@Param public var macdLongPeriod = 26
	@Param public var macdSmooth = 18
	
	// if this confuses you, you should read the TA4J documentation. Not mine	
	override setup(TimeSeries series) {
        val closePrice = new ClosePriceIndicator(series)
        
        shortEma = new EMAIndicator(closePrice, shortPeriod)
        longEma = new EMAIndicator(closePrice, longPeriod)

        stochasticOscillK = new StochasticOscillatorKIndicator(series, stochPeriod)

        macd = new MACDIndicator(closePrice, macdShortPeriod, macdLongPeriod)
        emaMacd = new EMAIndicator(macd, macdSmooth)
        
        val entryRule = new OverIndicatorRule(shortEma, longEma)
                .and(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20)))
                .and(new OverIndicatorRule(macd, emaMacd))
        
        val exitRule = new UnderIndicatorRule(shortEma, longEma)
                .and(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80)))
                .and(new UnderIndicatorRule(macd, emaMacd))
        
        return new Strategy(entryRule, exitRule)
	}
	
	// Here we set up our indicators
	override indicators(TimeSeries series) {
        return #[
        	0 -> #[shortEma, longEma], //Our ema's should appear in the price panel, so we give them a key of 0
        	1 -> #[stochasticOscillK], //Our stoch should have it's own panel, we give it a key of 1 and don't add any other indicators
        	2 -> #[macd, emaMacd] //Our MACD and MACD EMA should both be in the same panel, we give them a key of 2
        ]
	}
	
}

Screenshots

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].