Exemple #1
0
        public void Test_Bollinger_Bands()
        {
            Random rand = new Random(0);

            double[] xs    = DataGen.Consecutive(150);
            OHLC[]   ohlcs = DataGen.RandomStockPrices(rand, xs.Length);
            (var sma, var bolL, var bolU) = ScottPlot.Statistics.Finance.Bollinger(ohlcs);

            // replace timestamps with a series of numbers starting at 0
            for (int i = 0; i < ohlcs.Length; i++)
            {
                ohlcs[i].time = i;
            }

            var plt = new ScottPlot.Plot(600, 400);

            plt.PlotCandlestick(ohlcs);
            plt.PlotFill(xs, bolL, xs, bolU, fillColor: Color.Blue, fillAlpha: .1);
            plt.PlotScatter(xs, bolL, color: Color.Navy, markerSize: 0);
            plt.PlotScatter(xs, bolU, color: Color.Navy, markerSize: 0);
            plt.PlotScatter(xs, sma, color: Color.Navy, markerSize: 0, lineStyle: LineStyle.Dash);

            plt.Title("Bollinger Bands");
            plt.YLabel("Price");
            plt.XLabel("Days");
            plt.Legend();
            plt.AxisAutoX(.03);
            TestTools.SaveFig(plt);
        }