Esempio n. 1
0
        public StockChartPanel(string symbol)
        {
            this.Symbol  = symbol;
            this.Resize += StockChartPanel_Resize;

            // Create the summary bar
            SummaryBarPanel           = new Panel();
            SummaryBarPanel.Location  = new System.Drawing.Point(0, 0);
            SummaryBarPanel.Size      = new System.Drawing.Size(600, 25);
            SummaryBarPanel.BackColor = GuiStyle.BACKGROUND_COLOR;

            BuyButton          = new GuiButton("Buy");
            BuyButton.Location = new System.Drawing.Point(0, 5);
            SummaryBarPanel.Controls.Add(BuyButton);

            SellButton          = new GuiButton("Sell");
            SellButton.Location = new System.Drawing.Point(0, BuyButton.Location.Y);
            SummaryBarPanel.Controls.Add(SellButton);

            SummaryLabel           = new Label();
            SummaryLabel.ForeColor = GuiStyle.TEXT_COLOR;
            SummaryLabel.Size      = new System.Drawing.Size(200, 20);
            SummaryLabel.BackColor = System.Drawing.Color.Transparent;
            SummaryLabel.Location  = new System.Drawing.Point(10, 5);
            SummaryBarPanel.Controls.Add(SummaryLabel);

            CollapseButton           = new PictureBox();
            CollapseButton.Image     = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Collapse.png");
            CollapseButton.BackColor = System.Drawing.Color.Transparent;
            CollapseButton.Size      = CollapseButton.Image.Size;
            CollapseButton.Location  = new System.Drawing.Point(SummaryLabel.Location.X + SummaryLabel.Width, 5);
            CollapseButton.MouseUp  += CollapseButton_MouseUp;
            SummaryBarPanel.Controls.Add(CollapseButton);

            CloseButton           = new PictureBox();
            CloseButton.Image     = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Close.png");
            CloseButton.BackColor = System.Drawing.Color.Transparent;
            CloseButton.Size      = CollapseButton.Image.Size;
            CloseButton.Location  = new System.Drawing.Point(CollapseButton.Location.X + CollapseButton.Width, 5);
            SummaryBarPanel.Controls.Add(CloseButton);
            this.Controls.Add(SummaryBarPanel);

            this.Canvas = new Panel();
            this.Chart  = new StockChart(symbol);
            Canvas.Controls.Add(Chart.Canvas);

            // Request data to fill the stock chart
            Chart.RequestData(DateTime.Now.Date.AddHours(-48), DateTime.Now.Date.AddHours(16), new TimeSpan(0, 1, 0));
            Chart.SetSubscritpion(DataAccessor.Subscribe(Chart.Symbol, DataAccessor.SUBSCRIBE_FIVE_SEC));

            Canvas.Resize  += (sender, e) => { Chart.Canvas.Size = Canvas.Size; };
            Canvas.Location = new System.Drawing.Point(SummaryBarPanel.Location.X - 6, SummaryBarPanel.Location.Y + SummaryBarPanel.Height);
            this.Controls.Add(Canvas);
        }
        public LogInScreen()
        {
            GuiPanel = new Panel();

            GuiBox            = new Panel();
            GuiBox.AutoSize   = true;
            GuiBox.BackColor  = GuiStyle.BACKGROUND_COLOR;
            Username          = new TextBox();
            Username.Size     = new System.Drawing.Size(200, 15);
            Username.Location = new System.Drawing.Point(10, 40);
            GuiBox.Controls.Add(Username);

            Password = new TextBox();
            Password.UseSystemPasswordChar = true;
            Password.Size     = Username.Size;
            Password.Location = new System.Drawing.Point(Username.Location.X, Username.Location.Y + 40);
            GuiBox.Controls.Add(Password);

            RememberLogIn           = new CheckBox();
            RememberLogIn.Location  = new System.Drawing.Point(Password.Location.X + 10, Password.Location.Y + 25);
            RememberLogIn.Size      = new Size(200, 20);
            RememberLogIn.Text      = "Remember log-in";
            RememberLogIn.Checked   = false;
            RememberLogIn.Font      = GuiStyle.Font;
            RememberLogIn.ForeColor = GuiStyle.PRICE_COLOR_POSITIVE;
            RememberLogIn.TextAlign = ContentAlignment.BottomLeft;
            GuiBox.Controls.Add(RememberLogIn);

            LogInButton          = new GuiButton("Log In");
            LogInButton.Location = new System.Drawing.Point((Password.Location.X + Password.Width) - LogInButton.Width, RememberLogIn.Location.Y + 30);
            LogInButton.MouseUp += LogInButton_MouseUp;
            GuiBox.Controls.Add(LogInButton);

            CancelButton          = new GuiButton("Cancel");
            CancelButton.Location = new System.Drawing.Point(Password.Location.X, LogInButton.Location.Y);
            GuiBox.Controls.Add(CancelButton);

            GuiBox.Paint += (sender, e) =>
            {
                SolidBrush brush      = new SolidBrush(GuiStyle.PRICE_COLOR_POSITIVE);
                SolidBrush errorBrush = new SolidBrush(GuiStyle.PRICE_COLOR_NEGATIVE);
                e.Graphics.DrawString("Username", GuiStyle.Font, brush, new Point(Username.Location.X, Username.Location.Y - 20), StringFormat.GenericDefault);
                e.Graphics.DrawString("Password", GuiStyle.Font, brush, new Point(Password.Location.X, Password.Location.Y - 20), StringFormat.GenericDefault);
                e.Graphics.DrawString(ErrorText, GuiStyle.Font, errorBrush, new Point(Username.Location.X, Username.Location.Y - 40), StringFormat.GenericDefault);
            };

            GuiPanel.BackColor = GuiStyle.BACKGROUND_COLOR;
            GuiPanel.Controls.Add(GuiBox);
            GuiPanel.Resize += (sender, e) =>
            {
                GuiBox.Location = new System.Drawing.Point((GuiPanel.Width / 2) - (GuiBox.Width / 2), (GuiPanel.Height / 2) - (GuiBox.Height / 2));
            };
        }
Esempio n. 3
0
            public OrderSummary(Broker.Order orderInfo) : base(DataAccessor.Subscribe(orderInfo.Symbol, DataAccessor.SUBSCRIBE_FIVE_SEC))
            {
                this.OrderInfo = orderInfo;

                OrderLabel = new Label();
                //OrderLabel.Font = GuiStyle.Font;
                //OrderLabel.ForeColor = GuiStyle.DARK_GREY;
                OrderLabel.TextAlign = System.Drawing.ContentAlignment.BottomCenter;
                OrderLabel.Text      = string.Format("{0} {1}", orderInfo.BuySell == Broker.Order.BuySellType.BUY ? "Buy" : "Sell", orderInfo.Quantity);
                OrderLabel.Size      = new System.Drawing.Size(60, 15);
                OrderLabel.Location  = new System.Drawing.Point(5, 5);
                Controls.Add(OrderLabel);

                CancelOrderButton             = new GuiButton("Cancel");
                CancelOrderButton.Location    = new System.Drawing.Point(OrderLabel.Location.X, OrderLabel.Location.Y + OrderLabel.Height + 5);
                CancelOrderButton.MouseClick += (sender, e) =>
                {
                    Broker.Instance.CancelOrder(OrderInfo.Symbol);
                };
                Controls.Add(CancelOrderButton);
            }
        public BuySellPanel()
        {
            Instance       = this;
            this.BackColor = GuiStyle.BACKGROUND_COLOR;

            // Create the order type selection button
            BuySellLabel           = new Label();
            BuySellLabel.Size      = new System.Drawing.Size(50, 25);
            BuySellLabel.Location  = new System.Drawing.Point(50, 50);
            BuySellLabel.ForeColor = GuiStyle.TEXT_COLOR;
            BuySellLabel.Font      = new System.Drawing.Font(GuiStyle.Font.Name, 10, System.Drawing.FontStyle.Bold);
            BuySellLabel.TextAlign = System.Drawing.ContentAlignment.TopRight;
            this.Controls.Add(BuySellLabel);
            OrderTypeButton             = new GuiButton(OrderNames[(int)SelectedOrderType]);
            OrderTypeButton.Location    = new System.Drawing.Point(BuySellLabel.Bounds.Right + 5, 50);
            OrderTypeButton.MouseClick += (sender, e) => {
                OrderTypeSelectionPanel.Visible = !OrderTypeSelectionPanel.Visible;
                if (!OrderTypeSelectionPanel.Visible)
                {
                    RefreshOrderOptionList();
                }
            };
            this.Controls.Add(OrderTypeButton);

            // Create the order type selection list
            OrderTypeSelectionPanel          = new Panel();
            OrderTypeSelectionPanel.Location = new System.Drawing.Point(0, OrderTypeButton.Location.Y + OrderTypeButton.Height + 5);
            for (int idx = 0; idx < OrderNames.Length; idx++)
            {
                Broker.Order.OrderType ot = (Broker.Order.OrderType)idx;
                GuiButton orderButton     = new GuiButton(OrderNames[idx]);
                orderButton.Location    = new System.Drawing.Point(OrderTypeButton.Location.X + 10, (idx * (orderButton.Height + 5)) + 5);
                orderButton.MouseClick += (sender, e) =>
                {
                    SelectedOrderType = ot;
                    RefreshOrderTypeButtons();
                };
                OrderTypeSelectionPanel.Controls.Add(orderButton);
            }
            OrderTypeSelectionPanel.Visible = false;
            RefreshOrderTypeButtons();
            this.Controls.Add(OrderTypeSelectionPanel);

            this.Resize += (sender, e) =>
            {
                OrderTypeSelectionPanel.Width  = this.Width;
                OrderTypeSelectionPanel.Height = (this.Height - OrderTypeSelectionPanel.Location.Y);
            };

            // Create the back button
            BackButton             = new PictureBox();
            BackButton.Image       = System.Drawing.Bitmap.FromFile("Content/GUI/Back.png");
            BackButton.Size        = BackButton.Image.Size;
            BackButton.Location    = new System.Drawing.Point(10, 10);
            BackButton.MouseClick += (sender, e) => { this.Visible = false; };
            this.Controls.Add(BackButton);

            // Create the info label
            OrderInfoLabel                  = new Label();
            OrderInfoLabel.Size             = new System.Drawing.Size(this.Width, 60);
            OrderInfoLabel.Text             = "";
            OrderInfoLabel.ForeColor        = GuiStyle.TEXT_COLOR;
            OrderInfoLabel.Visible          = false;
            OrderInfoLabel.LocationChanged += (sender, e) =>
            {
                ReviewOrderButton.Location = new System.Drawing.Point(OrderInfoLabel.Location.X, OrderInfoLabel.Bounds.Bottom + 5);
                EditOrderButton.Location   = ReviewOrderButton.Location;
                SubmitOrderButton.Location = new System.Drawing.Point(EditOrderButton.Location.X, EditOrderButton.Bounds.Bottom + 5);
            };
            OrderInfoLabel.Location = new System.Drawing.Point(BackButton.Bounds.Right + 5, 220);
            this.Controls.Add(OrderInfoLabel);

            // Create the order review and submit buttons
            ReviewOrderButton.MouseClick += (sender, e) =>
            {
                OrderInfoLabel.Text = GetOrderSummary();
                OrderInfoLabel.Show();
                ReviewOrderButton.Hide();

                EditOrderButton.Show();
                SubmitOrderButton.Text = string.Format("Submit {0}", (BuySell == Broker.Order.BuySellType.BUY) ? "Buy" : "Sell");
                SubmitOrderButton.Show();
            };
            this.Controls.Add(ReviewOrderButton);

            EditOrderButton.MouseClick += (sender, e) =>
            {
                OrderInfoLabel.Hide();
                EditOrderButton.Hide();
                SubmitOrderButton.Hide();
                ReviewOrderButton.Show();
            };
            this.Controls.Add(EditOrderButton);

            SubmitOrderButton.MouseClick += (sender, e) =>
            {
                // Submit the order
                Broker.Order newOrder = new Broker.Order()
                {
                    BuySell    = BuySell,
                    LimitPrice = GetTradePrice(),
                    Quantity   = Shares,
                    Symbol     = Symbol,
                    Type       = SelectedOrderType,
                };
                decimal.TryParse(StopPriceTextbox.Text, out newOrder.StopPrice);
                Broker.Instance.SubmitOrder(newOrder);

                // Hide the buy/sell menu
                this.Hide();
            };
            this.Controls.Add(SubmitOrderButton);

            // Create the all and half buying power shortcut buttons
            GuiButton halfButton = new GuiButton("Half");

            halfButton.MouseClick += (sender, e) => {
                if (BuySell == Broker.Order.BuySellType.BUY)
                {
                    if (TargetTotalValue == 0)
                    {
                        TargetTotalValue = BuyingPower;
                    }
                    TargetTotalValue /= 2;
                    TargetShares      = 0;
                    UpdateTransaction();
                }
                else
                {
                    if (TargetShares == 0)
                    {
                        TargetShares = OwnedShares;
                    }
                    TargetShares    /= 2;
                    TargetTotalValue = 0;
                    UpdateTransaction();
                }
            };
            this.Controls.Add(halfButton);
            GuiButton allButton = new GuiButton("All");

            allButton.MouseClick += (sender, e) =>
            {
                if (BuySell == Broker.Order.BuySellType.BUY)
                {
                    TargetTotalValue = BuyingPower;
                    TargetShares     = 0;
                    UpdateTransaction();
                }
                else
                {
                    TargetShares     = OwnedShares;
                    TargetTotalValue = 0;
                    UpdateTransaction();
                }
            };
            this.Controls.Add(allButton);
            TotalTextbox.LocationChanged += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                halfButton.Location = new System.Drawing.Point(t.Bounds.Right - halfButton.Width, t.Bounds.Bottom + 5);
                allButton.Location  = new System.Drawing.Point(halfButton.Location.X - allButton.Width - 5, halfButton.Location.Y);
            };

            // Create the order textboxes
            Tuple <TextBox, string>[] textboxes = new Tuple <TextBox, string>[]
            {
                new Tuple <TextBox, string>(StopPriceTextbox, "Stop Price"),
                new Tuple <TextBox, string>(LimitPriceTextbox, "Limit Price"),
                new Tuple <TextBox, string>(SharesTextbox, "Shares"),
                new Tuple <TextBox, string>(PricePerShareTextbox, "Market Price"),
                new Tuple <TextBox, string>(TotalTextbox, "Total Value")
            };
            foreach (Tuple <TextBox, string> t in textboxes)
            {
                Label name = new Label();
                name.Size      = new System.Drawing.Size(150, 20);
                name.Location  = new System.Drawing.Point(50, 0);
                name.Text      = t.Item2;
                name.ForeColor = GuiStyle.TEXT_COLOR;
                name.Font      = new System.Drawing.Font(GuiStyle.FONT_NAME, 9, System.Drawing.FontStyle.Bold);
                this.Controls.Add(name);

                t.Item1.Size             = new System.Drawing.Size(100, 20);
                t.Item1.LocationChanged += (sender, e) => { name.Location = new System.Drawing.Point(name.Location.X, ((TextBox)sender).Location.Y); };
                t.Item1.VisibleChanged  += (sender, e) => { name.Visible = ((TextBox)sender).Visible; };
                t.Item1.Location         = new System.Drawing.Point(name.Bounds.Right, 0);
                t.Item1.ForeColor        = GuiStyle.TEXT_COLOR;
                t.Item1.BackColor        = GuiStyle.DARK_GREY;

                this.Controls.Add(t.Item1);
            }
            RefreshOrderOptionList();

            // Customization of textboxes
            PricePerShareTextbox.BorderStyle = BorderStyle.None;
            PricePerShareTextbox.BackColor   = GuiStyle.BACKGROUND_COLOR;
            PricePerShareTextbox.ForeColor   = GuiStyle.PRICE_COLOR_POSITIVE;
            PricePerShareTextbox.ReadOnly    = true;
            SharesTextbox.KeyDown           += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
                {
                    if (decimal.TryParse(((TextBox)sender).Text, out TargetShares))
                    {
                        // Remove focus from the textbox so that it will be updated
                        ((TextBox)sender).Parent.Focus();
                        UpdateTransaction();
                    }
                    TargetTotalValue = 0;
                }
            };
            TotalTextbox.KeyDown += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
                {
                    decimal val;
                    if (decimal.TryParse(TotalTextbox.Text.Replace("$", "").Replace(",", ""), out val))
                    {
                        ((TextBox)sender).Parent.Focus();
                        decimal price = GetTradePrice();
                        if (price != 0)
                        {
                            Shares = Math.Floor(val / price);
                        }
                        TargetTotalValue = val;
                    }
                    TargetShares = 0;
                }
            };
            LimitPriceTextbox.KeyDown += (sender, e) =>
            {
                if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return))
                {
                    UpdateTransaction();
                }
            };
        }
Esempio n. 5
0
        public AlgorithmScreen(AlgorithmScreenConfig config = null)
        {
            this.Cfg = ((config != null) ? config : new AlgorithmScreenConfig());
            GuiPanel = new Panel();

            GuiBox           = new Panel();
            GuiBox.AutoSize  = true;
            GuiBox.BackColor = GuiStyle.BACKGROUND_COLOR;

            // Add the GUI elements for configurating the script
            DataFileButton          = new GuiButton("Open...");
            DataFileButton.Location = new Point(5, 30);
            DataFileButton.MouseUp += (sender, e) =>
            {
                System.Windows.Forms.OpenFileDialog diag = new System.Windows.Forms.OpenFileDialog();
                diag.Multiselect      = true;
                diag.Title            = "Open Stock Data File...";
                diag.InitialDirectory = Cfg.SourceFilePath;
                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    if ((DataFileTextbox.Text.Length > 0) && (!DataFileTextbox.Text.EndsWith("\n")))
                    {
                        DataFileTextbox.Text += "\r\n";
                    }
                    foreach (string dataPath in diag.FileNames)
                    {
                        DataFileTextbox.Text += dataPath + "\r\n";
                        Cfg.SourceFilePath    = Path.GetDirectoryName(dataPath);
                    }
                    DataFileTextbox.Text           = DataFileTextbox.Text.Remove(DataFileTextbox.Text.Length - 2, 2);
                    DataFileTextbox.SelectionStart = DataFileTextbox.Text.Length;
                    DataFileTextbox.ScrollToCaret();
                    DataFileButton.SetImage(GuiButton.ButtonImage.GREEN_WHITE);
                    DataLiveButton.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
                }
            };
            GuiBox.Controls.Add(DataFileButton);
            GuiButton clearButton = new GuiButton("Clear");

            clearButton.Location = new Point(DataFileButton.Bounds.Right + 5, DataFileButton.Location.Y);
            clearButton.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
            clearButton.MouseUp += (sender, e) =>
            {
                DataFileTextbox.Text = "";
            };
            GuiBox.Controls.Add(clearButton);
            DataLiveButton          = new GuiButton("Live");
            DataLiveButton.Location = new Point(clearButton.Bounds.Right + 5, clearButton.Location.Y);
            DataLiveButton.SetImage(GuiButton.ButtonImage.GREEN_WHITE);
            DataLiveButton.MouseUp += (sender, e) =>
            {
                DataFileTextbox.Text = "";
                DataLiveButton.SetImage(GuiButton.ButtonImage.GREEN_WHITE);
                DataFileButton.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
            };
            GuiBox.Controls.Add(DataLiveButton);
            Label sourceDataLabel = new Label();

            sourceDataLabel.Text      = "Source Data";
            sourceDataLabel.ForeColor = GuiStyle.PRICE_COLOR_POSITIVE;
            sourceDataLabel.Font      = GuiStyle.Font;
            sourceDataLabel.Location  = new Point(DataFileButton.Bounds.Left, (DataFileButton.Bounds.Top - sourceDataLabel.Height) + 5);
            GuiBox.Controls.Add(sourceDataLabel);
            DataFileTextbox           = new TextBox();
            DataFileTextbox.Location  = new Point(DataFileButton.Bounds.Left, DataFileButton.Bounds.Bottom + 5);
            DataFileTextbox.Size      = new Size(300, 300);
            DataFileTextbox.Multiline = true;
            DataFileTextbox.WordWrap  = false;
            DataFileTextbox.BackColor = GuiStyle.DARK_GREY;
            DataFileTextbox.ForeColor = GuiStyle.TEXT_COLOR;
            DataFileTextbox.Font      = GuiStyle.Font;
            DataFileTextbox.Text      = Cfg.SourceFiles.Replace("\n", "\r\n");
            if (!string.IsNullOrEmpty(DataFileTextbox.Text))
            {
                DataFileButton.SetImage(GuiButton.ButtonImage.GREEN_WHITE);
                DataLiveButton.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
            }
            DataFileTextbox.TextChanged += (sender, e) =>
            {
                Cfg.SourceFiles = DataFileTextbox.Text;
            };
            GuiBox.Controls.Add(DataFileTextbox);

            // Add the GUI for selecting the data scripts
            DataScriptListPanel             = new Panel();
            DataScriptListPanel.Location    = new Point(DataFileTextbox.Bounds.Right + 25, DataFileTextbox.Location.Y);
            DataScriptListPanel.Size        = new Size(150, DataFileTextbox.Height);
            DataScriptListPanel.BorderStyle = BorderStyle.FixedSingle;
            DataScriptListPanel.ForeColor   = GuiStyle.PRICE_COLOR_POSITIVE;
            GuiBox.Controls.Add(DataScriptListPanel);
            Label dataScriptsLabel = new Label();

            dataScriptsLabel.Text      = "Data Analysis Scripts";
            dataScriptsLabel.ForeColor = GuiStyle.PRICE_COLOR_POSITIVE;
            dataScriptsLabel.Font      = GuiStyle.Font;
            dataScriptsLabel.Location  = new Point(DataScriptListPanel.Bounds.Left, (DataScriptListPanel.Bounds.Top - dataScriptsLabel.Height) + 5);
            GuiBox.Controls.Add(dataScriptsLabel);
            DataScriptListScrollbar             = new CustomControls.CustomScrollbar();
            DataScriptListScrollbar.Minimum     = 0;
            DataScriptListScrollbar.Maximum     = DataScriptListPanel.Height;
            DataScriptListScrollbar.LargeChange = DataScriptListScrollbar.Maximum / DataScriptListScrollbar.Height;
            DataScriptListScrollbar.SmallChange = 15;
            DataScriptListScrollbar.Value       = 0;
            DataScriptListScrollbar.Attach(DataScriptListPanel);
            GuiBox.Controls.Add(DataScriptListScrollbar);
            DataScriptAddButton          = new GuiButton("Add...");
            DataScriptAddButton.Location = new Point(DataScriptListPanel.Location.X + 5, DataScriptListPanel.Bounds.Bottom + 5);
            DataScriptAddButton.MouseUp += (sender, e) =>
            {
                System.Windows.Forms.OpenFileDialog diag = new System.Windows.Forms.OpenFileDialog();
                diag.Multiselect = true;
                diag.Filter      = "C# Files|*.cs";
                diag.Title       = "Open stock data script(s)...";
                string prevPath = diag.InitialDirectory;
                diag.InitialDirectory = Cfg.DataScriptPath;
                diag.RestoreDirectory = false;
                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (string scriptPath in diag.FileNames)
                    {
                        Cfg.DataScriptPath = Path.GetDirectoryName(scriptPath);

                        // Skip this item if it has already been loaded
                        var script = scriptPath;
                        if (Cfg.DataScripts.Contains(script))
                        {
                            continue;
                        }

                        AddDataScript(script);
                        Cfg.DataScripts.Add(script);
                    }
                }
            };
            foreach (var script in Cfg.DataScripts)
            {
                AddDataScript(script);
            }
            GuiBox.Controls.Add(DataScriptAddButton);
            DataScriptReloadButton          = new GuiButton("Reload");
            DataScriptReloadButton.Location = new Point(DataScriptAddButton.Right + 5, DataScriptAddButton.Top);
            DataScriptAddButton.MouseUp    += (sender, e) =>
            {
                if (StockSession.Instance != null)
                {
                    StockSession.Instance.Reload();
                }
            };
            GuiBox.Controls.Add(DataScriptReloadButton);

            // Add the GUI for selecting the data scripts
            DecisionScriptListPanel             = new Panel();
            DecisionScriptListPanel.Location    = new Point(DataScriptListPanel.Bounds.Right + 25, DataScriptListPanel.Location.Y);
            DecisionScriptListPanel.Size        = new Size(450, DataFileTextbox.Height);
            DecisionScriptListPanel.BorderStyle = BorderStyle.FixedSingle;
            DecisionScriptListPanel.ForeColor   = GuiStyle.PRICE_COLOR_POSITIVE;
            GuiBox.Controls.Add(DecisionScriptListPanel);
            Label decisionScriptsLabel = new Label();

            decisionScriptsLabel.Text      = "Action Scripts";
            decisionScriptsLabel.ForeColor = GuiStyle.PRICE_COLOR_POSITIVE;
            decisionScriptsLabel.Font      = GuiStyle.Font;
            decisionScriptsLabel.Location  = new Point(DecisionScriptListPanel.Bounds.Left, (DecisionScriptListPanel.Bounds.Top - decisionScriptsLabel.Height) + 5);
            GuiBox.Controls.Add(decisionScriptsLabel);
            DecisionScriptListScrollbar             = new CustomControls.CustomScrollbar();
            DecisionScriptListScrollbar.Minimum     = 0;
            DecisionScriptListScrollbar.Maximum     = DecisionScriptListPanel.Height;
            DecisionScriptListScrollbar.LargeChange = DecisionScriptListScrollbar.Maximum / DecisionScriptListScrollbar.Height;
            DecisionScriptListScrollbar.SmallChange = 15;
            DecisionScriptListScrollbar.Value       = 0;
            DecisionScriptListScrollbar.Attach(DecisionScriptListPanel);
            GuiBox.Controls.Add(DecisionScriptListScrollbar);
            DecisionScriptAddButton          = new GuiButton("Add...");
            DecisionScriptAddButton.Location = new Point(DecisionScriptListPanel.Location.X + 5, DecisionScriptListPanel.Bounds.Bottom + 5);
            DecisionScriptAddButton.MouseUp += (sender, e) =>
            {
                DecisionScriptListPanel.Controls.Add(new ScriptTextBox(this, ""));
            };
            GuiBox.Controls.Add(DecisionScriptAddButton);
            DecisionScriptBrowseButton          = new GuiButton("Browse...");
            DecisionScriptBrowseButton.Location = new Point(DecisionScriptAddButton.Right + 5, DecisionScriptAddButton.Bounds.Top);
            DecisionScriptBrowseButton.MouseUp += (sender, e) =>
            {
                System.Windows.Forms.OpenFileDialog diag = new System.Windows.Forms.OpenFileDialog();
                diag.Multiselect = true;
                diag.Filter      = "C# Files|*.cs";
                diag.Title       = "Open stock data script(s)...";
                string prevPath = diag.InitialDirectory;
                diag.InitialDirectory = Cfg.DataScriptPath;
                diag.RestoreDirectory = false;
                if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    foreach (string scriptPath in diag.FileNames)
                    {
                        Cfg.DataScriptPath = Path.GetDirectoryName(scriptPath);

                        // Skip this item if it has already been loaded
                        var script = scriptPath;
                        if (Cfg.DataScripts.Contains(script))
                        {
                            continue;
                        }

                        Cfg.ActionScripts.Add(scriptPath);
                        DecisionScriptListPanel.Controls.Add(new ScriptTextBox(this, scriptPath));
                    }
                }
            };
            GuiBox.Controls.Add(DecisionScriptBrowseButton);

            foreach (var script in Cfg.ActionScripts)
            {
                DecisionScriptListPanel.Controls.Add(new ScriptTextBox(this, script));
            }


            // Create the start button
            var RunAllButton = new GuiButton("Start");

            RunAllButton.Location = new Point(DecisionScriptListPanel.Bounds.Right - RunAllButton.Width - 5, DecisionScriptListPanel.Bounds.Top - RunAllButton.Height - 5);
            RunAllButton.MouseUp += (sender, e) =>
            {
                foreach (var s in Scripts)
                {
                    s.Run();
                }
            };
            GuiPanel.Controls.Add(RunAllButton);


            // Create the back button to leave the screen
            BackButton          = new PictureBox();
            BackButton.Image    = Bitmap.FromFile("Content/GUI/Back.png");
            BackButton.Size     = BackButton.Image.Size;
            BackButton.Location = new Point(5, 0);
            GuiPanel.Controls.Add(BackButton);

            // Define the overall panel that everything else is contained inside
            GuiPanel.BackColor = GuiStyle.BACKGROUND_COLOR;
            GuiPanel.Controls.Add(GuiBox);
            GuiPanel.Resize += (sender, e) =>
            {
                GuiBox.Size     = new Size(GuiPanel.Width - BackButton.Width, 300);
                GuiBox.Location = new System.Drawing.Point(BackButton.Width + 10, 10);
            };

            // Specify the interface that should be used to add a chart to the screen
            Script.StockSession.AddToGui += (control) =>
            {
                if (control != null)
                {
                    control.Location = new Point(ChartButton.Location.X, ChartButton.Bottom + 5);
                    GuiPanel.Controls.Add(control);
                }
            };
            Script.StockSession.GuiContainer = (System.Windows.Forms.Control)GuiPanel;

            // Create a button which adds a chart to the screen
            ChartButton          = new GuiButton("Add Chart");
            ChartButton.Location = new Point(5, DataFileTextbox.Bottom + 25);
            ChartButton.MouseUp += (sender, e) =>
            {
                Script.StockSession.AddChart(Cfg.SourceFiles.Replace("\r", "").Split('\n').ToList(), Cfg.DataScripts);
            };
            GuiPanel.Controls.Add(ChartButton);
        }
Esempio n. 6
0
        public DataChartGui(Dictionary <string, List <StockDataInterface> > dataSets, StockSession session) : base(dataSets, session)
        {
            GuiPanel             = new Panel();
            GuiPanel.Size        = new System.Drawing.Size(600, 300);
            GuiPanel.AutoSize    = false;
            GuiPanel.BackColor   = GuiStyle.BACKGROUND_COLOR;
            GuiPanel.BorderStyle = BorderStyle.FixedSingle;
            EventHandler resizeHandler = (sender, e) =>
            {
                GuiPanel.Size = new System.Drawing.Size(GuiPanel.Parent.Width - 50, GuiPanel.Parent.Height - GuiPanel.Top - 50);
            };

            GuiPanel.ParentChanged += (sender, e) =>
            {
                GuiPanel.Parent.Resize += resizeHandler;
                resizeHandler(sender, e);
            };
            GuiPanel.Resize += (sender, e) =>
            {
                SymbolTextbox.Location           = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), 5);
                SymbolNextButton.Location        = new Point(SymbolTextbox.Right + 5, SymbolTextbox.Top);
                SymbolPrevButton.Location        = new Point(SymbolTextbox.Left - 5 - SymbolPrevButton.Width, SymbolTextbox.Top);
                SaveImageButton.Location         = new System.Drawing.Point(GuiPanel.Width - (SaveImageButton.Width) - 5, 5);
                ChartDescriptionTextbox.Location = new Point(SymbolNextButton.Right + 15, SymbolTextbox.Top);
                ChartDescriptionTextbox.Size     = new Size((SaveImageButton.Left - ChartDescriptionTextbox.Left) - 15, ChartDescriptionTextbox.Height);
                XAxisTextbox.Location            = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), GuiPanel.Height - XAxisTextbox.Height - 10);
            };

            // Create the symbol search textbox
            SymbolTextbox           = new TextBox();
            SymbolTextbox.BackColor = GuiStyle.DARK_GREY;
            SymbolTextbox.ForeColor = GuiStyle.TEXT_COLOR;
#if false
            SymbolTextbox.AutoCompleteMode   = AutoCompleteMode.Suggest;
            SymbolTextbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            SymbolTextbox.TextChanged       += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestSymbols(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
#endif
            SymbolTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    SetPlotLineSymbol(SymbolTextbox.Text);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolTextbox);

            // Create the next and previous arrows for the symbol list
            SymbolNextButton        = new PictureBox();
            SymbolNextButton.Image  = System.Drawing.Bitmap.FromFile("Content/GUI/ArrowRight.png");
            SymbolNextButton.Size   = SymbolNextButton.Image.Size;
            SymbolNextButton.Click += (sender, e) =>
            {
                var allSymbols = DataSets.Keys.ToList();
                if (allSymbols.Count > 0)
                {
                    SetPlotLineSymbol(allSymbols[Math.Min(allSymbols.IndexOf(SymbolTextbox.Text) + 1, allSymbols.Count - 1)]);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolNextButton);
            SymbolPrevButton       = new PictureBox();
            SymbolPrevButton.Image = System.Drawing.Bitmap.FromFile("Content/GUI/ArrowRight.png");
            SymbolPrevButton.Image.RotateFlip(RotateFlipType.RotateNoneFlipX);
            SymbolPrevButton.Size   = SymbolPrevButton.Image.Size;
            SymbolPrevButton.Click += (sender, e) =>
            {
                var allSymbols = DataSets.Keys.ToList();
                if (allSymbols.Count > 0)
                {
                    SetPlotLineSymbol(allSymbols[Math.Max(allSymbols.IndexOf(SymbolTextbox.Text) - 1, 0)]);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolPrevButton);

            ChartDescriptionTextbox = SymbolTextbox.Clone();
            GuiPanel.Controls.Add(ChartDescriptionTextbox);

            XAxisTextbox              = SymbolTextbox.Clone();
            XAxisTextbox.Text         = "Time";
            XAxisTextbox.TextChanged += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestExpressions(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
            XAxisTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    try
                    {
                        SetXAxis(XAxisTextbox.Text);
                        ErrorMessageLabel.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        ErrorMessageLabel.Text    = ex.ToString();
                        ErrorMessageLabel.Visible = true;
                    }
                }
            };
            GuiPanel.Controls.Add(XAxisTextbox);
            XAxisValue                    = new Label();
            XAxisValue.Font               = GuiStyle.Font;
            XAxisValue.ForeColor          = GuiStyle.TEXT_COLOR;
            XAxisTextbox.LocationChanged += (sender, e) =>
            {
                XAxisValue.Location = new System.Drawing.Point(XAxisTextbox.Right + 5, XAxisTextbox.Top);
            };
            XAxisValue.Size      = new System.Drawing.Size(250, XAxisValue.Height);
            XAxisValue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            GuiPanel.Controls.Add(XAxisValue);

            AddPlotButton        = new PictureBox();
            AddPlotButton.Image  = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Add.png");
            AddPlotButton.Click += (sender, e) =>
            {
                AddPlotLine();
            };
            GuiPanel.Controls.Add(AddPlotButton);

            // Add the interactive chart controls
            Plot.AddInteraction(new PlotDrag(true, true));
            Plot.AddInteraction(Hover = new HoverInteraction(this));
            LineDrawer = new LineInteraction(this);
            Plot.AddInteraction(LineDrawer);

            var plotCanvas = base.Canvas;
            GuiPanel.Resize += (sender, e) =>
            {
                if ((GuiPanel.Width > 250) && (GuiPanel.Height > 75))
                {
                    plotCanvas.Size     = new System.Drawing.Size(GuiPanel.Width - 250, GuiPanel.Height - 75);
                    plotCanvas.Location = new System.Drawing.Point(GuiPanel.Width - plotCanvas.Width - 5, (GuiPanel.Height - plotCanvas.Height) / 2);
                }
            };
            GuiPanel.Controls.Add(plotCanvas);

            ErrorMessageLabel           = new Label();
            ErrorMessageLabel.ForeColor = GuiStyle.PRICE_COLOR_NEGATIVE;
            ErrorMessageLabel.BackColor = GuiStyle.DARK_GREY;
            ErrorMessageLabel.AutoSize  = false;
            ErrorMessageLabel.Visible   = false;
            ErrorMessageLabel.Width     = plotCanvas.Width - 10;
            ErrorMessageLabel.Height    = plotCanvas.Height - 10;
            plotCanvas.Resize          += (sender, e) =>
            {
                ErrorMessageLabel.Width  = plotCanvas.Width - 10;
                ErrorMessageLabel.Height = plotCanvas.Height - 10;
            };
            ErrorMessageLabel.Location  = new Point(plotCanvas.Left + 5, plotCanvas.Bottom - ErrorMessageLabel.Height - 5);
            plotCanvas.LocationChanged += (sender, e) =>
            {
                ErrorMessageLabel.Location = new Point(plotCanvas.Left + 5, plotCanvas.Top + 5);
            };
            GuiPanel.Controls.Add(ErrorMessageLabel);
            ErrorMessageLabel.BringToFront();

            // Add the button to reload the session
            SaveImageButton          = new GuiButton("Save Img");
            SaveImageButton.Location = new System.Drawing.Point(GuiPanel.Width - (SaveImageButton.Width / 2) - 5, 5);
            SaveImageButton.Click   += (sender, e) =>
            {
                var saveDiag = new System.Windows.Forms.SaveFileDialog();
                saveDiag.Title    = "Save chart image...";
                saveDiag.FileName = SymbolTextbox.Text + "_" + ChartDescriptionTextbox.Text + ".png";
                if (saveDiag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    SaveImage(saveDiag.FileName);
                }
            };
            GuiPanel.Controls.Add(SaveImageButton);

            ChartChanged += () =>
            {
                XAxisTextbox.Text = XAxis;
                foreach (var l in Lines)
                {
                    if (!l.Locked)
                    {
                        SymbolTextbox.Text = l.Symbol;
                        break;
                    }
                }
            };

            // Start with one line
            AddPlotLine("Price");

            // Reload the chart when the session is reloaded
            session.OnReload += ReloadData;
        }
Esempio n. 7
0
        public DataChartGui(Dictionary <string, List <StockDataInterface> > dataSets, StockSession session) : base(dataSets, session)
        {
            GuiPanel             = new Panel();
            GuiPanel.Size        = new System.Drawing.Size(600, 300);
            GuiPanel.AutoSize    = true;
            GuiPanel.BackColor   = GuiStyle.BACKGROUND_COLOR;
            GuiPanel.BorderStyle = BorderStyle.FixedSingle;
            EventHandler resizeHandler = (sender, e) =>
            {
                GuiPanel.Size          = new System.Drawing.Size(GuiPanel.Parent.Width - 50, GuiPanel.Height);
                SymbolTextbox.Location = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), 5);
                int intervalBtnPos = SymbolTextbox.Right + 5;
                foreach (var pair in IntervalButtons)
                {
                    pair.Item1.Location = new Point(intervalBtnPos, SymbolTextbox.Top);
                    intervalBtnPos      = pair.Item1.Right + 5;
                }
                ReloadButton.Location = new System.Drawing.Point(GuiPanel.Width - (ReloadButton.Width / 2) - 5, 5);
                XAxisTextbox.Location = new System.Drawing.Point((GuiPanel.Width / 2) - (SymbolTextbox.Width / 2), GuiPanel.Height - XAxisTextbox.Height - 10);
            };

            GuiPanel.ParentChanged += (sender, e) =>
            {
                GuiPanel.Parent.Resize += resizeHandler;
                resizeHandler(sender, e);
            };

            // Create the symbol search textbox
            SymbolTextbox                    = new TextBox();
            SymbolTextbox.BackColor          = GuiStyle.DARK_GREY;
            SymbolTextbox.ForeColor          = GuiStyle.TEXT_COLOR;
            SymbolTextbox.AutoCompleteMode   = AutoCompleteMode.Suggest;
            SymbolTextbox.AutoCompleteSource = AutoCompleteSource.CustomSource;
            SymbolTextbox.TextChanged       += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestSymbols(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
            SymbolTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    SetSymbolInterval();
                    SetPlotLineSymbol(SymbolTextbox.Text);
                    this.Refresh();
                }
            };
            GuiPanel.Controls.Add(SymbolTextbox);

            XAxisTextbox              = SymbolTextbox.Clone();
            XAxisTextbox.Text         = "Time";
            XAxisTextbox.TextChanged += (sender, e) =>
            {
                TextBox t = (TextBox)sender;
                if (t.Text.Length >= 1)
                {
                    // Get the available symbols matching the search string
                    AutoCompleteStringCollection collection = new AutoCompleteStringCollection();
                    collection.AddRange(SuggestExpressions(t.Text));

                    t.AutoCompleteCustomSource = collection;
                }
            };
            XAxisTextbox.KeyDown += (s, eventArgs) =>
            {
                if (eventArgs.KeyCode == Keys.Enter)
                {
                    try
                    {
                        SetXAxis(XAxisTextbox.Text);
                        ErrorMessageLabel.Visible = false;
                    }
                    catch (Exception ex)
                    {
                        ErrorMessageLabel.Text    = ex.ToString();
                        ErrorMessageLabel.Visible = true;
                    }
                }
            };
            GuiPanel.Controls.Add(XAxisTextbox);
            XAxisValue                    = new Label();
            XAxisValue.Font               = GuiStyle.Font;
            XAxisValue.ForeColor          = GuiStyle.TEXT_COLOR;
            XAxisTextbox.LocationChanged += (sender, e) =>
            {
                XAxisValue.Location = new System.Drawing.Point(XAxisTextbox.Right + 5, XAxisTextbox.Top);
            };
            XAxisValue.Size      = new System.Drawing.Size(250, XAxisValue.Height);
            XAxisValue.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
            GuiPanel.Controls.Add(XAxisValue);

            AddPlotButton        = new PictureBox();
            AddPlotButton.Image  = System.Drawing.Bitmap.FromFile("Content/GUI/Button_Add.png");
            AddPlotButton.Click += (sender, e) =>
            {
                AddPlotLine();
            };
            GuiPanel.Controls.Add(AddPlotButton);

            // Add the interactive chart controls
            Plot.AddInteraction(new PlotDrag(true, true));
            Plot.AddInteraction(new HoverInteraction(this));

            var plotCanvas = base.Canvas;

            GuiPanel.Resize += (sender, e) =>
            {
                plotCanvas.Size     = new System.Drawing.Size(GuiPanel.Width - 250, GuiPanel.Height - 75);
                plotCanvas.Location = new System.Drawing.Point(GuiPanel.Width - plotCanvas.Width - 5, (GuiPanel.Height - plotCanvas.Height) / 2);
            };
            GuiPanel.Controls.Add(plotCanvas);

            ErrorMessageLabel           = new Label();
            ErrorMessageLabel.ForeColor = GuiStyle.PRICE_COLOR_NEGATIVE;
            ErrorMessageLabel.BackColor = GuiStyle.DARK_GREY;
            ErrorMessageLabel.AutoSize  = false;
            ErrorMessageLabel.Visible   = false;
            ErrorMessageLabel.Width     = plotCanvas.Width - 10;
            ErrorMessageLabel.Height    = plotCanvas.Height - 10;
            plotCanvas.Resize          += (sender, e) =>
            {
                ErrorMessageLabel.Width  = plotCanvas.Width - 10;
                ErrorMessageLabel.Height = plotCanvas.Height - 10;
            };
            ErrorMessageLabel.Location  = new Point(plotCanvas.Left + 5, plotCanvas.Bottom - ErrorMessageLabel.Height - 5);
            plotCanvas.LocationChanged += (sender, e) =>
            {
                ErrorMessageLabel.Location = new Point(plotCanvas.Left + 5, plotCanvas.Top + 5);
            };
            GuiPanel.Controls.Add(ErrorMessageLabel);
            ErrorMessageLabel.BringToFront();

            foreach (var pair in IntervalButtons)
            {
                pair.Item1.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
                pair.Item1.Click += (sender, e) =>
                {
                    // Update the selected button (first)
                    foreach (var p in IntervalButtons)
                    {
                        p.Item1.SetImage(GuiButton.ButtonImage.GREEN_TRANSPARENT);
                    }
                    pair.Item1.SetImage(GuiButton.ButtonImage.GREEN_WHITE);

                    // Set the new interval
                    SetSymbolInterval();
                    foreach (var l in Lines)
                    {
                        l.Generate(this);
                    }
                    Refresh();
                };
                GuiPanel.Controls.Add(pair.Item1);
            }
            IntervalButtons[0].Item1.SetImage(GuiButton.ButtonImage.GREEN_WHITE);

            // Add the button to reload the session
            ReloadButton          = new GuiButton("Reload");
            ReloadButton.Location = new System.Drawing.Point(GuiPanel.Width - (ReloadButton.Width / 2) - 5, 5);
            ReloadButton.Click   += (sender, e) =>
            {
                Session.Reload();
            };
            GuiPanel.Controls.Add(ReloadButton);

            ChartChanged += () =>
            {
                XAxisTextbox.Text = XAxis;
                foreach (var l in Lines)
                {
                    if (!l.Locked)
                    {
                        SymbolTextbox.Text = l.Symbol;
                        break;
                    }
                }
            };

            // Start with one line
            AddPlotLine("Price");

            // Reload the chart when the session is reloaded
            session.OnReload += ReloadData;
        }