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 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