A simple charting application for ta4j using Swing and jfreechart.
You can get the latest release of this library by adding the following maven dependency:
<dependency>
<groupId>de.sjwimmer.ta4j-charting</groupId>
<artifactId>lib</artifactId>
<version>0.1</version>
</dependency>
The latest SNAPSHOT can by used by this dependency:
<dependency>
<groupId>de.sjwimmer.ta4j-charting</groupId>
<artifactId>lib</artifactId>
<version>0.2-SNAPSHOT</version>
</dependency>
The example application and library can be build by executing:
> git clone https://github.com/team172011/ta4jCharting.git
> cd ta4jCharting
> mvn clean package
After building the example application the example can be started by executing:
> java -jar example/target/example-0.0.1-SNAPSHOT.jar
final BarSeries barSeries = loadAppleIncSeries(); // create a ta4j bar series
TacChartBuilder.of(barSeries)
.buildAndShow("AAPL");
// 1 Create a barSeries, indicators and run your strategy with ta4j
final BarSeries barSeries = loadAppleIncSeries();
final VolumeIndicator volume = new VolumeIndicator(barSeries);
final ParabolicSarIndicator parabolicSar = new ParabolicSarIndicator(barSeries);
final ClosePriceIndicator closePrice = new ClosePriceIndicator(barSeries);
final EMAIndicator longEma = new EMAIndicator(closePrice, 12);
final EMAIndicator shortEma = new EMAIndicator(closePrice, 4);
final CrossedDownIndicatorRule exit = new CrossedDownIndicatorRule(shortEma, longEma);
final CrossedUpIndicatorRule entry = new CrossedUpIndicatorRule(shortEma, longEma);
final Strategy strategy = new BaseStrategy(entry, exit);
final TradingRecord tradingRecord = new BarSeriesManager(barSeries).run(strategy);
final Returns returns = new Returns(barSeries, tradingRecord, Returns.ReturnType.ARITHMETIC);
// 2 Use the ChartBuilder to create a plot with barSeries, indicators and trading record
TacChartBuilder.of(barSeries)
.withIndicator(
of(shortEma)
.name("Short Ema")
.color(Color.BLUE)) // default: ChartType.LINE, PlotType.OVERLAY
.withIndicator(
of(volume)
.name("Volume")
.plotType(PlotType.SUBPLOT)
.chartType(ChartType.BAR)
.color(Color.BLUE))
withIndicator(
of(parabolicSar) // default name = toString()
.plotType(PlotType.OVERLAY)
.chartType(ChartType.LINE)
.color(Color.MAGENTA))
.withIndicator(
of(longEma)
.name("Long Ema")
.plotType(PlotType.SUBPLOT)
.chartType(ChartType.LINE)) // random color
.withIndicator(
of(returns)
.name("Returns")
.plotType(PlotType.SUBPLOT)
.color(Color.BLACK)) // default: ChartType.LINE
.withTradingRecord(tradingRecord)
.buildAndShow(); // Creates and displays the JPanel in a JFrame
You can also use a dark theme:
TacChartBuilder.of(barSeries, Theme.DARK).buildAndShow();
This project is a simple maven project with a parent pom and two modules for the ta4j-charting library and the example project
└───ta4j-charting-parent
├───pom.xml
├───README.md
└───lib
│ ├───pom.xml
│ └───src
│ ├───main
│ │ └───resources
│ └───test
│
│
└───example
├───pom.xml
└───src
├───main
│ └───resources
└───test