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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        131 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X