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

Making a copy of an indicator

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

    Making a copy of an indicator

    Hi,

    I'm trying to make a copy of an indicator I have. Usually there is no issue.

    I did not create the indicator that is giving me some issues when making a copy. The message I'm getting is :-

    The namespace '<global namespace>' already contains a definition for 'xxxxxxxxxxx'.

    What does this mean and how do I resolve it so that I can make a copy that I can work on.

    Regards

    Kay Wai

    #2
    Which indicator are you trying to copy?

    What procedure did you try that failed?

    Are you trying to do this 'by hand'?

    For example,
    Did you do a file copy from '@EMA.cs' to 'MyEMA.cs'?

    Just copying an indicator to a new file is not enough.
    You have to edit the copy and also change the class name.

    Other indicators can be a bit more complicated.

    -=o=-

    Is there one universal standard way that handles all cases?

    Try using the NinjaScript Editor.
    Use the NinjaScript Explorer & double-click the indicator you wish to copy.
    For example: double-click EMA
    The indicator should appear in the editor window.
    Right-click in the editor window and select 'SaveAs'.
    For example: type myEMA
    Last edited by bltdavid; 04-30-2022, 09:30 AM.

    Comment


      #3
      Originally posted by kaywai View Post
      The namespace '<global namespace>' already contains a definition for 'xxxxxxxxxxx'.

      What does this mean and how do I resolve it so that I can make a copy that I can work on.
      Resolve it by deleting the copy you created and starting over.

      If the 'Right-Click/SaveAs' doesn't work, let us know.

      Just my 2˘.


      Comment


        #4
        Originally posted by kaywai View Post
        Hi,

        I'm trying to make a copy of an indicator I have. Usually there is no issue.

        I did not create the indicator that is giving me some issues when making a copy. The message I'm getting is :-

        The namespace '<global namespace>' already contains a definition for 'xxxxxxxxxxx'.

        What does this mean and how do I resolve it so that I can make a copy that I can work on.

        Regards

        Kay Wai
        Most likely you have the same class name 'xxxxxxxxxxx' for both the original and the copy, that is why the copy will not compile. Open the original indicator inside editor < Copy< at the Class rename the copy differently < then compile the new copy.

        Comment


          #5
          Hi All,

          bltdavid I opened it from NinjaScript editor and right clicked "Save As" and gave the file a new name. Then I compiled the copy, which gave rise to the error.

          @ alligator there were about 7 different namespaces. Manually change all of them before I compile it? As they occur quite a few time thru the code, I should change all of them, ya?

          Regards

          Kay Wai

          Comment


            #6
            You forgot most important detail -- which indicator?

            Comment


              #7
              bltdavid it isn't a system indicator but one which was coded by someone i collaborated with

              Comment


                #8
                Hmm, well, having 7 different namespaces, sounds like this is a rather
                complicated indicator.

                I would guess those 7 namespaces are defining a bunch of different
                classes, et al, and that when you create your copy, those classes are
                being defined again, which explains the compiler error you are seeing.

                IMHO, all those class definitions in all those namespaces should have
                been put into a single, separately named file. Why? Because for cases
                like this, where you'd like to make a copy, you are experiencing an
                unnecessary and excessive hindrance -- all because your programmer
                located those classes inside the same file.

                Beg pardon ... but ...
                It sounds like you are not a programmer, and may not understand the
                C# semantics your 'copy' is bumping up against. The issue you are
                seeing is a C# problem, and has nothing to do with NinjaScript. The
                problem is, from the point of view of making a copy, the code is
                organized poorly.

                If those 7 namespaces were in a separate file, you probably wouldn't
                be having this problem. Extra classes defined in extra namespaces
                should be located in extra files.

                Ok, but as to the here and now, what can you do?

                The 7 different namespaces are probably not the problem, per se.

                Realize it is the various things (perhaps the many various things) defined
                inside those 7 namespaces that are seen as duplicates -- and that is the
                problem.

                Try renaming the namespaces, but nothing else, which should be very
                easy. Leave your 'using' clauses set to use the original name.

                The new namespace name moves the definitions to a new 'place', which
                effectively prevents the compiler from seeing them as duplicates, which
                resolves the error. (Two classes defined as the same name in different
                namespaces does not raise the duplicate error -- two classes of the same
                name defined in the same namespace in two different files is an error.)

                Do not make changes to the rest of the code. This simple 'rename the
                namespace' change means all the original code in your copy continues
                to refer to the original definitions in the original namespaces in the original
                file.

                Make sense?

                Last edited by bltdavid; 04-30-2022, 09:17 PM.

                Comment


                  #9
                  bltdavid Yes it does. Thanks very much for that.

                  I'm moving the script to a different PC where I can modify it without fear of corrupting the correct script. And when completed I can move it to the original.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by trilliantrader, 04-18-2024, 08:16 AM
                  4 responses
                  16 views
                  0 likes
                  Last Post trilliantrader  
                  Started by mgco4you, Today, 09:46 PM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by wzgy0920, Today, 09:53 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post wzgy0920  
                  Started by Rapine Heihei, Today, 08:19 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by Rapine Heihei, Today, 08:25 PM
                  0 responses
                  8 views
                  0 likes
                  Last Post Rapine Heihei  
                  Working...
                  X