// Обработка события получения нового тика
        private void Connector_Event_GetTick(Tick tick)
        {
            if (Sec != null)                    // Проверка изменения инструмента в поле выбора
            {
                if (Sec.Load && tick.paperCode == secName)
                {
                    while (Chart.PlotSer)
                    {
                    }                           // Пока коллекция занята отрисовкой, ждем

                    add = true;                 // Сообщаем о добавлении данных в коллекцию
                    Sec.AddTick(tick);
                    if (ds.Load)
                    {
                        ds.AddRealTick(Sec, tick);
                    }
                    add = false;                // Добавление завершено
                    //  WindowGL.BarsDraw.AddReal(Sec, tk);
                }
            }
            else if (tick.paperCode == secName)
            {
                if (secName == "SiZ6" | secName == "SRZ6")
                {
                    Sec = new DataSeries(secName, 1, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
                }
                else
                {
                    Sec = new DataSeries(secName, 10, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
                }

                add = true;
                DateTime t = new DateTime(tick.dateTimeTick.Year, tick.dateTimeTick.Month, tick.dateTimeTick.Day,
                                          tick.dateTimeTick.Hour, tick.dateTimeTick.Minute, 0);
                tick.dateTimeTick = t;
                Sec.AddTick(tick);
                if (ds == null) // При отсутствии данных для отрисовки, создать новую DrawSeries
                {
                    if (secName == "SiZ6" | secName == "SRZ6")
                    {
                        ds = new DrawSeries(Sec.Bars.ElementAt(0).Value.Open, 1, minVol, maxVol);
                    }
                    else
                    {
                        ds = new DrawSeries(Sec.Bars.ElementAt(0).Value.Open, 10, minVol, maxVol);
                    }
                    ds.Add(Sec);
                    Chart.ReloadSeries(Sec, ds, Sec.Bars.ElementAt(0).Value.Open);
                    if (ds.Load)
                    {
                        ds.AddRealTick(Sec, tick);
                    }
                    add = false;
                }
                Chart.LookSet(); // Отобразить новые данные
            }
        }
        // Тестовая кнопка, загрузка тиковых данных из файла
        private void Load_Click(object sender, EventArgs e)
        {
            Sec = new DataSeries("RTS-3.15", 10, Exchange.SPBFUT, TimeFrame.Hour, chartStyle.Cluster, ignorTickVol);
            // WindowGL.Sec = Sec;
            //  Rts.Bars[0].
            Ticks = new Tick();
            var lines = File.ReadAllLines("D:\\Market Data\\fut_deal.csv", System.Text.Encoding.Default);

            for (int i = 1; i < lines.Count(); i++)
            {
                string[] parts = lines[i].Split(';');
                DateTime dtNew = DateTime.Now;
                if (parts[2] == "RTS-3.15")
                {
                    string   dt = parts[0] + ' ' + parts[1];
                    DateTime t  = DateTime.ParseExact(dt, "dd.MM.yyyy HH:mm:ss", null);
                    //Ticks.dateTimeTick = t;
                    Ticks.priceTick    = Convert.ToDouble(parts[3].Replace(".", ","));
                    Ticks.volumeTick   = Convert.ToInt32(parts[4]);
                    dtNew              = new DateTime(t.Year, t.Month, t.Day, t.Hour, t.Minute, 00);
                    Ticks.dateTimeTick = dtNew;
                    Sec.AddTick(Ticks);
                    // tickDBDataSet1.Tables.Add();
                }
            }
            Sec.AddLast();

            //  BarsDraw = new PaintPoint();
            //  BarsDraw.Add(Sec);
            //   WindowGL.BarsDraw = BarsDraw;

            ds = new DrawSeries(Sec.Bars.First().Value.Open, Sec.deltaTick, minVol, maxVol);
            ds.Add(Sec);
            //   WindowGL.DrawSer = ds;
            // WindowGL.PriceOpen = Sec.Bars.ElementAt(0).Value.Open;


            //  Sec.DrawPoint();
            // WindowGL.Sec = Sec;
            MessageBox.Show(Sec.Bars.Count().ToString());
            Chart.LookSet();
            Chart.Plot();
        }
        private void btApply_Click(object sender, EventArgs e)
        {
            //   Sec.Load = false;
            //  ds.Load = false;
            minVol       = Convert.ToInt32(tbVolFilterMin.Text);
            maxVol       = Convert.ToInt32(tbVolFilterMax.Text);
            ignorTickVol = Convert.ToInt32(tbIgnoreTickVol.Text);
            secName      = cbSecurity.SelectedItem.ToString();
            string[] TfArg = cbTf.SelectedItem.ToString().Split(' ');
            switch (TfArg[1])
            {
            case "SEC":
                TF.frame = TfRange.SEC;
                break;

            case "MIN":
                TF.frame = TfRange.MIN;
                break;

            case "HOUR":
                TF.frame = TfRange.HOUR;
                break;

            case "DAY":
                TF.frame = TfRange.DAY;
                break;
            }
            TF.digit = Convert.ToInt32(TfArg[0]);

            if (ignorTickVol != prevIgnorTickVol || secName != prevSecName || TFPrev.frame != TF.frame || TF.digit != TFPrev.digit)
            {
                while (Chart.PlotSer)
                {
                }
                if (Sec != null)
                {
                    Sec.Dispose();
                    Sec = null;
                    //   if(secName == "SIH6")
                    //   Sec = new DataSeries(secName, 1, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
                    //   else Sec = new DataSeries(secName, 1, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
                }
                prevIgnorTickVol = ignorTickVol;
                TFPrev           = TF;
            }
            if (ds != null)
            {
                ds.Dispose();
                ds = null;
                if (Sec != null)
                {
                    ds.Add(Sec);
                }
                // if (secName == "SIH6")
                //     Sec = new DataSeries(secName, 1, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
                // else Sec = new DataSeries(secName, 1, Exchange.SPBFUT, TimeFrame.M1, chartStyle.Cluster, ignorTickVol);
            }
            // ds?.Dispose();

            //   Load_Click(sender, e);


            //   Chart.LookSet();
            //   Chart.Plot();
        }