I have a problem with an addon, which has a strange behavior. When I open ninja with the addon activated (as default addon), it does not execute all the code of the addon, it stops suddenly
If I then recompile the addon, it works correctly.
The problem is when it is executed when ninja is opened.
This is the source code, in the event when a chart type window is opened, I want to look for the account selector and the position selector to capture the events.
Then I want to customize the charttrader buttons.
This is the source code:
OnWindowCreated event:
protected override void OnWindowCreated(Window window)
{
// We want to place our AddOn in the Control Center's menus
NinjaTrader.Code.Output.Process($"{window.Title}", PrintTo.OutputTab1);
if (window is Chart chart)
{
ConfigureControls(chart);
}
}
private void ConfigureControls(Chart chartWindow)
{
NinjaTrader.Code.Output.Process("Configurecontrols", PrintTo.OutputTab1);
// this is the entire chart trader area grid
Grid chartTraderGrid = (chartWindow.FindFirst("ChartWindowChartTraderControl") as ChartTrader).Content as Grid;
NinjaTrader.Code.Output.Process("PASA1", PrintTo.OutputTab1);
quantityUpDown = chartTraderGrid.FindFirst("ChartTraderControlQuantitySelector") as QuantityUpDown;
if (quantityUpDown != null)
{
quantityUpDown.ValueChanged += OnQuantityValueChanged;
commonData.quantitySelected = quantityUpDown.Value;
NinjaTrader.Code.Output.Process($"quantityUpDown -> {commonData.quantitySelected.ToString()}", PrintTo.OutputTab1);
}
NinjaTrader.Code.Output.Process("PASA2", PrintTo.OutputTab1);
accountSelector = chartTraderGrid.FindFirst("ChartTraderControlAccountSelector") as AccountSelector;
if (accountSelector != null)
{
accountSelector.SelectionChanged += OnAccountSelectionChanged;
commonData.accountSelected = accountSelector.SelectedAccount;
NinjaTrader.Code.Output.Process($"accountSelector -> {commonData.accountSelected.DisplayName}", PrintTo.OutputTab1);
}
NinjaTrader.Code.Output.Process("PASA3", PrintTo.OutputTab1);
}
Custom selectors events:
private void OnQuantityValueChanged (object sender, EventArgs args)
{
commonData.quantitySelected = quantityUpDown.Value;
NinjaTrader.Code.Output.Process($"quantitySelected -> {commonData.quantitySelected.ToString()}", PrintTo.OutputTab1);
}
private void OnAccountSelectionChanged (object sender, SelectionChangedEventArgs args)
{
commonData.accountSelected = accountSelector.SelectedAccount;
NinjaTrader.Code.Output.Process($"accountSelected -> {commonData.accountSelected.ToString()}", PrintTo.OutputTab1);
}
NinjaScript Editor Chart - Chart Configurecontrols PASA1 quantityUpDown -> 0 PASA2 OnStateChange -> Terminated quantitySelected -> 1 accountSelected -> XXXXXXXX
I can see, in the middle of execution, the OnStateChange (Terminated) is fired.
If I compile the addon, runs OK
Could you help me?

Comment