Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

The addon does not run completely

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

    The addon does not run completely

    Hello,

    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:

    Code:
    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);
    }
    }​
    ConfigureControls function

    Code:
    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:

    Code:
    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);
    }​
    This is the log that shows what the code does:

    Code:
    NinjaScript Editor
    Chart - Chart
    Configurecontrols
    PASA1
    quantityUpDown -> 0
    PASA2
    OnStateChange -> Terminated
    quantitySelected -> 1
    accountSelected -> XXXXXXXX​
    The code stops between PASA2 and PASA3, after configure account selector event (accountSelector.SelectionChanged += OnAccountSelectionChanged), because the two events are fired.
    I can see, in the middle of execution, the OnStateChange (Terminated) is fired.

    If I compile the addon, runs OK


    Could you help me?


    ​​​​​​​​

    #2
    Hello Powerbucker,

    I recommend you start with a working script.

    Copy this.

    And in the copy modify the script to add your code one line at a time until the behavior returns.

    The last added code is likely causing the behavior.

    Below is a link to a working sample addon script to get you started.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    566 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 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
    547 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X