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

On state change method error

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

    On state change method error

    Hi, my indicator shows the below error:
    Error on calling "Onstatechange" method: The calling thread must be STA, because many UI components require this.
    my indicator uses addon dll file. Can you please tell, why the above error may be showing?

    #2
    Hello asmmbillah,

    Thank you for your post.

    So that we may accurately assist you, please provide the following information.
    • What is the name of the AddOn dll file?
    • Where did you get the AddOn .dll file from?
    • How are you setting up/calling the .dll file within your script?
    Thanks in advance, I look forward to your reply.
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hello, good morning:
      I have the same error "Indicator 'SetIndicatorValueFromAddonWindowExample': Error on calling 'OnStateChange' method: The calling thread must be STA, because many UI components require this."

      The indicator and the addon are a NT8 exampleshowing how to launch an an addon from an indicator, from a button on it.

      I am trying to Launch the AddOn at the "OnstateChange" to apply it to my development which needs to launch the AddOn at early stages of an Indicator...
      I just move the lines where the addon were launch from the button click to the transition stage

      Code:
       else if (State == State.Transition)
      {
      // if (setIndicatorValueFromAddonWindowExampleToolsWindo w == null || setIndicatorValueFromAddonWindowExampleToolsWindow .IsVisible == false)
      // {
      Print("Before");
      setIndicatorValueFromAddonWindowExampleToolsWindow = new AddOns.SampleAddOns.SetIndicatorValueFromAddonWind owExampleToolsWindow();
      Print("after");
      // {
      // // set an internal property of the addon to this indicator to send information back
      // TargetIndicator = this
      // };
      // }
      // // open the window
      
      setIndicatorValueFromAddonWindowExampleToolsWindow .Show();
      // // bring to the top
      setIndicatorValueFromAddonWindowExampleToolsWindow .Activate();
      }
      Your help is highly appreciated
      Thank you
      Attached Files

      Comment


        #4
        Hello efeuvejota01,

        Thanks for your note.

        It seems that you may have reposted the original script created by my colleague Chelsea located in the forum thread linked below.



        That said, I see in the commented out code you posted that you are missing the use of a dispatcher for the UI in your script. This dispatcher is not missing from the attached file or the original indicator script.

        Please see the original script in the forum thread linked above which demonstrates using a dispatcher in the script.

        Also, see the help guide documentation below for more information about dispatchers.

        Multi-threading Condisterations for NinjaScript: https://ninjatrader.com/support/help...sub=dispatcher

        NinjaScript Best Practices: https://ninjatrader.com/support/help...sub=dispatcher

        Let us know if we may assist further.

        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Perr0Grande, Today, 08:16 PM
        0 responses
        2 views
        0 likes
        Last Post Perr0Grande  
        Started by elderan, Today, 08:03 PM
        0 responses
        4 views
        0 likes
        Last Post elderan
        by elderan
         
        Started by algospoke, Today, 06:40 PM
        0 responses
        10 views
        0 likes
        Last Post algospoke  
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        10 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        7 views
        0 likes
        Last Post quantismo  
        Working...
        X