Пример #1
0
        public static OHLC[] RandomStockPrices(Random rand, int pointCount, double mult = 10, double startingPrice = 123.45)
        {
            if (rand is null)
            {
                rand = new Random();
            }

            double[] basePrices = ScottPlot.DataGen.RandomWalk(rand, pointCount, mult, startingPrice);

            OHLC[] ohlcs = new OHLC[pointCount];

            for (int i = 0; i < ohlcs.Length; i++)
            {
                double open  = rand.NextDouble() * 10 + 50;
                double close = rand.NextDouble() * 10 + 50;
                double high  = Math.Max(open, close) + rand.NextDouble() * 10;
                double low   = Math.Min(open, close) - rand.NextDouble() * 10;

                // offset prices by randomwalk
                open  += basePrices[i];
                close += basePrices[i];
                high  += basePrices[i];
                low   += basePrices[i];

                ohlcs[i] = new ScottPlot.OHLC(open, high, low, close, i);
            }

            return(ohlcs);
        }
        public static void PlotOHLC(List <StockHistoryDay> stockHistory, string folderName, string fileName)
        {
            List <ScottPlot.OHLC> valSeriesList = new List <ScottPlot.OHLC>();

            foreach (StockHistoryDay stockHistoryDay in stockHistory)
            {
                ScottPlot.OHLC ohlc = new ScottPlot.OHLC(
                    stockHistoryDay.Open,
                    stockHistoryDay.High,
                    stockHistoryDay.Low,
                    stockHistoryDay.Close,
                    stockHistoryDay.Date
                    );

                valSeriesList.Add(ohlc);
            }

            ScottPlot.OHLC[] valSeries = valSeriesList.ToArray();

            var plt = new ScottPlot.Plot(1000, 700);

            plt.Title("MSFT", fontName: "Segoe UI Light", color: Color.Black);
            plt.Ticks(dateTimeX: true, fontName: "Cascadia Mono");

            // grids at every 7 days
            plt.Grid(xSpacing: 7, xSpacingDateTimeUnit: ScottPlot.Config.DateTimeUnit.Day);
            plt.SetCulture(shortDatePattern: "M\\/dd");

            // create folder if not exists
            System.IO.Directory.CreateDirectory(folderName);

            plt.PlotOHLC(valSeries);

            plt.SaveFig($"./{folderName}/{fileName}.png");
        }
Пример #3
0
        public static OHLC[] RandomStockPrices(Random rand, int pointCount, double mult = 10, double startingPrice = 123.45, int deltaMinutes = 0, int deltaDays = 1, bool sequential = false)
        {
            if (rand is null)
            {
                rand = new Random(0);
            }

            double[] basePrices = ScottPlot.DataGen.RandomWalk(rand, pointCount, mult, startingPrice);

            OHLC[] ohlcs = new OHLC[pointCount];

            DateTime dt = new DateTime(1985, 9, 24, 9, 30, 0);

            for (int i = 0; i < ohlcs.Length; i++)
            {
                double open  = rand.NextDouble() * 10 + 50;
                double close = rand.NextDouble() * 10 + 50;
                double high  = Math.Max(open, close) + rand.NextDouble() * 10;
                double low   = Math.Min(open, close) - rand.NextDouble() * 10;

                // offset prices by randomwalk
                open  += basePrices[i];
                close += basePrices[i];
                high  += basePrices[i];
                low   += basePrices[i];

                if (deltaMinutes > 0)
                {
                    dt = dt.AddMinutes(deltaMinutes);
                }
                else if (deltaDays > 0)
                {
                    dt = dt.AddDays(deltaDays);
                    while ((dt.DayOfWeek == DayOfWeek.Saturday) || (dt.DayOfWeek == DayOfWeek.Sunday))
                    {
                        dt = dt.AddDays(1);
                    }
                }

                if (sequential)
                {
                    ohlcs[i] = new OHLC(open, high, low, close, i);
                }
                else
                {
                    ohlcs[i] = new OHLC(open, high, low, close, dt);
                }
            }

            return(ohlcs);
        }
Пример #4
0
        public static string chart(string pair)
        {
            List <string> pena = new List <string>();

            System.Net.WebClient wc1 = new System.Net.WebClient();
            int    sum_chart         = 150;
            double last_price        = 0;
            String link_Response     = wc1.DownloadString("https://www.binance.com/api/v1/klines?symbol=" + pair + "&interval=15m&limit=" + sum_chart);

            MatchCollection matchList = System.Text.RegularExpressions.Regex.Matches(link_Response, @"(\d+.\d+)|\d+\d+|\d");

            pena = matchList.Cast <Match>().Select(match => match.Value).ToList();
            System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");

            int count      = 0;
            int count_draw = 0;

            //Оишбка в апи hbc в конце несколкьо нулей 0 0 0 0 0
            //введен костыль-переменная
            ScottPlot.OHLC[] ohlcs = new ScottPlot.OHLC[sum_chart];
            var plt = new ScottPlot.Plot(800, 400);

            for (int i = 0; i < sum_chart; i++)
            {
                double Open     = Convert.ToDouble(pena[count_draw + 1]);
                double High     = Convert.ToDouble(pena[count_draw + 2]);
                double Low      = Convert.ToDouble(pena[count_draw + 3]);
                double Close    = Convert.ToDouble(pena[count_draw + 4]);
                double Opentime = ((Convert.ToDouble(pena[count_draw])) / 1000) + (3600 * 3);

                ohlcs[count] = new ScottPlot.OHLC(Open, High, Low, Close, ConvertFromUnixTimestamp(Opentime), 1);
                count_draw   = count_draw + 12;
                count++;
                last_price = Close;
            }

            plt.Title("15 Minute Chart");
            plt.YLabel("Stock Price (" + pair + ")");
            plt.Ticks(dateTimeX: true, dateTimeFormatStringX: "HH:mm:ss", numericFormatStringY: "n");
            plt.PlotCandlestick(ohlcs);
            plt.Style(tick: Color.White, label: Color.White, title: Color.White, dataBg: Color.FromArgb(255, 36, 43, 60), grid: Color.FromArgb(255, 36, 43, 60), figBg: Color.FromArgb(255, 36, 43, 60));
            DateTime date1 = new DateTime();

            date1 = DateTime.Now;

            string name = "PlotTypes" + pair + "№" + date1.Ticks + ".png";

            string name_file  = name;
            string label_name = Convert.ToString(last_price);

            plt.PlotHLine(y: last_price, color: Color.Green, lineWidth: 0.5, label: label_name);
            plt.Legend(backColor: Color.FromArgb(255, 36, 43, 60), location: legendLocation.upperCenter);



            plt.SaveFig(name_file);



            return(name_file);
        }