Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnBarUpdate'

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

    Error on calling 'OnBarUpdate'


    Hello, sometimes the strategy gives me this error message and it disconnects, I don't know how to solve it so that it doesn't happen



    the error is; Strategy 'Bot1': Error on calling 'OnBarUpdate' method on bar 3142: The calling thread cannot access this object because a different thread owns it.


    One conclusion is that when drawing elements with a fixed name, you can then remove them with "removedrawnobject", but this should not be a problem since it only draws that object when a series of variables are given and if they are not given, "else" eliminates them he removes.


    This strategy should look back at most 120 bars, but nevertheless it calculates further and gives me this error.


    I would like to know if there is any way to avoid it, thanks as always for the help



    #2
    Hello RubenCazorla,

    The error that you are seeing would generally happen by incorrectly accessing user interface items from NinjaScript code. If you are working with anything that creates buttons/GUI elements or accesses values from the user interface that would happen without using a Dispatcher.

    To solve this error you would need to isolate the part of the OnBarUpdate logic which is having the error. You can comment out code and re test to find which part contributes to that.

    Comment


      #3

      I was able to solve it
      Last edited by RubenCazorla; 09-12-2022, 07:31 AM.

      Comment


        #4
        Dispatcher use inside onBarUpdate (working)

        Code:
        protected override void OnBarUpdate()
        {
            if ( condition1 )
            {
        
                if (ChartControl != null)
                {
                    ChartControl.Dispatcher.InvokeAsync(() =>
                    {
                        EnterShort(quantitySelector.Value, "Short Entry");
                    });
                }​
            }​
        }

        ( not working, previous error " Calling thread cannot access object because different thread owns it" )

        Code:
        ​​​​​​​protected override void OnBarUpdate()
        {
            if ( condition1 )
            {
                EnterShort(quantitySelector.Value, "Short Entry");
            }​
        }​

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by CarlTrading, 05-11-2026, 05:56 AM
        0 responses
        61 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 05-10-2026, 08:12 PM
        0 responses
        34 views
        0 likes
        Last Post CarlTrading  
        Started by Hwop38, 05-04-2026, 07:02 PM
        0 responses
        198 views
        0 likes
        Last Post Hwop38
        by Hwop38
         
        Started by CaptainJack, 04-24-2026, 11:07 PM
        0 responses
        364 views
        0 likes
        Last Post CaptainJack  
        Started by Mindset, 04-21-2026, 06:46 AM
        0 responses
        283 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X