Here are a couple examples I found. One puts it in the toolbar. the other places it in the upper right corner in a grid.
Is it possible to "render it" at coordinates on the chart that I specify?
I was unable to figure it out from the examples I found
thanks
private void AddButtonToToolbar()
{
_chartWindow = Window.GetWindow(this.ChartControl.Parent) as Chart;
if (_chartWindow == null)
{
Print("chartWindow == null");
return;
}
_button = CreateButton("BUY", "buybutton", Brushes.White, Brushes.DarkRed);
_button.Click += OnButtonBuyClick;
_chartWindow.MainMenu.Add(_button);
_isToolBarButtonAdded = true;
}
else if (State == State.Historical)
{
myFont12 = new NinjaTrader.Gui.Tools.SimpleFont("Ariel", 12);
myFont24 = new NinjaTrader.Gui.Tools.SimpleFont("Ariel", 24);
if (UserControlCollection.Contains(myGrid))
return;
Dispatcher.InvokeAsync((() =>
{
myGrid = new System.Windows.Controls.Grid
{
Name = "MyCustomGrid", HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top
};
System.Windows.Controls.ColumnDefinition column1 = new System.Windows.Controls.ColumnDefinition();
System.Windows.Controls.ColumnDefinition column2 = new System.Windows.Controls.ColumnDefinition();
myGrid.ColumnDefinitions.Add(column1);
myGrid.ColumnDefinitions.Add(column2);
longButton = new System.Windows.Controls.Button
{
Name = "LongButton", Content = "LONG", Foreground = Brushes.White, Background = Brushes.Green
};
shortButton = new System.Windows.Controls.Button
{
Name = "ShortButton", Content = "SHORT", Foreground = Brushes.Black, Background = Brushes.Red
};
longButton.Click += OnButtonClick;
shortButton.Click += OnButtonClick;
System.Windows.Controls.Grid.SetColumn(longButton, 0);
System.Windows.Controls.Grid.SetColumn(shortButton, 1);
myGrid.Children.Add(longButton);
myGrid.Children.Add(shortButton);
UserControlCollection.Add(myGrid);
}));
}
else if (State == State.Terminated)
{
Dispatcher.InvokeAsync((() =>
{
if (myGrid != null)
{
if (longButton != null)
{
myGrid.Children.Remove(longButton);
longButton.Click -= OnButtonClick;
longButton = null;
}
if (shortButton != null)
{
myGrid.Children.Remove(shortButton);
shortButton.Click -= OnButtonClick;
shortButton = null;
}
}
}));
}
}

Comment