Kindly help.
public class WinUiIndicator : Indicator
{
private System.Windows.Controls.Canvas canvasForListView;
private System.Windows.Controls.ListView listViewData = null;
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"ListView for Data";
Name = "WinUiIndicator";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
}
else if (State == State.Configure)
{
}
else if (State == State.Historical)
{
// Because we're dealing with UI elements, we need to use the Dispatcher which created the object
// otherwise we will run into threading errors...
// e.g, "Error on calling 'OnStateChange' method: You are accessing an object which resides on another thread."
// Furthermore, we will do this operation Asynchronously to avoid conflicts with internal NT operations
ChartControl.Dispatcher.InvokeAsync((() =>
{
// Grid already exists
if (UserControlCollection.Contains(canvasForListView) )
return;
// Add a control grid which will host our custom buttons
canvasForListView = new System.Windows.Controls.Canvas
{
Name = "CanvasForListView",
// Align the control to the top right corner of the chart
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
Background = Brushes.Red,
Height = 200,
Width = 1000,
};
listViewData = new ListView();
GridView gridView = new GridView();
GridViewColumn nameColumn = new GridViewColumn { Header = "Name", DisplayMemberBinding = new Binding("Name") };
GridViewColumn ageColumn = new GridViewColumn { Header = "Age", DisplayMemberBinding = new Binding("Age") };
gridView.Columns.Add(nameColumn);
gridView.Columns.Add(ageColumn);
listViewData.View = gridView;
ObservableCollection<Person> people = new ObservableCollection<Person>
{
new Person { Name = "John Doe", Age = 30 },
new Person { Name = "Jane Smith", Age = 25 }
};
listViewData.ItemsSource = people;
Canvas.SetLeft(listViewData, 100);
canvasForListView.Children.Add(listViewData);
// Finally, add the completed grid to the custom NinjaTrader UserControlCollection
UserControlCollection.Add(canvasForListView);
}));
}
}
private void SendMessage(string functionName)
{
ClearOutputWindow();
DateTime dt = DateTime.Now;
Print($"I am inside {functionName} and Time is {dt.ToLongTimeString()}");
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
}
}

Comment