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

Add NInjaScriptProperty where user can choose an Indicator

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

    Add NInjaScriptProperty where user can choose an Indicator

    Is it possible to have a property in a custom indicator that will show up in the properties UI and allow the user to open a dialog and choose an indicator? Much like the user can do when choosing the Input Data Series?

    I have tried something like the following.

    Code:
    [Display(Name = "Indicator 1", GroupName = "Parameters", Prompt = "Edit indicator 1...", Order = 0)]
    [PropertyEditor("NinjaTrader.Gui.Tools.InputEditor")]
    [XmlIgnore]
    public ISeries<double> InputIndicator1 { get; set; }
    I can select an indicator in the UI, but I must be missing some steps somewhere because when I debug, the series count is still zero.

    How should I initialize InputIndicator1 in this case?

    FYI: What I'm wanting to do is create a Correlation indicator that can be general purpose in nature by allowing the user to choose any two indicators through the UI. Then my correlation indicator can plot their correlation value.

    Thanks.
    Last edited by Steve L; 04-18-2019, 09:48 PM.
    Steve L
    NinjaTrader Ecosystem Vendor - Ninja Mastery

    #2
    Hello Steve L,

    Thank you for your post.

    It looks like you're probably trying to use the instance of that instance the selector gives you, but that's not going to be the same as calling an indicator. You should be able to use the name of the indicator you get from the selector in a switch statement and then call an indicator like normal.

    I've attached an example of how you could set this up.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello,
      Like SampleIndicatorInput, would be possible within strategy set a property with a "CollectionEditor" that holds indicators?
      Thanks.

      Comment


        #4
        Hello Optiondreamer,

        Thank you for your reply.

        What are you trying to achieve within your strategy with the indicators? Are you wanting something that allows the user to select the indicator from a list of options? If you give more detail it will help me give you the best answer.

        Thanks in advance; I look forward to assisting you further.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hello Kate,
          Thank you for your reply. The goal is that user can select one or more indicators, like when loaded in a chart, and will be saved in a collection to use in the strategy or indicator. All the indicators would have a common/single "Series" to allow call and get its value within strategy/indicator.

          Comment


            #6
            Hello Optiondreamer,

            Thank you for your reply.

            This would be extremely complex if you're trying to select from all the indicators on your platform. Many indicators use additional data series that the hosting script would also need to load, some cannot be used within other indicators, and so on.

            I note you've previously explored being able to add indicators through an addon, and my response here would be roughly the same as Jim's was to that inquiry.

            If you just want them to be able to choose from a list of a few indicators that are then called and used for calculations, this divergence spotter indicator from our User App Share uses an enum to choose from the various indicator options to use for its calculations:

            This is a conversion from NinjaTrader 7 of the Divergence Spotter indicator originally created by Ben Letto, November 2007, [email protected], as requested by a user. This version has optional background stripes. Update 01/24/2022: Fixed bug that kept indicator from loading on initial application to the chart (previously you had to reload NinjaScript on the chart [&#8230;]



            Please let us know if we may be of further assistance to you.

            The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.



            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hello, I am testing with this indicator "SampleIndicatorInput", but the saving/loading of templates does not work. How could the user save the data entered in a template?
              Thanks.

              Comment


                #8
                Hello cls71,

                Thanks for your notes.

                The user-defined public indicator input in the SampleIndicatorInput example script must call the XmlIgnore attribute on the property since it is a property that cannot be serialized.

                Since the XmlIgnore property is called for this property, the selected indicator value in the indicator's Properties cannot be saved to a template.

                Removing the XmlIgnore attribute from this property will cause an error to occur when trying to save a template for the indicator.

                See this help guide page for more information about the XmlIgnore attribute: https://ninjatrader.com/support/help...eattribute.htm
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks Brandon, I already knew that. That is why I asked if there is any way to save the data to a template in a standard way. Obviously it can be done, since it is what happens when a template is saved from a chart that contains indicators. Or when the configuration of a single indicator is saved to a template.
                  It would be very useful to have an example of a code such as the 'SampleIndicatorInput' indicator where the saving/loading of templates will work.​

                  Comment


                    #10
                    Hello cls71,

                    Thanks for your notes.

                    An xml file stores information as text. This file type is a specially formatted file that uses markup language tags to organize the text in storage. Values used in an application that are not text, have to be converted from the original object type to text that can be saved in the text files, and then restored from text back to the original object. This process is known as serialization.

                    NinjaTrader automatically attempts to save all variables using the ‘public’ access modifier to xml workspaces and templates. This saves the values the user has set for the inputs in the Indicator or Strategy window when restarting NinjaTrader, closing and opening workspaces, and when applying templates.

                    NinjaTrader auto-converts, to text, simple object types and some NinjaScript specific object types which are automatically serialized by NinjaTrader. Object types that do not easily convert into text strings cannot be saved in the xml file as text, causing an error.

                    The user-defined Indicator input would be an object type that does not easily convert into text strings so it cannot be saved in the xml file as text.

                    Data types that do not need serialization
                    • string
                    • bool
                    • int, double, float (or number type)
                    • enum
                    • SimpleFont
                    • Stroke

                    If the object type is in the list above, applying the XmlIgnore attribute and serializing is not required.

                    Public variables of all other data types will need the [XmlIgnore] attribute applied to prevent the variable from being included from being saved in the xml file, resulting in an error.

                    Help guide: NinjaScript > Language Reference > Common > Attributes > XmlIgnoreAttribute

                    Further, the user-defined public Indicator input seen in the SampleIndicatorInput sample cannot be serialized since it is too complex to just be a string and you cannot create new indicator instances from a string.
                    Brandon H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by fitspressoburnfat, Today, 04:25 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post fitspressoburnfat  
                    Started by Skifree, Today, 03:41 AM
                    1 response
                    4 views
                    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
                    604 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  
                    Working...
                    X