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

Use shared value from Indicator in Addon (OnStateChange)

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

    Use shared value from Indicator in Addon (OnStateChange)

    Hi, I have the following problem:

    I want to save the instrument name from the indicator to a variable and use it when initializing an add-on. The problem now is that the OnStateChange() method is called by the add-on before setting the variables, and it is therefore "null" if it is to be used in the add-on. I need the instrument name that is loaded by the indicator so that the same instrument is used when loading the add-on from the indicator. The goal is to load the indicator in the chart as usual. This loads the add-on in the background with the same instrument that executes the OnMarketData and sends the values obtained in it back to the indicator.

    Click image for larger version

Name:	Screenshot_1.jpg
Views:	326
Size:	541.3 KB
ID:	1169394
    sidlercom80
    NinjaTrader Ecosystem Vendor - Sidi Trading

    #2
    Hello sidlercom80,

    Small disclaimer, using static classes is not officially supported and not documented, and using these can cause unexpected behavior.

    That said, try using State.Active instead. (See "Active States vs Data Processing States" in the help guide)


    Are you planning to open a new window in the addon? Below is a link to an example that submits the indicator instance to the addon class, so that static classes do not have to be used.
    https://ninjatrader.com/support/foru...548#post774548
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi _ChelseaB, thank you very much for your reply. Unfortunately, no variable value can be set in Status.Active, not even the print statement is executed. So that doesn't help me ;-)

      Click image for larger version

Name:	Screenshot_1.jpg
Views:	282
Size:	197.3 KB
ID:	1169483

      My idea would be to have an addon that runs the OnMarketData() once for all the indicators that the market data needs. If an indicator needs market data, the instrument name is given to the addon when called and the addon starts in the background with the calculations in OnMarketData and returns these values to the indicator. The addon does not have to be visible in a window, but should perform the calculations in the background.
      sidlercom80
      NinjaTrader Ecosystem Vendor - Sidi Trading

      Comment


        #4
        Hello sidlercom80,

        Does the variable have to be static?

        Can you make a public variable in the addon, and then assign this from the indicator?

        new MyAddon() { MyInstrument = Instrument }

        This would be similar to how my example supplies the host instance to the addon.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi _ChelseaB, no it does not have to be a static variable. If I follow your example, it is no problem to solve everything via a Windows (NTWindow). But I don't want an extra window. Only when loading the indicator, additionally load an addon that executes OnMarketData. The addon should receive the instrument from the indicator.
          sidlercom80
          NinjaTrader Ecosystem Vendor - Sidi Trading

          Comment


            #6
            Hello sidlercom80,

            Our development has let me know that addonbase classes only have the OnStateChange called at NinjaTrader startup or compile and not when a new instance of a class is made.

            In this case, create a public method, and trigger this method from the host script.

            public void InstanceStart()
            {
            Code.Output.Process(MyInstrument.ToString(), PrintTo.Tab1);
            }

            From the host script:
            MyAddon myAddy = new MyAddon() { MyInstrument = Instrument };
            myAddy.InstanceStart();
            Last edited by NinjaTrader_ChelseaB; 09-08-2021, 07:11 AM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi _ChelseaB, thanks for the tip, I'll try it out
              sidlercom80
              NinjaTrader Ecosystem Vendor - Sidi Trading

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by mjairg, 07-20-2023, 11:57 PM
              3 responses
              213 views
              1 like
              Last Post PaulMohn  
              Started by TheWhiteDragon, 01-21-2019, 12:44 PM
              4 responses
              544 views
              0 likes
              Last Post PaulMohn  
              Started by GLFX005, Today, 03:23 AM
              0 responses
              3 views
              0 likes
              Last Post GLFX005
              by GLFX005
               
              Started by XXtrader, Yesterday, 11:30 PM
              2 responses
              12 views
              0 likes
              Last Post XXtrader  
              Started by Waxavi, Today, 02:10 AM
              0 responses
              7 views
              0 likes
              Last Post Waxavi
              by Waxavi
               
              Working...
              X