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 Hwop38, 05-04-2026, 07:02 PM
    0 responses
    150 views
    0 likes
    Last Post Hwop38
    by Hwop38
     
    Started by CaptainJack, 04-24-2026, 11:07 PM
    0 responses
    303 views
    0 likes
    Last Post CaptainJack  
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    243 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    345 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    174 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Working...
    X