void chartData_DataSeriesUpdated(object sender, ezDataSeriesUpdatedEventArgs e)
 {
     if (DataSeriesUpdated != null)
     {
         DataSeriesUpdated(this, e);
     }
 }
        void chartDataSeries_DataSeriesUpdated(object sender, DataSeriesUpdatedEventArgs e)
        {
            Spy.Print("DataSeriesUpdated (on thread)");

            if (e.TradeBarIndexUpdate == -1)
            {
                return;
            }

            var update = new ezDataSeriesUpdatedEventArgs(e.ModeIndexUpdate, e.SettlementIndexUpdate, e.TradeBarIndexUpdate);

            for (int i = e.TradeBarIndexUpdate; i < ctsChartData.TradeBars.Count; i++)
            {
                if (i >= chartData.TradeBars.Count)
                {
                    BarDataPoint bdp   = ctsChartData.TradeBars[i] as BarDataPoint;
                    var          ezBar = new ezBarDataPoint();
                    ezBar.Open       = bdp.OpenTicks;
                    ezBar.High       = bdp.HighTicks;
                    ezBar.Low        = bdp.LowTicks;
                    ezBar.Close      = bdp.CloseTicks;
                    ezBar.TradeCount = bdp.TradeCount;
                    ezBar.Volume     = bdp.Volume;
                    ezBar.TradeDate  = bdp.TradeDate;
                    ezBar.Time       = bdp.Time;
                    chartData.TradeBars.Add(ezBar);
                }
                else
                {
                    BarDataPoint bdp = ctsChartData.TradeBars[i] as BarDataPoint;
                    //var ezBar = new ezBarDataPoint(bdp.OpenTicks, bdp.HighTicks, bdp.LowTicks, bdp.CloseTicks, bdp.TradeCount, bdp.Volume, bdp.TradeDate, bdp.Time);
                    var ezBar = new ezBarDataPoint();
                    ezBar.Open       = bdp.OpenTicks;
                    ezBar.High       = bdp.HighTicks;
                    ezBar.Low        = bdp.LowTicks;
                    ezBar.Close      = bdp.CloseTicks;
                    ezBar.TradeCount = bdp.TradeCount;
                    ezBar.Volume     = bdp.Volume;
                    ezBar.TradeDate  = bdp.TradeDate;
                    ezBar.Time       = bdp.Time;
                    chartData.UpdateTradeBar(i, ezBar);
                }
            }
            chartData.DataProviderSeriesUpdated(update);
        }
예제 #3
0
        private void  // ERROR: Handles clauses are not supported in C#
        moBarData_DataSeriesUpdated(object sender, ezDataSeriesUpdatedEventArgs 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 ezDataSeriesUpdatedEventHandler(moBarData_DataSeriesUpdated), new object[] {
                    sender,
                    e
                });

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

            //On the GUI thread now, update the chart.

            // 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
            {
                //e.TradeBarIndexUpdate is the index of the first bar that was added or updated since the last update event.
                for (int i = e.TradeBarIndexUpdate; i <= chartDataProvider.ChartData.TradeBars.Count - 1; i++)
                {
                    ezBarDataPoint oBar = (ezBarDataPoint)chartDataProvider.ChartData.TradeBars[i];

                    if (i < chart1.Series[0].Points.Count)
                    {
                        Spy.Print("Updating bar index {0} - close = {1}", i, oBar.Close);

                        // Update the chart series.
                        DataPoint dp1 = chart1.Series[0].Points[i];
                        dp1.YValues[0] = oBar.High;
                        dp1.YValues[1] = oBar.Low;
                        dp1.YValues[2] = oBar.Open;
                        dp1.YValues[3] = oBar.Close;
                        DataPoint dp2 = chart1.Series[1].Points[i];
                        dp2.YValues[0] = oBar.Volume;

                        RecalcAllActiveSeries();
                        chart1.Refresh();
                    }
                    else
                    {
                        xAxis = chart1.ChartAreas["ChartAreaMain"].AxisX;
                        bool scrollToFurthest = (xAxis.ScaleView.ViewMaximum == xAxis.Maximum);
                        AddBarToChart(oBar);
                        RecalcAllActiveSeries();
                        chart1.Refresh();
                        if (scrollToFurthest == true)
                        {
                            xAxis.ScaleView.Scroll(xAxis.Maximum);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Spy.Print("Error updating chart data: " + ex.ToString());
                status.Text = "Error updating 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();
            }
        }