Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            // Getting the time series
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();
            // Building the trading strategy
            Strategy strategy = MovingMomentumStrategy.buildStrategy(series);

            /// <summary>
            /// Building chart datasets
            /// </summary>
            TimeSeriesCollection dataset = new TimeSeriesCollection();

            dataset.addSeries(buildChartTimeSeries(series, new ClosePriceIndicator(series), "Bitstamp Bitcoin (BTC)"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Bitstamp BTC", "Date", "Price", dataset, true, true, false);             // generate URLs? -  generate tooltips? -  create legend? -  data -  y-axis label -  x-axis label -  title
            XYPlot     plot  = (XYPlot)chart.Plot;
            DateAxis   axis  = (DateAxis)plot.DomainAxis;

            axis.DateFormatOverride = new SimpleDateFormat("MM-dd HH:mm");

            /// <summary>
            /// Running the strategy and adding the buy and sell signals to plot
            /// </summary>
            addBuySellSignals(series, strategy, plot);

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds an additional JFreeChart dataset from a ta4j time series. </summary>
        /// <param name="series"> a time series </param>
        /// <returns> an additional dataset </returns>
        private static TimeSeriesCollection createAdditionalDataset(TimeSeries series)
        {
            ClosePriceIndicator  indicator = new ClosePriceIndicator(series);
            TimeSeriesCollection dataset   = new TimeSeriesCollection();

            org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries("Btc price");
            for (int i = 0; i < series.TickCount; i++)
            {
                Tick tick = series.getTick(i);
                chartTimeSeries.add(new Second(tick.EndTime.toDate()), indicator.getValue(i).toDouble());
            }
            dataset.addSeries(chartTimeSeries);
            return(dataset);
        }