Exemplo n.º 1
0
 /// <summary>
 /// Builds a JFreeChart time series from a Ta4j time series and an indicator. </summary>
 /// <param name="tickSeries"> the ta4j time series </param>
 /// <param name="indicator"> the indicator </param>
 /// <param name="name"> the name of the chart time series </param>
 /// <returns> the JFreeChart time series </returns>
 private static org.jfree.data.time.TimeSeries buildChartTimeSeries(TimeSeries tickSeries, Indicator <Decimal> indicator, string name)
 {
     org.jfree.data.time.TimeSeries chartTimeSeries = new org.jfree.data.time.TimeSeries(name);
     for (int i = 0; i < tickSeries.TickCount; i++)
     {
         Tick tick = tickSeries.getTick(i);
         chartTimeSeries.add(new Day(tick.EndTime.toDate()), indicator.getValue(i).toDouble());
     }
     return(chartTimeSeries);
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            // Loading the Logback configuration
            loadLoggerConfiguration();

            // Getting the time series
            TimeSeries series = CsvTradesLoader.loadBitstampSeries();

            // Building the trading strategy
            Strategy strategy = CCICorrectionStrategy.buildStrategy(series);

            // Running the strategy
            series.run(strategy);
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            /// <summary>
            /// Getting time series
            /// </summary>
            TimeSeries series = CsvTicksLoader.loadAppleIncSeries();

            /// <summary>
            /// Creating indicators
            /// </summary>
            // Close price
            ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
            // Bollinger bands
            BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(closePrice);
            BollingerBandsLowerIndicator  lowBBand    = new BollingerBandsLowerIndicator(middleBBand, closePrice);
            BollingerBandsUpperIndicator  upBBand     = new BollingerBandsUpperIndicator(middleBBand, closePrice);

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

            dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
            dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
            dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));

            /// <summary>
            /// Creating the chart
            /// </summary>
            JFreeChart chart = ChartFactory.createTimeSeriesChart("Apple Inc. 2013 Close Prices", "Date", "Price Per Unit", 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("yyyy-MM-dd");

            /// <summary>
            /// Displaying the chart
            /// </summary>
            displayChart(chart);
        }