예제 #1
0
        /// <summary>
        /// Show chart with data series
        /// </summary>
        /// <param name="dataSeries"></param>
        public void LoadPriceChart(TradeRobotics.Model.StockDataSeries dataSeries)
        {
            //List<Bar> bars = dataSeries.Bars;
            Visifire.Charts.DataSeries ds = new DataSeries();
            ds.RenderAs            = RenderAs.CandleStick;
            ds.MarkerEnabled       = true;
            ds.MovingMarkerEnabled = true;
            ds.LightingEnabled     = true;
            ds.LineThickness       = 1.5;
            //ds.XValueType = ChartValueTypes.DateTime;
            ds.LegendText     = string.Concat(dataSeries.Symbol, " ", dataSeries.Period);
            ds.PriceUpColor   = new SolidColorBrush(Colors.Green);
            ds.PriceDownColor = new SolidColorBrush(Colors.Red);

            //PriceChart.AxesY[0].AxisMinimum = bars.Min(bar => bar.Low);
            //PriceChart.AxesY[0].AxisMaximum = bars.Max(bar => bar.High);
            PriceChart.AxesY[0].StartFromZero        = false;
            PriceChart.AxesY[0].ViewportRangeEnabled = true;

            if (dataSeries.Bars.Count > 0)
            {
                // Add points
                //for (int i = 0; i < dataSeries.Count; i++)
                foreach (Bar bar in dataSeries.Bars)
                {
                    ds.DataPoints.Add(new DataPoint
                    {
                        AxisXLabel = bar.Time.ToString("yyyy-MM-dd HH:mm"),
                        //ToolTipText = "aa\nbb",
                        //XValue = bar.Time, // a DateTime value
                        YValues = new double[] { bar.Open, bar.Close, bar.High, bar.Low }
                        //dataSeries.Close[i], dataSeries.High[i], dataSeries.Low[i] } // a double value
                    });
                }
            }
            else
            {
                foreach (Quote quote in dataSeries.Quotes)
                {
                    ds.DataPoints.Add(new DataPoint
                    {
                        AxisXLabel = quote.Time.ToString("yyyy-MM-dd HH:mm"),
                        //ToolTipText = "aa\nbb",
                        //XValue = bar.Time, // a DateTime value
                        YValues = new double[] { quote.Price, quote.Price, quote.Price, quote.Price }
                        //dataSeries.Close[i], dataSeries.High[i], dataSeries.Low[i] } // a double value
                    });
                }
            }

            PriceChart.Series.Add(ds);
            PriceChart.ZoomingEnabled = true;
        }
예제 #2
0
        /// <summary>
        /// Get bars from file
        /// </summary>
        /// <param name="symbol"></param>
        /// <param name="period"></param>
        //        public BarCollection LoadBars(string symbol, int period)
        public StockDataSeries LoadBars(string filePath)
        {
            // Load from file
            //string filePath = string.Format(historyFileName, symbol, period);
            Tuple<string, int, bool> dataInfo = GetDataFileInfo(filePath);
            filePath = string.Concat(DataContext.DataDirectory, filePath);

            string[] lines = File.ReadAllLines(filePath);
            int i = 0;
            // Init quik bar
            DataSeries = new StockDataSeries();
            DataSeries.Symbol = dataInfo.Item1;
            DataSeries.Period = dataInfo.Item2; ;
            // Add bars
            foreach (string line in lines)
            {
                // First line is a header, no parse
                if (i++ == 0)
                    continue;
                Bar bar = ConverterHelper.LoadBar(line);

                DataSeries.Bars.Add(bar);
                DataSeries.Times.Add(bar.Time);
                DataSeries.Open.Add(bar.Open);
                DataSeries.Low.Add(bar.Low);
                DataSeries.High.Add(bar.High);
                DataSeries.Close.Add(bar.Close);
                DataSeries.Volume.Add(bar.Volume);
            }

            return DataSeries;
        }
예제 #3
0
 /// <summary>
 /// ctor
 /// </summary>
 /// <param name="dataSeries">updated data series</param>
 /// <param name="i">bar index</param>
 public TickEventArgs(StockDataSeries dataSeries, int i)
 {
     DataSeries = dataSeries;
     LastBarIndex = i;
 }