Пример #1
0
        protected virtual Series CreateCandleStickSeries(StrategyDataItemInfo info)
        {
            Series s = new Series("Kline", ViewType.CandleStick);

            s.ArgumentDataMember = "Time";
            s.ArgumentScaleType  = ScaleType.DateTime;
            s.ValueDataMembers.AddRange("Low", "High", "Open", "Close");
            s.ValueScaleType = ScaleType.Numerical;

            CandleStickSeriesView view = new CandleStickSeriesView();

            view.LineThickness              = (int)(info.GraphWidth * DpiProvider.Default.DpiScaleFactor);
            view.LevelLineLength            = 0.25;
            view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            view.ReductionOptions.FillMode  = CandleStickFillMode.AlwaysFilled;
            view.Color = DXSkinColors.ForeColors.Information;
            view.ReductionOptions.Color = DXSkinColors.ForeColors.Critical;

            view.ReductionOptions.Level   = StockLevel.Open;
            view.ReductionOptions.Visible = true;
            view.AggregateFunction        = SeriesAggregateFunction.None;
            view.LineThickness            = (int)(1 * DpiProvider.Default.DpiScaleFactor);
            view.LevelLineLength          = 0.25;

            s.View = view;
            s.CrosshairLabelPattern = "O={OV}\nH={HV}\nL={LV}\nC={CV}";
            s.DataSource            = GetDataSource(info);
            return(s);
        }
Пример #2
0
        void UpdateChart()
        {
            if (Ticker == null)
            {
                return;
            }
            SuppressUpdateCandlestickData = true;
            try {
                if (!Ticker.Exchange.SupportBuySellVolume)
                {
                    this.chartControl1.Series["BuySellVolume"].DataSource = null;
                    ((XYDiagram)this.chartControl1.Diagram).Panes["Volume Pane"].Visibility = ChartElementVisibility.Hidden;
                }
                else
                {
                    ((XYDiagram)this.chartControl1.Diagram).Panes["VolumePane"].Visibility = ChartElementVisibility.Collapsed;
                    this.chartControl1.Series["BuySellVolume"].DataSource = new RealTimeSource()
                    {
                        DataSource = Ticker.CandleStickData
                    };
                    this.chartControl1.Series["BuySellVolume"].ArgumentDataMember = "Time";
                    this.chartControl1.Series["BuySellVolume"].ValueDataMembers.AddRange("BuySellVolume");
                }

                CandleStickSeriesView sv = (CandleStickSeriesView)this.chartControl1.Series["Current"].View;
                sv.Color = Exchange.CandleStickColor;
                sv.ReductionOptions.Color = Exchange.CandleStickReductionColor;


                this.chartControl1.Series["Volume"].ArgumentDataMember = "Time";
                this.chartControl1.Series["Volume"].ValueDataMembers.AddRange("Volume");

                this.chartMarketDepth.Series["TotalVolumeBuy"].DataSource         = Ticker.OrderBook.Bids;
                this.chartMarketDepth.Series["TotalVolumeBuy"].ArgumentDataMember = "Value";
                this.chartMarketDepth.Series["TotalVolumeBuy"].ValueDataMembers.AddRange("VolumeTotal");

                this.chartMarketDepth.Series["TotalVolumeSell"].DataSource         = Ticker.OrderBook.Asks;
                this.chartMarketDepth.Series["TotalVolumeSell"].ArgumentDataMember = "Value";
                this.chartMarketDepth.Series["TotalVolumeSell"].ValueDataMembers.AddRange("VolumeTotal");

                this.chartWalls.Series["Sell volume"].DataSource         = Ticker.OrderBook.Asks;
                this.chartWalls.Series["Sell volume"].ArgumentDataMember = "Value";
                this.chartWalls.Series["Sell volume"].ValueDataMembers.AddRange("Volume");
                this.chartWalls.Series["Sell volume"].View.Color = Exchange.AskColor;

                this.chartWalls.Series["Buy volume"].DataSource         = Ticker.OrderBook.Bids;
                this.chartWalls.Series["Buy volume"].ArgumentDataMember = "Value";
                this.chartWalls.Series["Buy volume"].ValueDataMembers.AddRange("Volume");
                this.chartWalls.Series["Buy volume"].View.Color = Exchange.BidColor;

                ConfigurateChart(ViewType.CandleStick);
                ((XYDiagram)this.chartControl1.Diagram).AxisX.VisualRange.SetMinMaxValues(DateTime.UtcNow.AddMinutes(-Ticker.CandleStickPeriodMin * CalculateCandlestickBestFit()), DateTime.UtcNow);
                ((XYDiagram)this.chartMarketDepth.Diagram).AxisX.VisualRange.SetMinMaxValues(0, 2 * GetMinRangeFromBidAsk());
                ((XYDiagram)this.chartWalls.Diagram).AxisX.VisualRange.SetMinMaxValues(0, 2 * GetMinRangeFromBidAsk());
                UpdateEvents(null);
            }
            finally {
                SuppressUpdateCandlestickData = false;
            }
        }
Пример #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Create a new chart.
            ChartControl candlestickChart = new ChartControl();

            // Create a candlestick series.
            Series series1 = new Series("Series 1", ViewType.CandleStick);

            // Bind the series to data.
            series1.DataSource = GetDataPoints();
            series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close");

            // Specify that date-time arguments are expected.
            series1.ArgumentScaleType = ScaleType.DateTime;

            // Add the series to the chart.
            candlestickChart.Series.Add(series1);

            // Customize the series view settings.
            CandleStickSeriesView view = (CandleStickSeriesView)series1.View;

            view.LineThickness   = 2;
            view.LevelLineLength = 0.25;

            // Specify the series reduction options.
            view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            view.ReductionOptions.FillMode  = CandleStickFillMode.AlwaysEmpty;
            view.ReductionOptions.Level     = StockLevel.Close;
            view.ReductionOptions.Visible   = true;

            // Set point colors.
            view.Color = Color.Green;
            view.ReductionOptions.Color = Color.Red;

            // Access the chart's diagram.
            XYDiagram diagram = (XYDiagram)candlestickChart.Diagram;

            // Exclude empty ranges from the X-axis range
            // to avoid gaps in the chart's data.
            diagram.AxisX.DateTimeScaleOptions.SkipRangesWithoutPoints = true;

            // Hide the range without points at the beginning of the y-axis.
            diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;

            // Hide the legend.
            candlestickChart.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

            // Add a title to the chart.
            candlestickChart.Titles.Add(new ChartTitle());
            candlestickChart.Titles[0].Text = "Candlestick Chart";

            // Add the chart to the form.
            candlestickChart.Dock = DockStyle.Fill;
            this.Controls.Add(candlestickChart);
        }
        void UpdateChart()
        {
            if (Ticker == null)
            {
                return;
            }
            SuppressUpdateCandlestickData = true;
            try {
                this.chartControl1.Series["BuySellVolume"].DataSource = new RealTimeSource()
                {
                    DataSource = Ticker.CandleStickData
                };
                this.chartControl1.Series["BuySellVolume"].ArgumentDataMember = "Time";
                this.chartControl1.Series["BuySellVolume"].ValueDataMembers.AddRange("BuySellVolume");

                CandleStickSeriesView sv = (CandleStickSeriesView)this.chartControl1.Series["Current"].View;
                sv.Color = Exchange.CandleStickColor;
                sv.ReductionOptions.Color = Exchange.CandleStickReductionColor;


                this.chartControl1.Series["Volume"].ArgumentDataMember = "Time";
                this.chartControl1.Series["Volume"].ValueDataMembers.AddRange("Volume");

                this.chartMarketDepth.Series["TotalVolumeBuy"].DataSource         = Ticker.OrderBook.Bids;
                this.chartMarketDepth.Series["TotalVolumeBuy"].ArgumentDataMember = "Value";
                this.chartMarketDepth.Series["TotalVolumeBuy"].ValueDataMembers.AddRange("VolumeTotal");

                this.chartMarketDepth.Series["TotalVolumeSell"].DataSource         = Ticker.OrderBook.Asks;
                this.chartMarketDepth.Series["TotalVolumeSell"].ArgumentDataMember = "Value";
                this.chartMarketDepth.Series["TotalVolumeSell"].ValueDataMembers.AddRange("VolumeTotal");

                this.chartWalls.Series["Sell volume"].DataSource         = Ticker.OrderBook.Asks;
                this.chartWalls.Series["Sell volume"].ArgumentDataMember = "Value";
                this.chartWalls.Series["Sell volume"].ValueDataMembers.AddRange("Volume");
                this.chartWalls.Series["Sell volume"].View.Color = Exchange.AskColor;

                this.chartWalls.Series["Buy volume"].DataSource         = Ticker.OrderBook.Bids;
                this.chartWalls.Series["Buy volume"].ArgumentDataMember = "Value";
                this.chartWalls.Series["Buy volume"].ValueDataMembers.AddRange("Volume");
                this.chartWalls.Series["Buy volume"].View.Color = Exchange.BidColor;

                ConfigurateChart(ViewType.CandleStick);
                UpdateEvents(null);
            }
            finally {
                SuppressUpdateCandlestickData = false;
            }
        }
Пример #5
0
        public void DrawingStockChart(ChartControl chartControl, IEnumerable <IOhlcv> oneOfStkHistoryPrice)
        {
            //設定price candle stick顏色
            CandleStickSeriesView priceSeriesView = (CandleStickSeriesView)chartControl.Series["Price"].View;

            priceSeriesView.Color = Color.Red;
            priceSeriesView.ReductionOptions.Color = Color.Green;
            //加入price資料
            chartControl.Series["Price"].DataSource         = oneOfStkHistoryPrice;
            chartControl.Series["Price"].ArgumentDataMember = "DateTime.DateTime";
            chartControl.Series["Price"].ValueDataMembers.AddRange(new string[] { "Low", "High", "Open", "Close" });
            //加入volume資料
            chartControl.Series["Volume"].DataSource         = oneOfStkHistoryPrice;
            chartControl.Series["Volume"].ArgumentDataMember = "DateTime.DateTime";
            chartControl.Series["Volume"].ValueDataMembers.AddRange(new string[] { "Volume" });
        }
Пример #6
0
        private void BindCharts(dynamic form, BindingList <CandleData> bindingList)
        {
            // Create a new chart.

            var max = bindingList.Max(m => m.High);
            var min = bindingList.Min(m => m.Low);
            // Create a candlestick series.
            Series series1 = new Series("Stock Prices", ViewType.CandleStick);

            // Specify the date-time argument scale type for the series,
            // as it is qualitative, by default.
            series1.ArgumentScaleType = ScaleType.DateTime;

            series1.ArgumentDataMember = "MTS";
            series1.ValueDataMembers.AddRange(new string[] { "Low", "High", "Open", "Close" });

            // Add the series to the chart.
            form.chart1.Series.Add(series1);
            form.chart1.Series["Stock Prices"].DataSource = bindingList;
            // Access the view-type-specific options of the series.
            CandleStickSeriesView myView = (CandleStickSeriesView)series1.View;

            myView.LineThickness   = 2;
            myView.LevelLineLength = 0.25;
            // Specify the series reduction options.
            myView.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            myView.ReductionOptions.FillMode  = CandleStickFillMode.FilledOnReduction;
            myView.ReductionOptions.Level     = StockLevel.Open;
            myView.ReductionOptions.Visible   = true;
            // Access the chart's diagram.
            XYDiagram diagram = ((XYDiagram)form.chart1.Diagram);

            // Access the type-specific options of the diagram.
            diagram.AxisY.WholeRange.MinValue         = min;
            diagram.AxisY.WholeRange.MaxValue         = max;
            diagram.AxisY.WholeRange.SideMarginsValue = 0.5;

            // Exclude weekends from the X-axis range,
            // to avoid gaps in the chart's data.
            diagram.AxisX.DateTimeScaleOptions.WorkdaysOnly = true;
        }
        protected virtual Series CreateCandleStickSeries(StrategyDataItemInfo info)
        {
            Series s = new Series("Kline", ViewType.CandleStick);

            s.ArgumentDataMember = "Time";
            s.ArgumentScaleType  = ScaleType.DateTime;
            s.ValueDataMembers.AddRange("Low", "High", "Open", "Close");
            s.ValueScaleType = ScaleType.Numerical;
            CandleStickSeriesView view = new CandleStickSeriesView();

            view.LineThickness              = (int)(info.GraphWidth * DpiProvider.Default.DpiScaleFactor);
            view.LevelLineLength            = 0.25;
            view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            view.ReductionOptions.FillMode  = CandleStickFillMode.FilledOnReduction;
            view.ReductionOptions.Level     = StockLevel.Open;
            view.ReductionOptions.Visible   = true;

            s.View       = view;
            s.DataSource = Strategy.StrategyData;
            return(s);
        }
Пример #8
0
        Series CreateCandleStickSeries()
        {
            Series s = new Series("Last", ViewType.CandleStick);

            s.ArgumentDataMember = "Time";
            s.ArgumentScaleType  = ScaleType.DateTime;
            s.ValueDataMembers.AddRange("Low", "High", "Open", "Close");
            s.ValueScaleType = ScaleType.Numerical;
            CandleStickSeriesView view = new CandleStickSeriesView();

            view.LineThickness              = 2;
            view.LevelLineLength            = 0.25;
            view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            view.ReductionOptions.FillMode  = CandleStickFillMode.FilledOnReduction;
            view.ReductionOptions.Level     = StockLevel.Open;
            view.ReductionOptions.Visible   = true;

            s.View       = view;
            s.DataSource = Ticker.CandleStickData;
            return(s);
        }
Пример #9
0
        private void ChartInit()
        {
            #region Chart

            ChartTitle chartTitle = new ChartTitle();
            //标题内容
            chartTitle.Text = "股票名称";
            //字体颜色
            chartTitle.TextColor = Color.White;
            //字体类型字号
            chartTitle.Font = new Font("新宋体", 11, FontStyle.Bold);
            //标题对齐方式
            chartTitle.Dock      = ChartTitleDockStyle.Top;
            chartTitle.Alignment = StringAlignment.Near;

            chartControl1.Titles.Clear();
            chartControl1.Titles.Add(chartTitle);

            chartControl1.BackColor = Color.Black;

            chartControl1.Legend.Visibility = DevExpress.Utils.DefaultBoolean.False;

            //RuntimeHitTesting设为True时,才可从ChartHitInfo中取得SeriesPoint
            chartControl1.RuntimeHitTesting = true;

            //_crosshairFreePosition1.DockTargetName = "Default Pane";
            //_crosshairFreePosition1.DockCorner = DockCorner.RightTop;
            //_crosshairFreePosition1.OffsetX = 50;
            //_crosshairFreePosition1.OffsetY = 30;

            //chartControl1.CrosshairOptions.CommonLabelPosition = _crosshairFreePosition1;
            chartControl1.CrosshairOptions.ShowValueLine      = true;
            chartControl1.CrosshairOptions.ShowValueLabels    = true;
            chartControl1.CrosshairOptions.ShowArgumentLine   = true;
            chartControl1.CrosshairOptions.ShowArgumentLabels = true;
            chartControl1.Cursor = Cursors.Default;

            #endregion Chart

            #region Series

            _seriesDayKLine = new Series("日行情", ViewType.CandleStick);
            _seriesDayKLine.ArgumentScaleType = ScaleType.Qualitative;

            _seriesDayKLine.CrosshairHighlightPoints = DevExpress.Utils.DefaultBoolean.False;
            CandleStickSeriesView myView = (CandleStickSeriesView)_seriesDayKLine.View;
            myView.Color                    = _redColor;
            myView.LineThickness            = 1;
            myView.LevelLineLength          = 0.15;
            myView.ReductionOptions.Level   = StockLevel.Close;
            myView.ReductionOptions.Color   = Color.FromArgb(102, 255, 255);
            myView.ReductionOptions.Visible = true;


            this.chartControl1.Series.Add(_seriesDayKLine);

            #endregion Series

            #region XYDiagram

            XYDiagram myDiagram = chartControl1.Diagram as XYDiagram;
            myDiagram.DefaultPane.BackColor   = Color.Black;
            myDiagram.DefaultPane.BorderColor = _redColor;
            myDiagram.DefaultPane.ScrollBarOptions.BackColor   = Color.Black;
            myDiagram.DefaultPane.ScrollBarOptions.BorderColor = _redColor;
            myDiagram.DefaultPane.ScrollBarOptions.BarColor    = _redColor;
            myDiagram.EnableAxisXScrolling = true;
            myDiagram.EnableAxisXZooming   = true;

            #endregion XYDiagram

            #region AxisX

            AxisX myAxisX = myDiagram.AxisX;
            myAxisX.Color           = _redColor;
            myAxisX.Label.TextColor = _redColor;
            myAxisX.Label.Staggered = false;
            //myAxisX.Label.TextPattern = "{A:MM/dd}";
            myAxisX.Label.Angle = -60;
            myAxisX.Label.EnableAntialiasing = DevExpress.Utils.DefaultBoolean.True;
            myAxisX.Tickmarks.MinorVisible   = false;
            //myAxisX.DateTimeScaleOptions.WorkdaysOnly = true;
            //myAxisX.DateTimeScaleOptions.ProcessMissingPoints = ProcessMissingPointsMode.Skip;
            //myAxisX.DateTimeScaleOptions.MeasureUnit = DateTimeMeasureUnit.Day;
            //myAxisX.DateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day;
            myAxisX.WholeRange.Auto = false;

            #endregion AxisX

            #region AxisY

            AxisY myAxisY = myDiagram.AxisY;
            myAxisY.Alignment                     = AxisAlignment.Far;
            myAxisY.Color                         = _redColor;
            myAxisY.Label.TextColor               = _redColor;
            myAxisY.Label.TextPattern             = "{V:F2}";
            myAxisY.GridLines.Color               = Color.FromArgb(165, 42, 42);
            myAxisY.GridLines.LineStyle.Thickness = 1;
            myAxisY.GridLines.LineStyle.DashStyle = DashStyle.Dot;
            myAxisY.Tickmarks.MinorVisible        = false;
            myAxisY.WholeRange.Auto               = false;

            #endregion AxisY
        }
        protected virtual Series CreateCandleStickSeries(StrategyDataItemInfo info)
        {
            Series s = new Series("Kline", ViewType.CandleStick);

            s.ArgumentDataMember = "Time";
            s.ArgumentScaleType  = ScaleType.DateTime;
            s.ValueDataMembers.AddRange("Low", "High", "Open", "Close");
            s.ValueScaleType = ScaleType.Numerical;

            CandleStickSeriesView view = new CandleStickSeriesView();

            view.LineThickness              = (int)(info.GraphWidth * DpiProvider.Default.DpiScaleFactor);
            view.LevelLineLength            = 0.25;
            view.ReductionOptions.ColorMode = ReductionColorMode.OpenToCloseValue;
            view.ReductionOptions.FillMode  = CandleStickFillMode.AlwaysFilled;
            view.Color = DXSkinColors.ForeColors.Information;
            view.ReductionOptions.Color = DXSkinColors.ForeColors.Critical;

            view.ReductionOptions.Level   = StockLevel.Open;
            view.ReductionOptions.Visible = true;
            view.AggregateFunction        = SeriesAggregateFunction.Financial;
            view.LineThickness            = (int)(1 * DpiProvider.Default.DpiScaleFactor);
            view.LevelLineLength          = 0.25;

            s.View = view;
            s.CrosshairLabelPattern = "O={OV}\nH={HV}\nL={LV}\nC={CV}";

            object           dataSource = GetDataSource(info);
            IResizeableArray array      = dataSource as IResizeableArray;

            if (array == null || array.Count < BigDataCount)
            {
                s.DataSource = dataSource;
            }
            else
            {
                SeriesPoint[] points = new SeriesPoint[array.Count];
                PropertyInfo  ap     = array.GetItem(0).GetType().GetProperty(s.ArgumentDataMember, BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo  lp     = array.GetItem(0).GetType().GetProperty("Low", BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo  hp     = array.GetItem(0).GetType().GetProperty("High", BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo  op     = array.GetItem(0).GetType().GetProperty("Open", BindingFlags.Public | BindingFlags.Instance);
                PropertyInfo  cp     = array.GetItem(0).GetType().GetProperty("Close", BindingFlags.Public | BindingFlags.Instance);

                Func <object, object> af = MakeAccessor(array.GetItem(0).GetType(), ap.PropertyType, s.ArgumentDataMember);
                Func <object, object> lf = MakeAccessor(array.GetItem(0).GetType(), lp.PropertyType, "Low");
                Func <object, object> hf = MakeAccessor(array.GetItem(0).GetType(), lp.PropertyType, "High");
                Func <object, object> of = MakeAccessor(array.GetItem(0).GetType(), lp.PropertyType, "Open");
                Func <object, object> cf = MakeAccessor(array.GetItem(0).GetType(), lp.PropertyType, "Close");

                if (ap.PropertyType == typeof(DateTime))
                {
                    for (int i = 0; i < array.Count; i++)
                    {
                        object item = array.GetItem(i);
                        points[i] = new SeriesPoint((DateTime)af(item),
                                                    new double[] {
                            (double)lf(item),
                            (double)hf(item),
                            (double)of(item),
                            (double)cf(item)
                        });
                    }
                }
                s.Points.AddRange(points);
            }

            //s.DataSource = GetDataSource(info);
            return(s);
        }