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 sjsj2732, Today, 04:31 AM
    0 responses
    20 views
    0 likes
    Last Post sjsj2732  
    Started by NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    280 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    279 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    130 views
    1 like
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    90 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Working...
    X