Ejemplo n.º 1
0
        /// <summary>
        /// Draw the X,Y axis of the Stock snapshot,  To build up the main stock chart
        /// </summary>
        /// <param name="canvas"></param>
        public void DrawStockMajorToCanvas(ref Canvas canvas)
        {
            double xmin  = marginX;
            double xmax  = width - marginX;
            double ymin  = marginY;
            double ymax  = height - marginY;
            double stepX = (xmax - xmin) / (x_count - 1);
            double stepY = (ymax - ymin) / (y_count - 1);

            BuilderTools.Axis(ref canvas, xmin, xmax, ymax, ymax, x_count, 0, datesAxisKeypoint, 1, Brushes.Black);   // build x
            BuilderTools.Axis(ref canvas, xmin, xmin, ymin, ymax, y_count, 1, pricesAxisKeypoint, 1, Brushes.Black);  //build y1 for price
            BuilderTools.Axis(ref canvas, xmax, xmax, ymin, ymax, y_count, 1, volumesAxisKeypoint, 1, Brushes.Black); // build y2 for volume
            var points = stockData.Charts[Constant.ChartMapper[type]];

            if (menuSetting.ChartSettings["CHARTTYPE"])
            {
                var stockPath = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.ClosePrice).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 1, Brushes.Blue, false);
                canvas.Children.Add(stockPath);
            }
            else
            {
                var stockPath = BuilderTools.CandleChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.OpenPrice).ToList(), points.Select(p => p.ClosePrice).ToList(), points.Select(p => p.HighPrice).ToList(), points.Select(p => p.LowPrice).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 1, Brushes.Blue, false);
                foreach (var p in stockPath)
                {
                    canvas.Children.Add(p);
                }
            }
            if (menuSetting.ChartSettings["SMA10"])
            {
                var sma_10 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_10).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.Green, true);
                canvas.Children.Add(sma_10);
            }
            if (menuSetting.ChartSettings["SMA50"])
            {
                var sma_50 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_50).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.DarkSeaGreen, true);
                canvas.Children.Add(sma_50);
            }
            if (menuSetting.ChartSettings["SMA200"])
            {
                var sma_200 = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.SMA_200).ToList(), 0, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.Blue, true);
                canvas.Children.Add(sma_200);
            }

            //start to draw stock
            if (menuSetting.ChartSettings["VOLUME"])
            {
                var volumePath = GetVolumeChartPath(xmin, ymin, ymax, stepX, stepY, VolumeStringToVolume(volumesAxisKeypoint.Last()));
                canvas.Children.Add(volumePath);
            }
            if (menuSetting.ChartSettings["TREND"] && menuSetting.ChartType == Constant.DAILYCHART)
            {
                var TrendPath = GetTrendLineChartPath(xmin, ymin, ymax, stepX, stepY, GeneralTools.StringParser(pricesAxisKeypoint[0]), GeneralTools.StringParser(pricesAxisKeypoint.Last()), 2, Brushes.LightBlue, false);
                canvas.Children.Add(TrendPath[0]);
                canvas.Children.Add(TrendPath[1]);
            }
            canvas.MouseDown += new MouseButtonEventHandler(AddPointInfo);
            canvas.MouseUp   += new MouseButtonEventHandler(RemovePointInfo);
        }
Ejemplo n.º 2
0
        private Path [] GetTrendLineChartPath(double xmin, double ymin, double ymax, double stepX, double stepY, double lowVal, double highVal, int strokeThickness, SolidColorBrush color, bool isDash)
        {
            StockSummary summary = sqlReader.ReadStockAnalysis("ACB");

            if ((bool)summary.CacheData["fail"])
            {
                return(null);
            }
            double[] boundaries  = summary.SerializedProperties["boundaries"] as double[];
            var      summaryDate = summary.LastUpdate;
            int      index       = 0;
            var      points      = stockData.Charts[Constant.ChartMapper[type]];

            foreach (var point in points)
            {
                var tmp = point.Date.Split('-');
                if (Int16.Parse(tmp[0]) == summaryDate.Year && Int16.Parse(tmp[1]) == summaryDate.Month && Int16.Parse(tmp[2]) == summaryDate.Day)
                {
                    break;
                }
                index++;
            }
            int           indexH = 100 - (index + (int)boundaries[1] + 60); // the start x axis point we draw the line
            double        startHigh = points.ElementAt(index + (int)boundaries[1]).HighPrice + 60 * boundaries[0];
            int           indexL = 100 - (index + (int)boundaries[3] + 60); // the start x axis point we draw the line
            double        startLow = points.ElementAt(index + (int)boundaries[3]).LowPrice + 60 * boundaries[2];
            List <double> valH = new List <double>(); List <double> valL = new List <double>();

            for (int i = 0; i < 100; i++)
            {
                valH.Add(startHigh - boundaries[0] * i);
                valL.Add(startLow - boundaries[2] * i);
            }
            valH.Reverse();
            valL.Reverse();
            return(new Path[] { BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, valH, indexH, lowVal, highVal, strokeThickness, color, false),
                                BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, valL, indexL, lowVal, highVal, strokeThickness, color, false) });
        }
Ejemplo n.º 3
0
        public void DrawRSIToCanvas(ref Canvas canvas, int y_count)
        {
            double ymin  = 5;
            double ymax  = canvas.Height - 5;
            double xmin  = marginX;
            double xmax  = canvas.Width - marginX;
            double stepX = (xmax - xmin) / (x_count - 1);
            double stepY = (ymax - ymin) / (y_count - 1);

            BuilderTools.Axis(ref canvas, xmin, xmax, ymax - 10, ymax - 10, x_count, 0, datesAxisKeypoint, 1, Brushes.Black);
            List <string> RSI = new List <string>()
            {
                "0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100"
            };

            BuilderTools.Axis(ref canvas, xmin, xmin, ymin, ymax, y_count, 1, RSI, 1, Brushes.Black);
            var points  = stockData.Charts[Constant.ChartMapper[type]];
            var RSIPath = BuilderTools.LineChart(xmin, ymin, ymax, stepX, stepY, points.Select(p => p.RSI).ToList(), 0, 0, 100, 2, Brushes.Blue, false);

            canvas.Children.Add(RSIPath);
            canvas.MouseDown += new MouseButtonEventHandler(AddPointInfo);
            canvas.MouseUp   += new MouseButtonEventHandler(RemovePointInfo);
        }