Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Chart trader buttons position

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Chart trader buttons position

    Hi,

    i found a chart traders buttons example and want to adapt it to my needs.

    The original script had 4 buttons, i removed one to have only 3,but for the last week, i couldn't figure out how to place the CANCEL ( button 3 ) right below the LONG and SHORT buttons, and make it as wide as the two upper buttons together.
    Right now it looks like this :
    Click image for larger version

Name:	image.png
Views:	188
Size:	38.4 KB
ID:	1317083
    Would some be so king and add missing lines or adjust the code so the CANCEL button gets below the other two? I'm not familiar with this yet.
    Here's my code:
    Code:
        
            protected void InsertWPFControls()
            {
                chartTraderGrid = (Window.GetWindow(ChartControl.Parent).FindFirst("ChartWindowChartTraderControl") as ChartTrader).Content as System.Windows.Controls.Grid;
                chartTraderButtonsGrid = chartTraderGrid.Children[0] as System.Windows.Controls.Grid;
                myButtonsGrid = new System.Windows.Controls.Grid();
    
                chartTraderGrid.Children.Add(myButtonsGrid);
    
                // add a new space for our custom grid below the ask and bid prices
                chartTraderGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(445) });
    
                System.Windows.Controls.Grid.SetRow(myButtonsGrid, 270);
                System.Windows.Controls.Grid.SetColumn(myButtonsGrid, 70);
    
                chartTraderButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(100)    });
                // spacer row
                myButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(31) });
                myButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(31) });
                myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(100) });
                // spacer column
                myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(62) });
                myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(100) });
    
                newButton1 = new System.Windows.Controls.Button()
                {
                    Background = Brushes.Green,
                    BorderBrush = Brushes.DimGray,
                    Content = "LONG",
                    Height = 30
                };
    
                newButton2 = new System.Windows.Controls.Button()
                {
                    Background = Brushes.Red,
                    BorderBrush = Brushes.DimGray,
                    Content = "SHORT",
                    Height = 30
                };
    
                newButton3 = new System.Windows.Controls.Button()
                {
                    Background = Brushes.Gray,
                    BorderBrush = Brushes.DimGray,
                    Content = "CANCEL",
                    Height = 30
                };
    
    
    
                newButton1.Click += Button1Click;
                System.Windows.Automation.AutomationProperties.SetAutomationId(newButton1, "newButton1");
                chartTraderButtonsGrid.Children.Add(newButton1);
                System.Windows.Controls.Grid.SetRow(newButton1, 12);
    
                newButton2.Click += Button2Click;
                System.Windows.Automation.AutomationProperties.SetAutomationId(newButton2, "newButton2");
                chartTraderButtonsGrid.Children.Add(newButton2);
                System.Windows.Controls.Grid.SetRow(newButton2, 12);
                System.Windows.Controls.Grid.SetColumn(newButton2, 2);
    
                newButton3.Click += Button3Click;
                System.Windows.Automation.AutomationProperties.SetAutomationId(newButton3, "newButton3");
                myButtonsGrid.Children.Add(newButton3);
                System.Windows.Controls.Grid.SetColumn(newButton3, 0);
                System.Windows.Controls.Grid.SetRow(newButton3, 12);
    
    
            }​


    Thank you very much in advance!

    #2
    Hello gyilaoliver,

    Thank you for your post.

    It looks like you have added your button to the wrong grid - you're using myButtonsGrid with the custom columns/row but this grid isn't being used for the buttons. You've only added the 'Cancel' button to myButtonsGrid.

    Buttons 1 and 2 are using chartTraderButtonsGrid, but Button 3 is using myButtonsGrid.

    Please let us know if you need further assistance.

    Comment


      #3
      Hi Gaby,

      thanks for your reply.
      Actually the code is from a NinjaTrader staff ( i guess, as i found it somewhere here and was made by NinjaTrader_xxx ), so i used that as a base.

      I found the code that you mentioned, i changed it, now the cancel button covers the buy button... sorry for these dumb questions, totally new with wpfcontrol...
      [CODE][
      protected void InsertWPFControls()
      {
      chartTraderGrid = (Window.GetWindow(ChartControl.Parent).FindFirst(" ChartWindowChartTraderControl") as ChartTrader).Content as System.Windows.Controls.Grid;
      chartTraderButtonsGrid = chartTraderGrid.Children[0] as System.Windows.Controls.Grid;
      myButtonsGrid = new System.Windows.Controls.Grid();

      chartTraderGrid.Children.Add(myButtonsGrid);

      // add a new space for our custom grid below the ask and bid prices
      chartTraderGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(445) });

      System.Windows.Controls.Grid.SetRow(myButtonsGrid, 270);
      System.Windows.Controls.Grid.SetColumn(myButtonsGr id, 70);

      chartTraderButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(100) });
      // spacer row
      myButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(31) });
      myButtonsGrid.RowDefinitions.Add(new System.Windows.Controls.RowDefinition() { Height = new GridLength(31) });
      myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(100) });
      // spacer column
      myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(62) });
      myButtonsGrid.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition() { Width = new GridLength(100) });

      newButton1 = new System.Windows.Controls.Button()
      {
      Background = Brushes.Green,
      BorderBrush = Brushes.DimGray,
      Content = "LONG",
      Height = 30
      };

      newButton2 = new System.Windows.Controls.Button()
      {
      Background = Brushes.Red,
      BorderBrush = Brushes.DimGray,
      Content = "SHORT",
      Height = 30
      };

      newButton3 = new System.Windows.Controls.Button()
      {
      Background = Brushes.Gray,
      BorderBrush = Brushes.DimGray,
      Content = "CANCEL",
      Height = 30
      };



      newButton1.Click += Button1Click;
      System.Windows.Automation.AutomationProperties.Set AutomationId(newButton1, "newButton1");
      chartTraderButtonsGrid.Children.Add(newButton1);
      System.Windows.Controls.Grid.SetRow(newButton1, 12);

      newButton2.Click += Button2Click;
      System.Windows.Automation.AutomationProperties.Set AutomationId(newButton2, "newButton2");
      chartTraderButtonsGrid.Children.Add(newButton2);
      System.Windows.Controls.Grid.SetRow(newButton2, 12);
      System.Windows.Controls.Grid.SetColumn(newButton2, 2);

      newButton3.Click += Button3Click;
      System.Windows.Automation.AutomationProperties.Set AutomationId(newButton3, "newButton3");
      chartTraderButtonsGrid.Children.Add(newButton3);
      System.Windows.Controls.Grid.SetColumn(newButton3, 0);
      System.Windows.Controls.Grid.SetRow(newButton3, 24);


      }​
      /CODE]

      Click image for larger version

Name:	image.png
Views:	168
Size:	33.6 KB
ID:	1317131

      Comment


        #4
        Hello,

        I'm not sure what reference sample you're looking at - I recommend taking a look at the SampleWPFModifications script:



        You'll need to add rows to the grid, and then set the row of your button. In this sample, there is addedRow1 and addedRow2 - you'll need to add another row (addedRow3) in the same way.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        556 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        545 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X