Пример #1
0
        private void LoadDataSettingsFile(string fileName)
        {
            _stockDataSettings = ChinaStockDataSettings.LoadFromFile(fileName);

            _stockNameTable = new StockNameTable(_stockDataSettings.StockNameTableFile);

            // fill the codes and names to grid view
            var stockProperties = _stockNameTable.StockNames
                                  .Select(sn => new StockProperty()
            {
                Code = sn.Code,
                Name = string.Join("|", sn.Names)
            })
                                  .OrderBy(sp => sp.Code)
                                  .ToArray();

            dataGridViewCodes.DataSource = new SortableBindingList <StockProperty>(stockProperties);

            // reset data accessor (cache)
            ChinaStockDataAccessor.Reset();
        }
Пример #2
0
        public MainForm()
        {
            InitializeComponent();

            dataGridViewCodes.AutoGenerateColumns = false;
            ColumnCodesCode.DataPropertyName      = "Code";
            ColumnCodesName.DataPropertyName      = "Name";

            dataGridViewClosedPosition.AutoGenerateColumns = false;
            ColumnPositionCode.DataPropertyName            = "Code";
            ColumnPositionName.DataPropertyName            = "Name";
            ColumnPositionBuyTime.DataPropertyName         = "BuyTime";
            ColumnPositionBuyPrice.DataPropertyName        = "BuyPrice";
            ColumnPositionSellTime.DataPropertyName        = "SellTime";
            ColumnPositionSellPrice.DataPropertyName       = "SellPrice";
            ColumnPositionVolume.DataPropertyName          = "Volume";
            ColumnPositionGain.DataPropertyName            = "Gain";
            ColumnPositionR.DataPropertyName = "R";

            // initialize data accessor (cache)
            ChinaStockDataAccessor.Initialize();
        }
Пример #3
0
        private void ShowStockData(string code, DateTime startTime, DateTime endTime, bool addAnnotation)
        {
            string file = _stockDataSettings.BuildActualDataFilePathAndName(code);

            StockHistoryData data;

            try
            {
                data = ChinaStockDataAccessor.Load(file, _stockNameTable);
            }
            catch (Exception ex)
            {
                ShowError("Load data file failed", ex);
                return;
            }

            // update label of code
            labelCode.Text = code;

            var stockSeries  = chartData.Series[StockSeriesIndex];
            var volumeSeries = chartData.Series[VolumeSeriesIndex];
            var chartArea    = chartData.ChartAreas[ChartAreaIndex];

            var bars = data.DataOrderedByTime;

            if (bars == null || bars.Count() == 0)
            {
                stockSeries.Points.Clear();
                volumeSeries.Points.Clear();
                return;
            }

            // add data to chart
            if (data != _currentShownData)
            {
                _currentShownData = data;

                stockSeries.Points.Clear();
                volumeSeries.Points.Clear();

                for (int i = 0; i < bars.Length; ++i)
                {
                    var bar = bars[i];
                    stockSeries.Points.AddXY(
                        bar.Time,
                        bar.HighestPrice,
                        bar.LowestPrice,
                        bar.OpenPrice,
                        bar.ClosePrice);

                    volumeSeries.Points.AddXY(bar.Time, bar.Volume);
                }
            }

            // calculate the index of start time and end time in data
            int startIndex = GetIndexOfTimeInBars(bars, startTime);
            int endIndex   = GetIndexOfTimeInBars(bars, endTime);

            if (startIndex > endIndex)
            {
                int temp = startIndex;
                startIndex = endIndex;
                endIndex   = temp;
            }

            // create scale view to cover start time and end time
            int position = startIndex - SurroundDataPointCount;
            int size     = endIndex - startIndex + SurroundDataPointCount * 2;

            position = Math.Max(0, position);
            size     = Math.Min(Math.Max(MinScaleViewSize, size), bars.Length);

            if (size + position > bars.Length)
            {
                position = bars.Length - size;
            }

            chartArea.AxisX.ScaleView = new System.Windows.Forms.DataVisualization.Charting.AxisScaleView()
            {
                Position = position,
                Size     = size
            };

            // adjust view to accomendate the scale
            AdjustChartView();

            // add annotation
            var startAnnotation = chartData.Annotations[StartAnnotationIndex];
            var endAnnotation   = chartData.Annotations[EndAnnotationIndex];

            if (addAnnotation)
            {
                //startAnnotation.AnchorDataPoint = stockSeries.Points[startIndex];
                //endAnnotation.AnchorDataPoint = stockSeries.Points[endIndex];

                startAnnotation.AnchorX = startIndex + 1;
                startAnnotation.AnchorY = bars[startIndex].LowestPrice;
                endAnnotation.AnchorX   = endIndex + 1;
                endAnnotation.AnchorY   = bars[endIndex].HighestPrice;

                startAnnotation.Visible = true;
                endAnnotation.Visible   = true;
            }
            else
            {
                //startAnnotation.AnchorDataPoint = null;
                //endAnnotation.AnchorDataPoint = null;

                startAnnotation.AnchorX = 0;
                startAnnotation.AnchorY = 0;
                endAnnotation.AnchorX   = 0;
                endAnnotation.AnchorY   = 0;

                startAnnotation.Visible = false;
                endAnnotation.Visible   = false;
            }

            chartData.Invalidate();
            chartData.Update();
        }