/// <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);
        }
        private void AddPointInfo(object sender, MouseButtonEventArgs e)
        {
            Canvas canvas = (Canvas)sender;
            var    point  = e.GetPosition(canvas);
            double index  = (x_count - 1) * ((point.X - marginX) / (width - 2 * marginX));
            var    points = stockData.Charts[Constant.ChartMapper[type]];

            index = datesAxisKeypoint.Count - 1 - (int)index;
            if (canvas.Name == "Stock")
            {
                tmp = BuilderTools.AddText("P:" + points[(int)index].ClosePrice + ",\n" + "V:" + points[(int)index].Volume + ",\n" + "S10:" + points[(int)index].SMA_10 + ",\n" + "S50:" + points[(int)index].SMA_50 + ",\n" + "S200:" + points[(int)index].SMA_200, point.X, point.Y, 50, 80);
            }
            else if (canvas.Name == "MACD")
            {
                tmp = BuilderTools.AddText(points[(int)index].MACD + ",\n" + points[(int)index].MACD_SIGNAL + ",\n" + points[(int)index].MACD_HIST, point.X, point.Y, 50, 50);
            }
            else if (canvas.Name == "RSI")
            {
                tmp = BuilderTools.AddText(points[(int)index].RSI + "", point.X, point.Y, 30, 20);
            }
            canvas.Children.Add(tmp);
        }
        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) });
        }
        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);
        }
        /// <summary>
        /// currently 0 -> MACD; 1->RSI
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="y_count"></param>
        /// <param name="type"></param>
        public void DrawMACDToCanvas(ref Canvas canvas, int y_count)
        {
            double ymid  = canvas.Height / 2;
            double xmin  = marginX;
            double xmax  = canvas.Width - marginX;
            double stepX = (xmax - xmin) / (x_count - 1);
            double stepY = canvas.Height / (y_count - 1);

            BuilderTools.Axis(ref canvas, xmin, xmax, ymid, ymid, x_count, 0, datesAxisKeypoint, 1, Brushes.Black);
            BuilderTools.Axis(ref canvas, xmin, xmin, 0, 2 * ymid, y_count, 1, MACDAxisKeypoint, 1, Brushes.Black);

            var lowVal   = GeneralTools.StringParser(MACDAxisKeypoint.First());
            var highVal  = GeneralTools.StringParser(MACDAxisKeypoint.Last());
            var MACDPath = GetMACDChartPath(xmin, ymid, stepX, stepY, lowVal, highVal);

            foreach (var path in MACDPath)
            {
                canvas.Children.Add(path);
            }

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