Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Dictionary <> Access by a Strategy

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

    Dictionary <> Access by a Strategy

    I've written an indicator that calculates values. I'd like to store them, then access them from a strategy. I'm thinking a Dictionary<> is the best way to do this. However, despite my best efforts, I don't know how to accomplish this. Yes, I've been able to access individual variables that are in an indicator, so that's not the issue.

    Any suggestions ?

    Please don't suggest a DataSeries because I don't want my data synced to the primary bars (I'm working with more than one time series and instrument); doing so adds dummy data which I don't want.
    Last edited by spottysallrite; 04-03-2018, 07:49 PM. Reason: clarification

    #2
    Hello spottysallrite,

    Thanks for opening the thread.

    I have attached an example based on SampleBoolSeries which exposes indicator values that are not plots. This example creates a dictionary in an indicator, exposes it, and demonstrates accessing it from a strategy. I have included a link to the SampleBoolSeries example for further reference on how this approach works.

    SampleBoolSeries - https://ninjatrader.com/support/foru...ead.php?t=4991

    Dictionaries are a generic C# concept. They will require a fully qualified namespace or will require a using declaration for System.Collections.Generic. More information on Dictionaries can be referenced externally in the MSDN documentation. I will provide a link below.

    Dictionaries - https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Please let me know if you have any questions.
    Attached Files

    Comment


      #3
      WORKS !!! Thanks much !

      Comment


        #4
        Jim, thanks.
        If the child indicator didnt have "update()" in getter, should we call Update() manually in the hosting indicator's onBarUpdate()??

        Comment


          #5
          Hello TazoTodua,

          Adding Update will be necessary to make sure that public properties which are not plots (synced Series<double> or DataSeries objects) are up to date when being being referenced externally.

          Adding Update to the public property's getter assures that Update gets called whenever that property is read. This would be recommended. You may also perform a test by removing the Update() call in the getter and testing with IndiDict.Update() before accessing the public dictionary property.

          For example:
          Code:
          IndiDict.Update();
          Print(IndiDict.MyDictionary.Count);
          We could test commenting the IndiDict.Update(); line with the Update removed from IndiDictionary and observing the result. We will see that the Update is required before accessing this property since it is not synchronized.

          If there is anything else I can do to help, please let me know.

          Comment


            #6
            No, my question intent was different.
            I mean situation, where in Child indi (which is not controlled by me) contains a public property (dictionary) which getter doesnt include the Update().

            So, in HOSTING indicator, in this case, I should call:

            child_indi.Update();

            once in OnBarUpdate, right?

            Comment


              #7
              Hello TazoTodua,

              Yes, I apologize if this was not clear in my last post. If an un-synced public property in a child indicator does not have Update() in that property's getter, child_indi.Update() should be used in the parent NinjaScript before accessing that property so it is up to date.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              628 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              359 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              105 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              562 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              568 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X