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 Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    553 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
    100 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    543 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    546 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X