コード例 #1
0
 void chartData_DataLoadComplete(object sender, ezDataLoadCompleteEventArgs e)
 {
     if (DataLoadComplete != null)
     {
         DataLoadComplete(this, e);
     }
 }
コード例 #2
0
        private void  // ERROR: Handles clauses are not supported in C#
        moBarData_DataLoadComplete(object sender, ezDataLoadCompleteEventArgs e)
        {
            // NOTE: This event is raised on it's own thread. If you are updating a GUI application with the chart data (like this example), don't forget that you
            //       MUST marshall this update onto the GUI thread before you modify any GUI components.
            // (This is the same for all T4 API events.)

            if (this.InvokeRequired)
            {
                // An invoke is required to update the GUI, simply invoke back to this same mthod.
                this.BeginInvoke(new ezDataLoadCompleteEventHandler(moBarData_DataLoadComplete), new object[] {
                    sender,
                    e
                });

                // Don't forget to exit now!
                return;
            }

            // On the GUI thread now, update the chart.
            if (e.Status == zDataLoadStatus.Failed)
            {
                status.Text = "ERROR: Chart data request failed.";
                Spy.Print("IChartDataRequest_ChartDataComplete: Chart data request failed.");
                return;
            }
            else
            {
                // Sometimes, you won't get all the historical data you requested. This could happen if there isn't chart data available all the back to the start date you requested.
                Spy.Print("IChartDataRequest_ChartDataComplete: Status: {0}, Dates Requested: {1}, Dates Received: {2}", e.Status, e.DateRangeRequested, e.DateRangeProcessed);
            }

            status.Text = "To add an indicator to the chart, choose a chart indicator from the indicator dropdown list.";

            // Date/time label formats are different for Day than they are for "shorter than day" periods.
            if (chartDataProvider.BarInterval.Interval == zChartInterval.Day)
            {
                chart1.ChartAreas["ChartAreaMain"].AxisX.LabelStyle.Format   = "ddd M/d";
                chart1.ChartAreas["ChartAreaBottom"].AxisX.LabelStyle.Format = "ddd M/d";
            }
            else
            {
                chart1.ChartAreas["ChartAreaMain"].AxisX.LabelStyle.Format   = "ddd h:mmtt";
                chart1.ChartAreas["ChartAreaBottom"].AxisX.LabelStyle.Format = "M/d h:mmtt";
            }

            chart1.Series["candlestickSeries"].Points.Clear();
            chart1.Series["candlestickVolumeSeries"].Points.Clear();

            // Remove all but the two main series.
            for (int i = 2; i < chart1.Series.Count; i++)
            {
                chart1.Series.Remove(chart1.Series[i]);
            }

            double dataPointHigh = double.MinValue;
            double dataPointLow  = double.MaxValue;

            // Before iterating the data collection, you MUST lock it. This will prevent live trade updates from modifying the collection as you read it.
            chartDataProvider.Lock();

            try
            {
                /*for (int i = 0; i <= chartBarData.TradeBars.Count - 1; i++) {
                 *      ezBarDataPoint oBar = (ezBarDataPoint)chartBarData.TradeBars[i];
                 *
                 *      Trace.WriteLine(string.Format("TradeDate: {6}, Time: {5}, Open: {0}, High: {1}, Low: {2}, Close: {3}, Volume: {4}", oBar.OpenTicks, oBar.HighTicks, oBar.LowTicks, oBar.CloseTicks, oBar.Volume, oBar.Time, oBar.TradeDate));
                 *
                 *      moTable.Rows.Add(i, oBar.TradeDate, oBar.Time, oBar.OpenTicks, oBar.HighTicks, oBar.LowTicks, oBar.CloseTicks, oBar.Volume);
                 *
                 * // Add candlestick to chart (high, low, open, close).
                 * object[] multipleValues = new object[] { oBar.HighTicks, oBar.LowTicks, oBar.OpenTicks, oBar.CloseTicks };
                 * chart1.Series[0].Points.AddXY(oBar.Time, multipleValues);
                 * chart1.Series[1].Points.AddXY(oBar.Time, oBar.Volume);
                 *
                 * // See if our maximum and minimum values on the chart have changed (we will use this for axis scaling).
                 * dataPointHigh = Math.Max(dataPointHigh, oBar.HighTicks);
                 * dataPointLow = Math.Min(dataPointLow, oBar.LowTicks);
                 * }*/

                for (int i = 0; i <= chartDataProvider.ChartData.TradeBars.Count - 1; i++)
                {
                    ezBarDataPoint oBar = (ezBarDataPoint)chartDataProvider.ChartData.TradeBars[i];

                    // Add candlestick to chart (high, low, open, close).
                    AddBarToChart(oBar);

                    // See if our maximum and minimum values on the chart have changed (we will use this for axis scaling).
                    dataPointHigh = Math.Max(dataPointHigh, oBar.High);
                    dataPointLow  = Math.Min(dataPointLow, oBar.Low);
                }

                chart1.ChartAreas["ChartAreaMain"].AxisY.Minimum = dataPointLow;
                chart1.ChartAreas["ChartAreaMain"].AxisY.Maximum = dataPointHigh;

                //this.Text = "Monkey Chart - " + chartDataProvider.Name + string.Format(" - {0} {1}", chartDataProvider.BarInterval.Period, chartDataProvider.BarInterval.Interval);
            }
            catch (Exception ex)
            {
                Spy.Print("Error loading chart data: " + ex.ToString());
                status.Text = "Error loading chart data: " + ex.ToString();
            }
            finally
            {
                // If you don't be sure to unlock the data collection, you probably won't get any live trade updates.
                chartDataProvider.Unlock();
            }
        }