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

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
    JimNinjaTrader Customer Service

    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.
          JimNinjaTrader Customer Service

          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.
              JimNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              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
              7 views
              0 likes
              Last Post maybeimnotrader  
              Started by quantismo, Today, 05:13 PM
              0 responses
              7 views
              0 likes
              Last Post quantismo  
              Started by AttiM, 02-14-2024, 05:20 PM
              8 responses
              168 views
              0 likes
              Last Post jeronymite  
              Started by cre8able, Today, 04:22 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X