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

Share strategy data with multiple instances of an indicator

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

    Share strategy data with multiple instances of an indicator

    I want to share unique data in a single instance of a strategy with all existing and new instances of an indicator. Obviously, I can create relevant data structures in the strategy and the indicator, but clearly I need something akin to a Singleton to ensure only a single instance of the data is referenced by the strategy and all instances of the indicator.

    Does anyone have any example code to do this, please?

    Many thanks.
    Multi-Dimensional Managed Trading
    jeronymite
    NinjaTrader Ecosystem Vendor - Mizpah Software

    #2
    Originally posted by jeronymite View Post
    I want to share unique data in a single instance of a strategy with all existing and new instances of an indicator. Obviously, I can create relevant data structures in the strategy and the indicator, but clearly I need something akin to a Singleton to ensure only a single instance of the data is referenced by the strategy and all instances of the indicator.

    Does anyone have any example code to do this, please?

    Many thanks.
    Data Structure marked static ?
    Last edited by koganam; 07-25-2016, 09:06 AM. Reason: Corrected spelling.

    Comment


      #3
      Hello,

      As koganam mentioned a static structure may be what you need.

      Potentially creating a static class for the different instances to access, this is more of a C# concept than a NinjaScript item so we do not specifically have any documentation on using static classes.

      There are a few simple examples on stackoverflow documentation here: http://stackoverflow.com/documentati...51438415293717

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Share strategy data with multiple instances of an indicator

        Thanks koganam and Jesse.

        I had previously tried this approach and found issues with it ... but then maybe that was because of the way I implemented it. I'll try again with a fresh view and a clean slate and see what I can do.

        Thanks.
        Multi-Dimensional Managed Trading
        jeronymite
        NinjaTrader Ecosystem Vendor - Mizpah Software

        Comment


          #5
          Share strategy data with multiple instances of an indicator

          OK. I have revisited my code to do this and updated using a static data array in a static class in a separate namespace.

          The issue I previously saw seems to still be there. (Obviously a gap in my knowledge/understanding/implementation.)

          The issue is simple. I set a value in the array in my strategy and expect all existing indicators on charts to use that value immediately. They appear not to, and I have to restart the indicators for them to use the value. Hence, my suspicion that instantiation might have been the problem.

          Clearly the data is visible to the strategy and indicators, but it is a question of the immediate availability of the data to instances of the indicators that use it.

          Also, even after restarting the indicator, it will pick up the values at the time of restart, but will not pick up changes to values made after that.

          Your thoughts/advice gratefully appreciated. Thanks.
          Multi-Dimensional Managed Trading
          jeronymite
          NinjaTrader Ecosystem Vendor - Mizpah Software

          Comment


            #6
            Hello,

            Thank you for the reply.

            The subsiquent indicators should be able to read the value immediately after it was set, but would not recieve any type of notification that the value had been changed in order to be updated. A OnBarUpdate/tick of market data etc would be required to drive the logic to check that value. A strategy could call the indciator after setting the value to get it to retrieve the new value.

            I have included a small sample that just shows a strategy setting a static value into a list. The indicator reads the list and gets its count. Each event is printed to the output window so you can see the indicator sees the same values as the strategy.

            Using static classes in NinjaTrader is considered a very advanced topic because you are essentially breaking away from the standard strategy/indicator design pattern. You are certainly free to develop what you want, but I wanted to mention this as the amount of help information regarding this subject is very limited. In most cases to update an indicators value, the strategy would pass that as a parameter of a call to ensure the value is set while being used.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Share strategy data with multiple instances of an indicator

              Thanks, Jesse.

              The indicator has CalculateOnBarClose=false and so OnBarUpdate is called for every tick. I have two local values within the indicator that are updated within OnBarUpdate along with the values set in the static variables. The two local values update as expected. The static variables in the indicator appear not to do so. I have Printed the values in the indicator and the strategy as I set them and I can see the local indicator values change, and the static values change in the strategy, but not in the indicator.

              Thoughts? Thanks.
              Multi-Dimensional Managed Trading
              jeronymite
              NinjaTrader Ecosystem Vendor - Mizpah Software

              Comment


                #8
                Hello,

                Could you provide a simple example of the structure you are using currently that is not working?

                I was able to see the sample I used working in the way I had expected, but if you are using a different approach or the same sample in a different way I would need to test it to really understand what may be happening.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by junkone, Today, 11:37 AM
                2 responses
                12 views
                0 likes
                Last Post junkone
                by junkone
                 
                Started by frankthearm, Yesterday, 09:08 AM
                12 responses
                43 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by quantismo, 04-17-2024, 05:13 PM
                5 responses
                35 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by proptrade13, Today, 11:06 AM
                1 response
                7 views
                0 likes
                Last Post NinjaTrader_Clayton  
                Started by love2code2trade, 04-17-2024, 01:45 PM
                4 responses
                35 views
                0 likes
                Last Post love2code2trade  
                Working...
                X