Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Cross Thread Problem?

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

    Cross Thread Problem?

    I'm using ChartTraderCustomButtonsExample coded by Chelsea Bell. I want to control one of the buttons from OnBarUpdate()


    protected override void OnBarUpdate()
    {
    if (enTrade)
    {
    buttonsArray[0].Foreground = Brushes.Black;
    if (!greenLight )
    {
    buttonsArray[0].Background = Brushes.Yellow;
    }
    else buttonsArray[0].Background = Brushes.LightGreen;

    if (!greenLight) EnterLongStopMarket(aL2[0]);
    else EnterShortStopMarket(aL[0] - TickSize);
    }

    }

    When this method is called I get "Strategy 'ChartTraderCustomButtonsExample': Error on calling 'OnBarUpdate' method on bar 2406: The calling thread cannot access this object because a different thread owns it"

    How should I code this correctly?

    #2
    Hello boreland,

    Thanks for your post.

    You will want to use a dispatcher to modify UI elements from OnBarUpdate.

    Code:
    ChartControl.Dispatcher.InvokeAsync(() =>
    {
        // Code to modify UI elements here
    });


    We look forward to assisting.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by lorem, Yesterday, 09:18 AM
    5 responses
    19 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by WHICKED, Today, 12:56 PM
    2 responses
    15 views
    0 likes
    Last Post WHICKED
    by WHICKED
     
    Started by Felix Reichert, Today, 02:12 PM
    0 responses
    1 view
    0 likes
    Last Post Felix Reichert  
    Started by Tim-c, Today, 02:10 PM
    0 responses
    1 view
    0 likes
    Last Post Tim-c
    by Tim-c
     
    Started by cre8able, Today, 01:16 PM
    2 responses
    9 views
    0 likes
    Last Post cre8able  
    Working...
    X