Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need help in account selection from chart trader

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

    Need help in account selection from chart trader

    Hi,

    I created a simple indicator that has buy/sell buttons to place pending orders.
    The indicator works perfectly on sim account, but when i change the account from the chart trader, the script stops working.

    In the SetDefaults i search for the Sim account :

    lock (Account.All)
    Code:
    myAccount = Account.All.FirstOrDefault(a => a.Name == "Sim101");​
    Then, in the OnBarUpdate I added a piece of code that checks on each tick if the account has changed :

    Code:
    ChartControl.Dispatcher.InvokeAsync((Action)(() =>
                    {
                        xAlselector = Window.GetWindow(ChartControl.Parent).FindFirst("ChartTraderControlAccountSelector") as NinjaTrader.Gui.Tools.AccountSelector;
                        AccName = xAlselector.SelectedAccount.Name;
                    }));​
    This correctly prints the current account, selected in the chart trader.
    After that, i want to place my pending order :

    Code:
        TriggerCustomEvent(o =>
                    {
                        //Order stopOrder = null;
                
        
                        longOrder = myAccount.CreateOrder(Instrument,
                        OrderAction.Buy,
                        OrderType.StopMarket,
                        TimeInForce.Day,
                        nContractQuantity,
                        0,
                        longprice,
                        string.Empty,
                        "Entry",
                        null);
    
                        // Submits our entry order with the ATM strategy named "myAtmStrategyName"
                        NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy(AtmStrategyName1, longOrder);
                        myAccount.Submit(new[] { longOrder });
                        }, null);​



    It is all working well on the Sim account, however i have a feeling that the myAccount variable is still on the Sim and does not update when I change the account from the chart trader.

    If this is the case, how can i set the myAccount variable to the correct account?

    Thank you very much

    #2
    Hello,

    Are you using .SelectionChanged to detect when the account selected has changed?



    There is also a sample script written by a forum user that detects selection changed events.

    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