public DataGridViewTextBoxScannerColorColumn()
 {
     CellTemplate = new DataGridViewTextBoxScannerColorCell();
     ReadOnly     = true;
 }
Example #2
0
        //Loads all required data into memory. This function must be called first.
        public bool LoadAllSymbolsIntoMemory()
        {
            //Verify the input and check script for errors
            if (m_ctlData == null || !TestScripts())
            {
                return(false);
            }

            EnableControls(false);

            //Clear everything
            m_stop = false;
            m_TSAlertDictionary.Clear();
            m_DGVRowDictionary.Clear();
            grdResults.Rows.Clear();

            DataGridViewBarGraphColumn volumeCol = (DataGridViewBarGraphColumn)grdResults.Columns["Volume"];

            if (volumeCol != null)
            {
                volumeCol.MaxValue = 0;
            }

            //Load history for all symbols into memory
            pnlProgress.Cursor  = Cursors.WaitCursor;
            pnlProgress.Visible = true;

            if (Symbols.Count > 1)
            {
                ProgressBar1.Properties.Maximum = Symbols.Count - 1;
            }

            ChartSelection selection = new ChartSelection
            {
                Periodicity = Periodicity,
                Interval    = Interval,
                Bars        = Bars * 3
            };

            if (selection.Bars < 50)
            {
                selection.Bars = 50;
            }

            lblInfo.Text = "Priming scanner, please wait...";

            for (int n = 0; n < Symbols.Count; n++)
            {
                string symbol = Symbols[n];

                if (m_stop)
                {
                    break;
                }

                if (m_TSAlertDictionary.ContainsKey(symbol))
                {
                    continue;
                }

                selection.Symbol = symbol;

                ProgressBar1.Properties.Value = n;
                lblSymbol.Text = symbol;
                Application.DoEvents();

                //Get historic data
                var bars = m_ctlData.GetHistory(symbol, this, selection.Periodicity, selection.Interval, selection.Bars);
                if (bars == null || bars.Count < 3)
                {
                    continue;
                }

                //Insert the data into TradeScript
                Alert oAlert = new Alert {
                    License = "XRT93NQR79ABTW788XR48"
                };

                foreach (M4.DataServer.Interface.BarData t in bars)
                {
                    double jDate = oAlert.ToJulianDate(t.TradeDate.Year, t.TradeDate.Month, t.TradeDate.Day,
                                                       t.TradeDate.Hour, t.TradeDate.Minute, t.TradeDate.Second,
                                                       t.TradeDate.Millisecond);
                    oAlert.AppendHistoryRecord(jDate, t.OpenPrice, t.HighPrice, t.LowPrice, t.ClosePrice, (int)t.VolumeF);
                }

                //Start the alert object by adding the script
                oAlert.AlertScript = Script;
                oAlert.Symbol      = symbol;

                oAlert.ScriptError += oScript_ScriptError;
                oAlert.Alert       += OnAlert;

                m_TSAlertDictionary.Add(symbol, oAlert);

                //Add symbol to datagridview
                int row;
                try
                {
                    row = grdResults.Rows.Add(new DataGridViewRow());
                }
                catch (Exception)
                {
                    return(false);
                }
                m_DGVRowDictionary.Add(symbol, grdResults.Rows[row]);
                grdResults.Rows[row].Height = 25;

                M4.DataServer.Interface.BarData lastBar = bars.Last();

                DataGridViewTextBoxScannerColorCell alertDateTime = (DataGridViewTextBoxScannerColorCell)grdResults.Rows[row].Cells["Alert Time"];
                alertDateTime.HighlightOnly = true;
                alertDateTime.Value         = lastBar.TradeDate;
                alertDateTime.Interval      = 5000;

                grdResults.Rows[row].Cells["Trade Time"].Value = lastBar.TradeDate;
                grdResults.Rows[row].Cells["Symbol"].Value     = symbol;
                grdResults.Rows[row].Cells["Last"].Value       = Format.ToUsCurrency(lastBar.ClosePrice);
                grdResults.Rows[row].Cells["Volume"].Value     = Format.ToLocalInteger((int)lastBar.VolumeF);

                DataGridViewButtonCell button = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Trade"];
                button.Value     = "Trade";
                button.FlatStyle = FlatStyle.Flat;

                button           = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Chart"];
                button.Value     = "Chart";
                button.FlatStyle = FlatStyle.Flat;

                button           = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Settings"];
                button.Value     = "Settings";
                button.FlatStyle = FlatStyle.Flat;

                button           = (DataGridViewButtonCell)grdResults.Rows[row].Cells["Start"];
                button.Value     = "Start";
                button.FlatStyle = FlatStyle.Flat;

                DataGridViewImageButtonCell start = (DataGridViewImageButtonCell)grdResults.Rows[row].Cells["Start"];
                start.ImageOn  = Resources.Play;
                start.ImageOff = Resources.Pause;
                start.OffsetY  = 4;

                DataGridViewImageButtonCell @lock = (DataGridViewImageButtonCell)grdResults.Rows[row].Cells["Locked"];
                @lock.ImageOn  = Resources.Lock;
                @lock.ImageOff = Resources.Unlock;
                @lock.OffsetY  = 2;
            }

            lblInfo.Text        = string.Empty;
            pnlProgress.Visible = false;
            pnlProgress.Cursor  = Cursors.Arrow;

            EnableControls(true);

            return(true);
        }