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

Overloading Indicators

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

    Overloading Indicators

    Hi,

    I have written an indicator (MyCustomIndicator) which I wish to use in a strategy. The indicator uses four parameters. The parameters, however, are alll cosmetic: colors, fonts, etc. and are not required for the operation of the indicator. I have properly exposed the variables BullFlag and BearFlag in my indicator and I do update them manually.

    In my strategy I would like to use an expression of the form:

    if(MyCustomIndicator().BullFlag)
    { ... }

    The issue is that this statement will create an error during compilation because MyCustomIndicator does not have an overload with zero parameters.

    So I have two questions:

    1. Do I have to include ALL the parameters in the calling statement? For example,
    if(MyCustomIndicator(param1, param2, param3, param4).BullFlag). Or, can I include only one parameter? For example, if(MyCustomIndicator(param1).BullFlag). This will compile.

    2. Is there any way to overload MyCustomIndicator so that I can use it inside a trategy with zero parameters. For example as ... if(MyCustomIndicator().BullFlag)...without compilation errors?

    Please advise. Thank you very much.

    #2
    Hello Zeos6,

    The overloads available for the indicator are built from the public properties section. There are a couple reasons why you want variables in the properties region:

    1) You want variables declared publically because they are designed to be inputs. The structure for this is detailed here.

    2) You want to expose variables and the properties section is needed to link the public > private. The structure for this is detailed here.

    You should look at the variables you have in your properties region and see if they fit purpose 1 or 2 and then use the needed structure. If they don't serve purpose 1 or 2 then remove them and use only private variables.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Hi Ryan,

      Thank you for your reply. I am well aware of the points you make but your reply does not answer my question. The parameters are cosmetic because I wish to use the indicator outside a strategy as well as inside a strategy and I don't want to duplicate the indicator with no parameters solely for use in a strategy. I am looking to overload the indicator for use in a strategy. Therefore, can you please answer my questions? Thank you very much.

      Comment


        #4
        There's no way to specify the overloads except for working with the properties region. If you don't want to specify parameters for public inputs, then create a separate indicator and remove these public inputs.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Hi Ryan,

          Thank you for your response. I understand re the overload with no parameters. This answers my question 2.

          Now back to question 1. As I mentioned in my original post, my indicator has 4 parameters. In my strategy, I can reference my indicator with less than the four parameters and it will compile. The system seems to implicitly overload the indicator with less than the full complement of parameters. Do you know if this will cause any problems in the strategy; i.e. using less than the full complement of parameters? Please let me know. Thank you.

          Comment


            #6
            If it compiles then you should be fine.
            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Thank you for your response Ryan.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by rdtdale, Today, 01:02 PM
              0 responses
              2 views
              0 likes
              Last Post rdtdale
              by rdtdale
               
              Started by alifarahani, Today, 09:40 AM
              3 responses
              15 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by RookieTrader, Today, 09:37 AM
              4 responses
              18 views
              0 likes
              Last Post RookieTrader  
              Started by PaulMohn, Today, 12:36 PM
              0 responses
              7 views
              0 likes
              Last Post PaulMohn  
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              41 views
              0 likes
              Last Post love2code2trade  
              Working...
              X