Example #1
0
        private void ChartForm_Load(object sender, EventArgs e)
        {
            oandaApi = new OandaAPI();
            candles  = oandaApi.GetCandles(100, instrument, granularity).ToList();

            chart1.Series.Clear();
            chart1.ChartAreas.Clear();
            chart1.Titles.Clear();

            float low  = candles.Select(c => c.lowMid).Min();
            float high = candles.Select(c => c.highMid).Max();

            ChartArea chartArea = new ChartArea();

            chart1.ChartAreas.Add(chartArea);
            chartArea.AxisX.LabelStyle.Format = "T";

            double n = 0.1d;

            while (true)
            {
                double d = Math.Round((high - low) / n);
                if (d <= 2)
                {
                    break;
                }
                n *= 2;
            }

            chartArea.AxisY.Maximum = Math.Ceiling(high / n) * n;
            chartArea.AxisY.Minimum = Math.Floor(low / n) * n;

            Series candleSeries = new Series();

            chart1.Series.Add(candleSeries);
            candleSeries.XValueType = ChartValueType.DateTime;
            candleSeries.ChartType  = SeriesChartType.Candlestick;
            foreach (var candle in candles)
            {
                candleSeries.Points.Add(new DataPoint(candle.DateTime.ToOADate(), new double[] { candle.highMid, candle.lowMid, candle.openMid, candle.closeMid }));
            }
        }