Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

why the following has to be called within ChartControl.Dispa

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

    why the following has to be called within ChartControl.Dispa

    Hi Bltdavid or Chelsea:

    can any of you explain why the following has to be called within ChartControl.Dispatcher.InvokeAsync​ () ? Can I just place all codes within OnButtonClick() with using InvokeAsync?
    much appreciated !

    {
    ChartControl.Dispatcher.InvokeAsync((Action)(() => {

    Account a = ChartControl.OwnerChart.ChartTrader.Account;
    int quantity = ChartControl.OwnerChart.ChartTrader.Quantity;
    AtmStrategy atm = ChartControl.OwnerChart.ChartTrader.AtmStrategy;
    Instrument instr = ChartControl.OwnerChart.ChartTrader.Instrument;
    Order order1 = a.CreateOrder(instr, OrderAction.Buy,
    OrderType.Market, OrderEntry.Automated, TimeInForce.Day, quantity, 0, 0, "", "Entry",
    Core.Globals.MaxDate, null);


    Order order2 = a.CreateOrder(Cbi.Instrument.GetInstrument ("NQ 12-24"), OrderAction.SellShort,
    OrderType.Market, OrderEntry.Automated, TimeInForce.Day, quantity, 0, 0, "", "Entry",
    Core.Globals.MaxDate, null);

    if (atm == null)
    // was set to 'None'
    a.Submit(new[] { order1,order2 });


    }));
    }​

    #2
    Hello judysamnt7,

    Anything that runs on the UI thread needs to be accessed from the ChartControl dispatcher with InvokeAysnc().

    When modifying the WPF of a chart, such as placing a button, or when using ChartControl objects the dispatcher must be used.

    The account, does not need to be accessed with a dispatcher to send orders, but is generally thread-safe and can be within a dispatcher.

    Below is a link to an example that submits orders with button clicks.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    128 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    73 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    116 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    109 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    88 views
    0 likes
    Last Post CarlTrading  
    Working...
    X