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

Read/write variable set in an AddOn from a Drawing tool

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

    Read/write variable set in an AddOn from a Drawing tool

    Hi,

    I would like to be able to read from a drawing tool the values of a list that is created from an AddOn.

    I have tried many different ways to achieve that without success. I spent enough time that I felt I now have to ask here.

    In the AddOn, a list is created and values added by the OnStateChange().

    From the Drawing tool, I would like to read the values set by the AddOn in the list in the OnStateChange(). I would also like to be able to modify the list from the Drawing tool such the AddOn will see the updated values for the list. The list defined in the AddOn is also used in other methods in that AddOn under the same class (MyCustomAddOn).

    I have attached 2 very basic sample files to show what I want to achieve.

    It might be my lack of knowledge of c# or OOP so if there is some good documentation that explains this concept I would greatly appreciate getting this reference.

    Note: The timing of the read / write is not critical for the functionality I need.
    Attached Files

    #2
    Hello PriceSurfer,

    What you are asking to do would be easiest to do by using C# Static. That is because there is no connection between an addon and drawing objects. Drawing objects are part of a chart and the chart does not create addons. For the drawing objects to know about the addon instance they would need some object to find the addon however the chart has no object for them to interact with addons. It would be possible to find chart windows using the addon and then drill down into each charts properties to find the drawing objects collection and assign a variable to each for the addon instance but that would require much more code.

    I would suggest to pause here and first research the C# topic static to get a better understanding of how that concept works. Static generally should not be used in NinjaScript because NinjaScript uses instances of objects, in certain cases static can be useful like sharing a read/write property between unrelated types.

    https://docs.microsoft.com/en-us/dot...eywords/static
    https://docs.microsoft.com/en-us/dot...-class-members

    For what you are asking to do you could make a static public variable in the addon class or a separate static class with static methods/variables.

    Your addon would be able to interact with either its own static properties or the static classes properties, the other scripts can also interact with that static variable or class at a static level. That involves no instance and instead uses the classes type as a means to access the static methods/variables within that class.



    Last edited by NinjaTrader_Jesse; 05-20-2022, 07:46 AM.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Thank you Jesse,

      I managed to get it working with static methods but I was looking for a more convenient way.

      Thank you for your support and for the links.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Skifree, Today, 03:41 AM
      1 response
      1 view
      0 likes
      Last Post Skifree
      by Skifree
       
      Started by usazencort, Today, 01:16 AM
      0 responses
      1 view
      0 likes
      Last Post usazencort  
      Started by kaywai, 09-01-2023, 08:44 PM
      5 responses
      603 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by xiinteractive, 04-09-2024, 08:08 AM
      6 responses
      23 views
      0 likes
      Last Post xiinteractive  
      Started by Pattontje, Yesterday, 02:10 PM
      2 responses
      22 views
      0 likes
      Last Post Pattontje  
      Working...
      X