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

'MyCustomIndicator' is a 'namespace' but is used like a 'type' compiler error

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

    'MyCustomIndicator' is a 'namespace' but is used like a 'type' compiler error

    Hello,

    I've got an indicator, 'MyCustomIndicator' which I would like to add to a strategy.

    'MyCustomIndicator' requires 10+ overloads and one of those overloads only work if I add the following namespace:

    using MyCustomIndicator.Utility


    However, since MyCustomIndicator accepts so many overloads, I'd like to create a variable of type MyCustomIndicator as such:

    private MyCustomIndicator myVar

    When I do this I get the following compilation error: 'MyCustomIndicator' is a 'namespace' but is used like a 'type'

    Does anyone know how to resolve this issue?

    Many Thanks!

    #2
    Hello MercuryScripter,

    Are you asking about a script that has multiple parameters?

    Or are you asking how to have different sets of overloads? (Overloads are the different ways parameters can be supplied to a indicator or method)

    For example with EnterLong this has 4 overloads.
    overload 1 - EnterLong()
    overload 2 - EnterLong(string signalName)
    overload 3 - EnterLong(int quantity)
    overload 4 - EnterLong(int quantity, string signalName)

    The overloads allow to use 0 parameters, 1 parameter (either the quantity or signal name), or 2 parameters (both the quantity and signal name).


    Regarding calling your indicator and then a method or variable from your indicator, that should be possible with the code you have posted.

    Attached is an example.
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello MercuryScripter,

      Are you asking about a script that has multiple parameters?

      Or are you asking how to have different sets of overloads? (Overloads are the different ways parameters can be supplied to a indicator or method)

      For example with EnterLong this has 4 overloads.
      overload 1 - EnterLong()
      overload 2 - EnterLong(string signalName)
      overload 3 - EnterLong(int quantity)
      overload 4 - EnterLong(int quantity, string signalName)

      The overloads allow to use 0 parameters, 1 parameter (either the quantity or signal name), or 2 parameters (both the quantity and signal name).


      Regarding calling your indicator and then a method or variable from your indicator, that should be possible with the code you have posted.

      Attached is an example.
      Hello Chelsea,

      No. I am unable to declare a variable of type MyCustomIndicator because in order to add MyCustomIndicator to my strategy I must use the following namespace:

      using MyCustomIndicator.Utility.

      so after I add the using statement and try to declare

      private MyCustomIndicator myIndVar

      I get the error I mentioned on the subject of the thread.

      Comment


        #4
        Hello MercuryScripter,

        May I confirm that you have looked at the example script I have posted in post #2?

        I have set the hosted indicator to a variable just as you have described and then called a value from this.

        Is this not what you are trying to do?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello MercuryScripter,

          May I confirm that you have looked at the example script I have posted in post #2?

          I have set the hosted indicator to a variable just as you have described and then called a value from this.

          Is this not what you are trying to do?
          Hello Chelsea, please watch this 2 min video illustrating the issue. Thank you.

          Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

          Comment


            #6
            Hello MercuryScripter,

            After watching your video, it still sounds as if you want to save an indicator to a variable so that you do not have to write the parameters each time you call the indicator.

            This is exactly what I am trying to demonstrate in the example script I have given you. The script saves an instance of the HostedIndicator using a parameter to a variable. Then using the variable it prints a value from the hosted indicator.

            Can you explain with words why this example script does not demonstrate what you are looking for?

            Can you further explain what you are looking for?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks Chelsea, I guess I am having some trouble. clearly following the script you sent me. Could you clarify what I might do in my particular situation?

              Comment


                #8
                Hello MercuryScripter,

                I cannot comment on the using statement MyCustomIndicator.Utility because this is custom code written by you. I also do not understand why the utility class must be added as a using statement instead of being accessed through the indicator class.

                MyCustomIndicator.Utility.myValue..

                However, my script has two indicators a host indicator and a hosted indicator. The host indicator calls the hosted indicator and saves an instance of this with the parameters called to a variable. Then I use the variable to print a value of a property from the hosted indicator.

                I not aware of any way to further simply this script.

                However, from the HostIndicator script, is this not exactly what you are looking for?

                Can you explain how this is incorrect?

                Without further information about why this is not what you want, I am not able to provide a proper response.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea,

                  I realize that I already tried what you suggested in your script before even starting this thread. In your sample script you do the following declaration:

                  private HostedIndicator myHostedIndy;

                  I am unable to do this in my script.

                  I am also unable to access the utility class from the indicator class as you suggested:

                  MyCustomIndicator.Utility.myValue

                  Doing this gives me a compilation error. Please see this video as to what is happening.

                  Illustrated in this video
                  Free online storage and sharing with Screencast.com. 2 GB of storage and 2 GB of bandwidth per month for free. We won't compress, alter or take ownership of your content.

                  Comment


                    #10
                    Hello MercuryScripter,

                    This confirms that this is what you are trying to do and that the sample I gave is along the right lines. You are trying to access an indicator in this way and it is giving you an error.

                    Also, with the video I can see the line of code generating the error and the error message, so I can now provide you with an example.
                    Attached Files
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello Chelsea,

                      Thank you very much for the updated sample. However, this is exactly what I already tried as I demonstrated in the previous video and keep getting compiler errors. I am not sure why I am unable to access IndicatorName.Utility.SqueezeStyle.SqueezeName when passing it in this way.

                      Comment


                        #12
                        Hello MercuryScripter,

                        May I confirm that the example I have provided achieves your intended goal?

                        May I confirm that the example compiles and runs without any issue?

                        Likely the issue is that the hosted indicator classname is the same as the namespace name of where the enum is.

                        I received an error when I structured my code this was as well. So I changed the namespace of the enums as it is bad coding practice to use names in ambigious ways such as this.

                        The host indicator doesn't know if you are referring to the indicator or to the namespace because they were both named the same thing.


                        However, now that I understand what the Utility class is and how the namespaces are being used, I can understand why a using statement is used.
                        And it is fine to use a using statement, however, if the using statement was causing an error I was asking if there was a way it didn't have to be used.

                        Did you add a using statement for JPTSqueezeDiverger.Utility to the host script and then reference the enum directly?

                        Your video shows that code there, and then you change it without trying to compile it. So I have not seen an error message that would let us know if there is an issue and what the issue is when doing this.

                        I've modified my example to demonstrate using a using statement when the enum and indicator classname are the same.
                        Attached is an importable file that has two versions. One version has the namespace for the enums matching the classname of the indicator and this uses a using statement.
                        The other version, completely removes the using statements. (allow this to overwrite the older versions)

                        Please confirm that my example does demonstrate what you are trying to do and that it compiles correctly and runs correctly.

                        The better of these two, would be to use different names for the namespace for the enums and the indicator name. This ambiguous usage, I feel, is bad coding.

                        Can you provide more information such as the lines of code used and the error message you are getting from your script?
                        Attached Files
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Chelsea,

                          Thank you sincerely for your diligence on this inquiry. So I was previously doing exactly what you've provided in the example files and encountering my issue. However, you hit the nail on the head with:

                          So I changed the namespace of the enums as it is bad coding practice to use names in ambigious ways such as this.

                          The host indicator doesn't know if you are referring to the indicator or to the namespace because they were both named the same thing.
                          I did the same - changed the name of the enum namespace and voila mission accomplished!

                          Many Thanks to you! You all at NT are superb. One of the reasons I exclusively work on NT development because of the outstanding support provided by the team not found elsewhere.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by aussugardefender, Today, 01:07 AM
                          0 responses
                          3 views
                          0 likes
                          Last Post aussugardefender  
                          Started by pvincent, 06-23-2022, 12:53 PM
                          14 responses
                          238 views
                          0 likes
                          Last Post Nyman
                          by Nyman
                           
                          Started by TraderG23, 12-08-2023, 07:56 AM
                          9 responses
                          384 views
                          1 like
                          Last Post Gavini
                          by Gavini
                           
                          Started by oviejo, Today, 12:28 AM
                          0 responses
                          4 views
                          0 likes
                          Last Post oviejo
                          by oviejo
                           
                          Started by pechtri, 06-22-2023, 02:31 AM
                          10 responses
                          125 views
                          0 likes
                          Last Post Leeroy_Jenkins  
                          Working...
                          X