protected override void Paint(Graphics graphics, Rectangle clipBounds,
                                      Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState,
                                      object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds,
                       rowIndex, cellState,
                       value, "", errorText, cellStyle,
                       advancedBorderStyle, paintParts);

            //Get the value of the cell
            int cellValue = Utils.IsDBNull(value) ? 0 : Format.FromLocalInteger(value);

            //If cell value is 0, you still
            //want to show something, so set the value to 1
            if (cellValue == 0)
            {
                cellValue = 1;
            }

            DataGridViewBarGraphColumn parent = (DataGridViewBarGraphColumn)OwningColumn;

            parent.CalcMaxValue();
            long maxValue = parent.MaxValue;
            Font fnt      = parent.InheritedStyle.Font;

            int availableWidth = cellBounds.Width;

            if (maxValue != 0)
            {
                cellValue = (int)((cellValue / maxValue) * availableWidth);
            }

            //Draw the bar, truncating to fit in the space
            //you've got in the cell:
            const int HORIZONTALOFFSET = 1;

            //  Image img = ctlScanner.GradientBar((int)cellValue, cellBounds.Height - 3);
            // graphics.DrawImage(img, cellBounds.X + HORIZONTALOFFSET, cellBounds.Y + 1, img.Width, img.Height);

            //Get the text to draw and calculate its width:
            string cellText = formattedValue.ToString();
            SizeF  textSize = graphics.MeasureString(cellText, fnt);

            PointF textStart = new PointF(1, (cellBounds.Height - textSize.Height) / 2);

            //Calculate the correct color:
            Color textColor = parent.InheritedStyle.ForeColor;

            if ((cellState & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected)
            {
                textColor = Color.Yellow; // textColor = parent.InheritedStyle.SelectionForeColor; // Optional
            }

            //Draw the text:
            using (SolidBrush brush = new SolidBrush(textColor))
            {
                graphics.DrawString(cellText, fnt, brush,
                                    cellBounds.X + cellBounds.Width - textSize.Width,
                                    cellBounds.Y + textStart.Y);
            }
        }
Example #2
0
        public ctlScanner(frmMain oMain, ctlData oData)
        {
            InitializeComponent();
            m_frmMain = oMain;
            m_ctlData = oData;

            oScript = new Alert {
                License = "XRT93NQR79ABTW788XR48"
            };
            Symbols  = new List <string>();
            DataBars = new List <DataManager.BarData>();

            //Setup the results grid
            grdResults.RowTemplate.Height = 28;

            grdResults.ShowCellToolTips = false;
            grdResults.GridColor        = Color.FromArgb(50, 50, 50);
            grdResults.RowsDefaultCellStyle.SelectionBackColor = Color.Black;
            grdResults.RowsDefaultCellStyle.SelectionForeColor = Color.Yellow;

            grdResults.BackgroundColor            = Color.Black;
            grdResults.ForeColor                  = Color.White;
            grdResults.DefaultCellStyle.BackColor = Color.Black;
            grdResults.DefaultCellStyle.ForeColor = Color.White;

            grdResults.RowTemplate.Height = 30;

            DataGridViewTextBoxColumn tradeTime = new DataGridViewTextBoxColumn();
            {
                tradeTime.HeaderText = "Trade Time";
                tradeTime.Name       = "Trade Time";
                tradeTime.ReadOnly   = true;
                grdResults.Columns.Add(tradeTime);
            }

            DataGridViewTextBoxColumn symbolCol = new DataGridViewTextBoxColumn();

            {
                symbolCol.HeaderText = "Symbol";
                symbolCol.Name       = "Symbol";
                symbolCol.ReadOnly   = true;
            }
            grdResults.Columns.Add(symbolCol);

            DataGridViewTextBoxColumn lastCol = new DataGridViewTextBoxColumn();

            {
                lastCol.HeaderText = "Last";
                lastCol.Name       = "Last";
                lastCol.ReadOnly   = true;
                lastCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }
            grdResults.Columns.Add(lastCol);

            DataGridViewBarGraphColumn volumeCol = new DataGridViewBarGraphColumn();

            {
                volumeCol.HeaderText = "Volume";
                volumeCol.Name       = "Volume";
                volumeCol.ReadOnly   = true;
                volumeCol.SortMode   = DataGridViewColumnSortMode.Automatic;
                volumeCol.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleRight;
            }
            grdResults.Columns.Add(volumeCol);

            DataGridViewTextBoxScannerColorColumn alertTime = new DataGridViewTextBoxScannerColorColumn();
            {
                alertTime.HeaderText = "Alert Time";
                alertTime.Name       = "Alert Time";
                alertTime.ReadOnly   = true;
                grdResults.Columns.Add(alertTime);
            }

            DataGridViewButtonColumn tradeCol = new DataGridViewButtonColumn();

            {
                tradeCol.HeaderText  = "Trade";
                tradeCol.Name        = "Trade";
                tradeCol.Text        = "Trade";
                tradeCol.ToolTipText = "Enter Order";
                tradeCol.DefaultCellStyle.NullValue  = "Trade";
                tradeCol.UseColumnTextForButtonValue = true;
            }
            grdResults.Columns.Add(tradeCol);

            DataGridViewButtonColumn chartCol = new DataGridViewButtonColumn();

            {
                chartCol.HeaderText = "Chart";
                chartCol.Name       = "Chart";
                chartCol.Text       = "Chart";
                chartCol.UseColumnTextForButtonValue = true;
            }
            grdResults.Columns.Add(chartCol);

            DataGridViewButtonColumn settingsCol = new DataGridViewButtonColumn();
            {
                settingsCol.HeaderText  = "Settings";
                settingsCol.Name        = "Settings";
                settingsCol.Text        = "Settings";
                settingsCol.ToolTipText = "Edit Settings";
                settingsCol.DefaultCellStyle.NullValue  = "Settings";
                settingsCol.UseColumnTextForButtonValue = true;
                grdResults.Columns.Add(settingsCol);
            }

            DataGridViewImageButtonColumn lockCol = new DataGridViewImageButtonColumn();
            {
                lockCol.HeaderText = "Lock Script";
                lockCol.Name       = "Locked";
                grdResults.Columns.Add(lockCol);
            }

            DataGridViewImageButtonColumn startCol = new DataGridViewImageButtonColumn();

            {
                startCol.HeaderText  = "Pause";
                startCol.Name        = "Start";
                startCol.ToolTipText = "Start Scan";
                grdResults.Columns.Add(startCol);
            }

            UpdateStyle(m_frmMain.m_Style);
        }
Example #3
0
        private void LoadScanner()
        {
            string scanName = cboScanners.Text.Trim();

            if (string.IsNullOrEmpty(scanName))
            {
                return;
            }

            m_loading = true;

            cmdSave.Enabled     = false;
            cmdDelete.Enabled   = false;
            cboScanners.Enabled = false;
            txtScannerName.Text = scanName;

            string data;

            try
            {
                data = svc.GetUserData(frmMain.ClientId, frmMain.ClientPassword, frmMain.LicenseKey, "Scanner Settings: " + scanName);
            }
            catch (Exception)
            {
                MessageBox.Show("Failed to load scanner.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                cmdSave.Enabled     = true;
                cmdDelete.Enabled   = true;
                cboScanners.Enabled = true;
                return;
            }

            string[] text = data.Split(Utils.Chr(134));
            if (text.Length < 4)
            {
                return;
            }

            List <string> strRows = new List <string>(text[0].Split(Utils.Chr(145)));
            char          d       = Utils.Chr(182);

            //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 all symbols
            Symbols.Clear();
            string[] strRow;

            for (int n = 0; n < strRows.Count - 1; n++)
            {
                strRow = strRows[n].Split(d);
                Symbols.Add(strRow[0]);
            }

            //Global settings
            switch (text[1])
            {
            case "Minutely":
                Periodicity = Periodicity.Minutely;
                break;

            case "Hourly":
                Periodicity = Periodicity.Hourly;
                break;

            case "Daily":
                Periodicity = Periodicity.Daily;
                break;

            case "Weekly":
                Periodicity = Periodicity.Weekly;
                break;
            }
            Interval = Convert.ToInt32(text[2]);
            Bars     = Convert.ToInt32(text[3]);
            Script   = text[4];

            //Prime data
            LoadAllSymbolsIntoMemory();

            //Go back through for settings
            for (int n = 0; n < strRows.Count - 2; n++)
            {
                strRow = strRows[n].Split(new[] { d });
                if (strRow.Length < 3)
                {
                    continue;
                }

                for (int j = 0; j < grdResults.Rows.Count; j++)
                {
                    if (string.Compare(grdResults.Rows[j].Cells["Symbol"].Value.ToString(), strRow[0], true) == 0)
                    {
                        DataGridViewImageButtonCell start = (DataGridViewImageButtonCell)grdResults.Rows[j].Cells["Start"];
                        start.Checked = string.Compare(strRow[3], "true", true) == 0;

                        Alert oAlert = m_TSAlertDictionary[strRow[0]];
                        if (oAlert != null)
                        {
                            if (!start.Checked)
                            {
                                oAlert.AlertScript = strRow[1];
                            }
                            else
                            {
                                oAlert.AlertScript = strRow[1];
                            }
                        }//oAlert != null


                        DataGridViewImageButtonCell @lock = (DataGridViewImageButtonCell)grdResults.Rows[j].Cells["Locked"];
                        @lock.Checked = string.Compare(strRow[2], "true", true) == 0;

                        break;
                    } //if grdResults
                }     //for j
            }         //for n

            m_loading = false;
            m_changed = false;

            UpdateName(txtScannerName.Text);

            cmdSave.Enabled     = true;
            cmdDelete.Enabled   = true;
            cboScanners.Enabled = true;

            cmdDelete.Enabled = cboScanners.SelectedIndex != -1;
        }
Example #4
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);
        }