Beispiel #1
0
        private async Task QueryMultipleCollection(string id)
        {
            var chartItems = await loader.GetStockItems(id);

            if (chartItems == null || chartItems.Prices == null)
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var maColls = CreateMACollections(chartItems.Prices).ToArray();

            IEnumerable <ChartItem>[] cItemsList = new IEnumerable <ChartItem> [maColls.Count() + 1];
            IPen[] pens = new IPen[maColls.Count() + 1];

            cItemsList[0] = chartItems.Prices;
            pens[0]       = DrawingObjectFactory.CreatePen(model.RaiseBrush, 1);

            for (int i = 1; i < cItemsList.Length; i++)
            {
                cItemsList[i] = maColls[i - 1].Items;
                pens[i]       = maColls[i - 1].Pen;
            }

            var collection = CreateCollection(id, cItemsList, pens);

            price.SetMainCollection(collection);
            SetAttritues();
            price.ForceDraw(true);
        }
Beispiel #2
0
        private async Task QueryChartOverlapCollection(string id, string id2)
        {
            var chartItems = await loader.GetChartItems(id);

            if (chartItems == null || !chartItems.Any())
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var chartItems2 = await loader.GetChartItems(id2);

            if (chartItems2 == null || !chartItems2.Any())
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var collection  = CreateCollection(id, chartItems, ChartItemType.Linear, DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), null);
            var collection2 = CreateCollection(id2, chartItems2, ChartItemType.Linear, DrawingObjectFactory.CreatePen(model.FallBrush, 1), null);

            price.SetMainCollection(collection);
            SetAttritues();
            price.AddAssistCollection(collection2, true);
            price.ForceDraw(true);
        }
Beispiel #3
0
        private async Task QueryCandleComparisonCollection(string id, string id2)
        {
            var svItems = await loader.GetStockItems(id);

            if (svItems == null || svItems.Prices == null)
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var chartItems2 = await loader.GetChartItems(id2);

            if (chartItems2 == null || !chartItems2.Any())
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var collection = CreateCollection(id, svItems.Prices, chartItems2, ChartItemType.Candle,
                                              DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), DrawingObjectFactory.CreatePen(model.FallBrush, 1),
                                              new IPen[] { DrawingObjectFactory.CreatePen(model.ContrastBrush, 1) }
                                              );

            price.SetMainCollection(collection);
            SetAttritues();
            price.CoordinateType = CoordinateType.Percentage;
            price.ForceDraw(true);
        }
Beispiel #4
0
        private async Task QueryTimeCollection(string id)
        {
            var svItems = await Timeloader.GetStockItems(id);

            if (svItems == null || svItems.Prices == null || svItems.Volumns == null)
            {
                Debug.WriteLine("Can not load candle items");
                return;
            }

            var collection = CreateCollection(id, svItems.Prices, ChartItemType.Time,
                                              DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), null);

            price.SetMainCollection(collection);
            SetAttritues(false);
            var idAverage = id + "average";
            var cItems    = await Timeloader.GetChartItems(idAverage);

            if (cItems != null && cItems.Any())
            {
                var maCollection = CreateTimeMACollection(cItems, idAverage);
                price.AddAssistCollection(maCollection);
            }

            var vCollection = CreateCollection(id, svItems.Volumns, ChartItemType.TimeVolumn,
                                               DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), DrawingObjectFactory.CreatePen(model.FallBrush, 1));

            volumn.SetMainCollection(vCollection);
            volumn.AddConnection(price);
            price.ForceDraw(true);
        }
Beispiel #5
0
        private async Task QueryCandleTrading(string id)
        {
            var svItems = await loader.GetStockItems(id);

            if (svItems == null || svItems.Prices == null || svItems.Volumns == null)
            {
                Debug.WriteLine("Can not load candle items");
                return;
            }

            var collection = CreateCollection(id, svItems.Prices, ChartItemType.Candle,
                                              DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), DrawingObjectFactory.CreatePen(model.FallBrush, 1));

            price.SetMainCollection(collection);
            SetAttritues();

            var maCollections = CreateMACollections(svItems.Prices);

            foreach (var maColl in maCollections)
            {
                price.AddAssistCollection(maColl);
            }

            var vCollection = CreateCollection(id, svItems.Volumns, ChartItemType.Volumn,
                                               DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), DrawingObjectFactory.CreatePen(model.FallBrush, 1));

            volumn.SetMainCollection(vCollection);
            volumn.AddConnection(price);

            price.ForceDraw();

            CandleTrading(id, collection, vCollection, price.AssistCollections, svItems);
        }
        public void DrawExtraData(ChartControl chartSource, IDrawingContext dc)
        {
            var dataSource = chartSource.MainCollection;

            if (dataSource == null)
            {
                return;
            }

            var items = dataSource.Items;

            int iStart = dataSource.FirstVisibleItemIndex;
            int count  = dataSource.VisiableItemCount;

            IPen pen = DrawingObjectFactory.CreatePen(Forground, 1);

            var xMid = dataSource.ItemXDistance / 2;

            startY        = -1;
            internalIndex = -1;
            XRItems       = null;
            for (int i = iStart; i < iStart + count; i++)
            {
                var item = dataSource.Items[i];
                if (item.ExtraData == null)
                {
                    continue;
                }

                var xhHistory = item.ExtraData.Get(ExtraDataNames.XRName) as ExitRight;
                if (xhHistory != null)
                {
                    var x = dataSource.GetItemPositionX(i, ChartItemCollection.ValueName);

                    if (startY == -1)
                    {
                        startY  = dataSource.ChartRegion.Bottom - height;
                        XRItems = new List <XRItem>();
                    }
                    XRItems.Add(new XRItem()
                    {
                        X       = x,
                        Index   = i,
                        toolTip = xhHistory.ToString()
                    });

                    x = PointSnapper.SnapValue(x + xMid);

                    var point1 = new Point(x, dataSource.ChartRegion.Bottom);
                    var point2 = new Point(x, dataSource.ChartRegion.Bottom - 2);

                    dc.DrawLine(pen, point1, point2);

                    point1 = new Point(x, dataSource.ChartRegion.Bottom - 5);

                    dc.DrawEllipse(Forground, null, point1, radius, radius);
                }
            }
        }
Beispiel #7
0
        public MainWindow()
        {
            InitializeComponent();

            raisePen = DrawingObjectFactory.CreatePen(Brushes.Red, 1);
            fallPen  = DrawingObjectFactory.CreatePen(Brushes.Green, 1);

            contrastPen = DrawingObjectFactory.CreatePen(Brushes.Black, 1);

            DataContext = ViewModel = new MainViewModel();

            RenderOptions.SetEdgeMode(this, EdgeMode.Aliased);
        }
Beispiel #8
0
        public void CreateCurve()
        {
            string id = "000001";
            //Load chart items
            IList <ChartItem> chartItems = loader.GetChartItems(id);
            //Create collection id
            CollectionId collId = new CollectionId(id);

            //Create pen
            IPen pen = DrawingObjectFactory.CreatePen(Brushes.Black, 1);
            //Create chart item collection
            ChartItemCollection collection = new ChartItemCollection(collId, chartItems, pen, null);

            //Set main collection
            priceControl.SetMainCollection(collection);
        }
Beispiel #9
0
        private void QueryChartCollection(string id)
        {
            var chartItems = loader.GetChartItems(id);

            if (chartItems == null || !chartItems.Any())
            {
                Debug.WriteLine("Can not load chart items");
                return;
            }

            var collection = CreateCollection(id, chartItems, ChartItemType.Linear, DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), null);

            price.SetMainCollection(collection);
            SetAttritues();
            price.ForceDraw();
        }
Beispiel #10
0
        private async Task QueryTimeTrading(string id)
        {
            var cOldItems = await loader.GetChartItems(id);

            if (cOldItems == null || !cOldItems.Any())
            {
                Debug.WriteLine("Can not load old candle items");
                return;
            }

            var oldItem = cOldItems.Last();

            var collection = CreateCollection(id, null, ChartItemType.Time,
                                              DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), null) as SymmetricChartItemCollection;

            collection.StartDate  = oldItem.Date.Date;
            collection.StartValue = oldItem.Value;


            price.SetMainCollection(collection);
            SetAttritues(false);

            var maColl = CreateCollection(id, null, ChartItemType.Time,
                                          DrawingObjectFactory.CreatePen(model.ContrastBrush, 1), null) as SymmetricChartItemCollection;

            maColl.StartDate  = oldItem.Date.Date;
            maColl.StartValue = oldItem.Value;

            price.AddAssistCollection(maColl);

            var vCollection = CreateCollection(id, null, ChartItemType.TimeVolumn,
                                               DrawingObjectFactory.CreatePen(model.RaiseBrush, 1), DrawingObjectFactory.CreatePen(model.FallBrush, 1)) as SymmetricVolumnItemCollection;

            vCollection.StartDate = oldItem.Date.Date;

            volumn.SetMainCollection(vCollection);
            price.AddConnection(volumn);
            price.ForceDraw();

            model.Date = oldItem.Date.ToString(dateFormat);

            await TimeTrading(id);
        }
Beispiel #11
0
        public IEnumerable <ChartItemCollection> CreateMACollections(List <StockItem> chartItems, int mvStart = 0)
        {
            for (int i = mvStart; i < mvStart + mvCount; i++)
            {
                var maPeriod = mvUnits[i];
                var maData   = MA(maPeriod, chartItems);

                List <ChartItem> mvItems = new List <ChartItem>(maData.Count);
                for (int j = 0; j < maData.Count; j++)
                {
                    mvItems.Add(new ChartItem()
                    {
                        Value = maData[j], Date = chartItems[j + maPeriod - 1].Date
                    });
                }

                var id = new CollectionId(maPeriod.ToString());
                ChartItemCollection collMa = new ChartItemCollection(id, mvItems, DrawingObjectFactory.CreatePen(mvBrushs[i], 1), null, true, false);
                yield return(collMa);
            }
        }
Beispiel #12
0
        public MultipleChartItemCollection CreateMultipleStatisticCollection()
        {
            const int size = 4;

            CollectionId id = new CollectionId("AveragePE", "SZ");

            var mItemList = CreateMultipleChartItemList(size);

            Brush[] brushes = new Brush[size] {
                Brushes.Black, Brushes.Red, Brushes.Blue, Brushes.Yellow
            };
            IPen[] pens = new IPen[brushes.Length];

            for (int i = 0; i < brushes.Length; i++)
            {
                pens[i] = DrawingObjectFactory.CreatePen(brushes[i], 1);
            }

            MultipleChartItemCollection coll = new MultipleChartItemCollection(id, mItemList, pens, true);

            return(coll);
        }
Beispiel #13
0
        public void CreateCandle()
        {
            string id = "000001";
            //Load chart items
            StockVolumnList svList = loader.GetStockItems(id);
            //Create collection id
            CollectionId collId = new CollectionId(id);
            //Create pens
            IPen raisePen = DrawingObjectFactory.CreatePen(Brushes.Red, 1);
            IPen fallPen  = DrawingObjectFactory.CreatePen(Brushes.Green, 1);
            //Create stock item collection
            StockItemCollection stockColl = new StockItemCollection(collId, svList.Prices, raisePen, fallPen, null);

            //Set main collection
            priceControl.SetMainCollection(stockColl);
            //Create volumn item collection
            VolumnItemCollection volumnColl = new VolumnItemCollection(collId, svList.Volumns, raisePen, fallPen);

            //Set main collection
            volumnControl.SetMainCollection(volumnColl);
            //Connect two controls
            priceControl.AddConnection(volumnControl);
        }
Beispiel #14
0
        private void CreateChartView(Stock stock, string marketId)
        {
            if (stock != null)
            {
                var closeList = stock.Items.Select(cd => new ChartItem()
                {
                    Value = cd.close, Date = cd.DateTime
                }).ToList();
                CollectionId        id   = new CollectionId(stock.id, marketId);
                ChartItemCollection coll = new ChartItemCollection(id, closeList, raisePen, null, true, isDynamic);

                price.SetMainCollection(coll);

                for (int i = mvStart; i < mvStart + mvCount; i++)
                {
                    var maPeriod = mvUnits[i];
                    var ma60     = stock.MA(maPeriod);

                    List <ChartItem> mv60Items = new List <ChartItem>(ma60.Count);
                    for (int j = 0; j < ma60.Count; j++)
                    {
                        mv60Items.Add(new ChartItem()
                        {
                            Value = ma60[j], Date = stock.Data[j + maPeriod - 1].DateTime
                        });
                    }

                    id = new CollectionId(stock.id, marketId);
                    ChartItemCollection collMa60 = new ChartItemCollection(id, mv60Items,
                                                                           DrawingObjectFactory.CreatePen(mvBrushs[i], 1), null, true, isDynamic);

                    price.AddAssistCollection(collMa60);
                }

                price.ForceDraw();
            }
        }
Beispiel #15
0
        private void CreateChartViewInMultipleChartItemCollectionPercentage(List <Stock> stocks, string marketId)
        {
            if (stocks != null)
            {
                var multItemList = CreateFrom(stocks);

                CollectionId id   = new CollectionId(stocks.FirstOrDefault().id, marketId);
                List <IPen>  pens = new List <IPen>();
                pens.Add(DrawingObjectFactory.CreatePen(Brushes.Black, 1));
                pens.AddRange(mvBrushs.Skip(mvStart).Take(mvCount).Select(mvBrush => DrawingObjectFactory.CreatePen(mvBrush, 1)));
                MultipleChartItemCollection multipleColl = new MultipleChartItemCollection(id, multItemList, pens.ToArray(), true, false);
                price.SetMainCollection(multipleColl);
            }
            else
            {
                price.SetMainCollection(null);
                volumn.SetMainCollection(null);
            }
            price.YScaleDock  = YScaleDock.Right;
            volumn.YScaleDock = YScaleDock.Right;
            price.AddConnection(volumn);

            price.ForceDraw();
        }
Beispiel #16
0
        public void CreateTime()
        {
            string id = "600100";

            StockVolumnList svList = timeLoader.GetStockItems(id);

            //Create collection id
            CollectionId collId = new CollectionId(id);
            //Create pens
            IPen raisePen = DrawingObjectFactory.CreatePen(Brushes.Red, 1);
            IPen fallPen  = DrawingObjectFactory.CreatePen(Brushes.Green, 1);
            //Create stock item collection
            SymmetricChartItemCollection stockColl = new SymmetricChartItemCollection(collId, svList.Prices, raisePen, null, SymmetricCommonSettings.CNSettings);

            //Set main collection
            priceControl.SetMainCollection(stockColl);
            //Create volumn item collection
            SymmetricVolumnItemCollection volumnColl = new SymmetricVolumnItemCollection(collId, svList.Volumns, raisePen, fallPen, SymmetricCommonSettings.CNSettings);

            //Set main collection
            volumnControl.SetMainCollection(volumnColl);
            //Connect two controls
            priceControl.AddConnection(volumnControl);
        }
Beispiel #17
0
        private ChartItemCollection CreateTimeMACollection(List <ChartItem> cItems, string id)
        {
            CollectionId cId = new CollectionId(id);

            return(CreateChartItemCollection(ChartItemType.Time, cItems, cId, DrawingObjectFactory.CreatePen(model.FallBrush, 1), null));
        }
Beispiel #18
0
        private void CreateCandleView(Stock stock, string marketId)
        {
            if (stock != null)
            {
                var        closeList = new List <StockItem>();
                var        volList   = new List <VolumnItem>();
                CandleData cdPre     = stock.Items.FirstOrDefault();
                foreach (var cd in stock.Items)
                {
                    closeList.Add(new StockItem()
                    {
                        Value       = cd.close,
                        Date        = cd.DateTime,
                        High        = cd.high,
                        Low         = cd.low,
                        Open        = cd.open,
                        CloseChange = (cd.close - cdPre.close) / cdPre.close
                    });

                    cdPre = cd;

                    volList.Add(new VolumnItem()
                    {
                        Date     = cd.DateTime,
                        IsRaise  = cd.open <= cd.close,
                        Volumn   = cd.amount,
                        Turnover = cd.money
                    });
                }

                CollectionId        id   = new CollectionId(stock.id, marketId);
                StockItemCollection coll = new StockItemCollection(id, closeList, raisePen, fallPen, null, isDynamic);
                //coll.ItemStyle = StockItemStyle.Linear;

                price.SetMainCollection(coll);

                for (int i = mvStart; i < mvStart + mvCount; i++)
                {
                    var maPeriod = mvUnits[i];
                    var ma60     = stock.MA(maPeriod);

                    List <ChartItem> mv60Items = new List <ChartItem>(ma60.Count);
                    for (int j = 0; j < ma60.Count; j++)
                    {
                        mv60Items.Add(new ChartItem()
                        {
                            Value = ma60[j], Date = stock.Data[j + maPeriod - 1].DateTime
                        });
                    }

                    id = new CollectionId(stock.id, marketId);
                    ChartItemCollection collMa60 = new ChartItemCollection(id, mv60Items, DrawingObjectFactory.CreatePen(mvBrushs[i], 1), null, true);

                    price.AddAssistCollection(collMa60);
                }

                id = new CollectionId(stock.id, marketId);
                VolumnItemCollection volColl = new VolumnItemCollection(id, volList, raisePen, fallPen, isDynamic);
                //volColl.VolumnItemStyle = VolumnItemStyle.Linear;
                volumn.SetMainCollection(volColl);
            }
            else
            {
                price.SetMainCollection(null);
                volumn.SetMainCollection(null);
            }
            price.YScaleDock  = YScaleDock.Left;
            volumn.YScaleDock = YScaleDock.Left;
            price.AddConnection(volumn);

            price.ForceDraw();
        }
Beispiel #19
0
        private void CreateCandleViewInSignleStockItemCollection(Stock stock, string marketId)
        {
            if (stock != null)
            {
                var        multItemList = new List <StockValuesItem>();
                var        volList      = new List <VolumnItem>();
                CandleData cdPre        = stock.Items.FirstOrDefault();
                foreach (var cd in stock.Items)
                {
                    multItemList.Add(new StockValuesItem()
                    {
                        Value       = cd.close,
                        Date        = cd.DateTime,
                        High        = cd.high,
                        Low         = cd.low,
                        Open        = cd.open,
                        CloseChange = (cd.close - cdPre.close) / cdPre.close,
                        Values      = new List <double>(mvCount)
                    });

                    volList.Add(new VolumnItem()
                    {
                        Date     = cd.DateTime,
                        IsRaise  = cd.open <= cd.close,
                        Volumn   = cd.amount,
                        Turnover = cd.money
                    });

                    cdPre = cd;
                }

                for (int i = mvStart; i < mvStart + mvCount; i++)
                {
                    var maPeriod = mvUnits[i];
                    var maN      = stock.MA(maPeriod);

                    if (!maN.Any())
                    {
                        continue;
                    }

                    int iInvalidCount = maPeriod - 1;

                    for (int j = 0; j < iInvalidCount; j++)
                    {
                        var mItem = multItemList[j];
                        mItem.Values.Add(ChartItemCollection.valueNA);
                    }

                    List <ChartItem> mv60Items = new List <ChartItem>(maN.Count);
                    for (int j = 0; j < maN.Count; j++)
                    {
                        var mItem = multItemList[j + iInvalidCount];
                        mItem.Values.Add(maN[j]);
                    }
                }
                CollectionId id   = new CollectionId(stock.id, marketId);
                List <IPen>  pens = new List <IPen>(mvBrushs.Skip(mvStart).Take(mvCount).Select(mvBrush => DrawingObjectFactory.CreatePen(mvBrush, 1)));
                StockValuesItemCollection multipleColl = new StockValuesItemCollection(id, multItemList, raisePen, fallPen, null, pens.ToArray(), false);
                price.SetMainCollection(multipleColl);

                VolumnItemCollection volColl = new VolumnItemCollection(id, volList, raisePen, fallPen, isDynamic);
                //volColl.VolumnItemStyle = VolumnItemStyle.Linear;
                volumn.SetMainCollection(volColl);
            }
            else
            {
                price.SetMainCollection(null);
                volumn.SetMainCollection(null);
            }
            price.YScaleDock  = YScaleDock.Right;
            volumn.YScaleDock = YScaleDock.Right;
            price.AddConnection(volumn);

            price.ForceDraw();
        }
Beispiel #20
0
        public bool NextDraw(Point pt, IDrawingContext dc, bool isFinal)
        {
            Points[1] = pt;

            double radius = Math.Atan((Points[1].X - Points[0].X) / (Points[0].Y - Points[1].Y));
            double degree = radius * 180 / Math.PI;

            if (degree < 0)
            {
                if (Points[1].X > Points[0].X)
                {
                    degree = 180 + degree;
                }
            }
            else
            {
                if (Points[1].X < Points[0].X)
                {
                    degree = 180 + degree;
                }
            }

            IPen pen = DrawingObjectFactory.CreatePen(MeasureColor, MeasureThickness);

            if (MeasureDashes != null)
            {
                pen.Dashes = MeasureDashes;
            }
            //Trace.WriteLine(radius + "," + degree);
            RotateTransform transferm = new RotateTransform()
            {
                Angle   = degree,
                CenterX = Points[0].X,
                CenterY = Points[0].Y
            };

            dc.PushTransform(transferm);
            Point pt1 = new Point(Points[0].X + 3, Points[0].Y);
            Point pt2 = new Point(Points[0].X - 3, Points[0].Y);

            dc.DrawLine(pen, pt1, pt2);

            double value = -Math.Sqrt(Math.Abs(Points[0].X - Points[1].X) * Math.Abs(Points[0].X - Points[1].X) + Math.Abs(Points[0].Y - Points[1].Y) * Math.Abs(Points[0].Y - Points[1].Y));
            Point  pt3   = new Point(Points[0].X, Points[0].Y + value);

            dc.DrawLine(pen, Points[0], pt3);

            pt1 = new Point(Points[0].X + 3, Points[0].Y + value);
            pt2 = new Point(Points[0].X - 3, Points[0].Y + value);
            dc.DrawLine(pen, pt1, pt2);

            dc.Pop();

            ITextFormat format = DrawingObjectFactory.CreateTextFormat(measureValue.ToString("P2"), FlowDirection, FontFamily, FontStyle, FontWeight, FontStretch, FontSize, Foreground);

            Point ptText = Points[1];

            ptText.Y -= format.Height;
            dc.DrawText(format, ptText);
            return(false);
        }
Beispiel #21
0
        public IEnumerable <ChartItemCollection> CreateMVCollections()
        {
            for (int i = mvStart; i < mvStart + mvCount; i++)
            {
                var maPeriod = mvUnits[i];
                var ma60     = currentStock.MA(maPeriod);

                List <ChartItem> mv60Items = new List <ChartItem>(ma60.Count);
                for (int j = 0; j < ma60.Count; j++)
                {
                    mv60Items.Add(new ChartItem()
                    {
                        Value = ma60[j], Date = currentStock.Data[j + maPeriod - 1].DateTime
                    });
                }

                var id = new CollectionId(currentStock.id, GetMarketId());
                ChartItemCollection collMa60 = new ChartItemCollection(id, mv60Items, DrawingObjectFactory.CreatePen(mvBrushs[i], 1), null, true, false);
                yield return(collMa60);
            }
        }