Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Errors When Copying the MACD Indicator in NinjaScript

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

    Getting Errors When Copying the MACD Indicator in NinjaScript

    Hello,
    I am attempting to make a copy of MACD indicator to edit and make changes in NinjaScript, but I am having some issues. I use the Save As feature to save and copy the original MACD under a new name, "MACD2", but the name is still seeing "MACD" in the list of indicators to add. The name of the second version doesn't update.

    If I change the name to "MACD2" in the (State == State.SetDefaults), I get the error code CS0117.

    What am I doing wrong? Thank you in advance for your help.
    Attached Files

    #2
    After "Save As" did you F5- compile ?
    Last edited by dj22522; 07-29-2023, 01:14 PM.

    Comment


      #3
      Yes I did and still didn't work. I think it has something to do with this warning.
      Attached Files

      Comment


        #4
        Where you changed the name to "MACD2" in the (State == State.SetDefaults) put the name back to what it was originally, MACD.

        Then change the name from MACD to MACD2 in this line of code: public class MACD2 : Indicator

        Then F5 (Compile)

        Code:
        namespace NinjaTrader.NinjaScript.Indicators
        {
        
        public class MACD2 : Indicator
        {
        private Series<double> fastEma;
        private Series<double> slowEma;
        private double constant1;
        private double constant2;
        private double constant3;
        private double constant4;
        private double constant5;
        private double constant6;
        
        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = Custom.Resource.NinjaScriptIndicatorDescriptionMAC D;
        Name = Custom.Resource.NinjaScriptIndicatorNameMACD;
        Fast = 12;
        IsSuspendedWhileInactive = true;
        Slow = 26;
        Smooth = 9;




        Last edited by dj22522; 07-30-2023, 02:50 AM.

        Comment


          #5
          I think your issue with the indicator initially not saving with your new name MACD2 is because the indicator has a lock sign on it.


          Comment out these two lines using //:

          //Description = Custom.Resource.NinjaScriptIndicatorDescriptionMAC D;
          //Name = Custom.Resource.NinjaScriptIndicatorNameMACD;



          and replace them with these:

          Description = @"MACD";
          Name = "MACD2";


          For Name = " " you can type what ever you want between the speech marks " " and that's what you'll see in your indicator list. ie "MACD2" or "MACD_2" etc..

          Code:
          ​public class MACD2 : Indicator
          {
          private Series<double> fastEma;
          private Series<double> slowEma;
          private double constant1;
          private double constant2;
          private double constant3;
          private double constant4;
          private double constant5;
          private double constant6;
          
          protected override void OnStateChange()
          {
          if (State == State.SetDefaults)
          {
          //Description = Custom.Resource.NinjaScriptIndicatorDescriptionMACD;
          //Name = Custom.Resource.NinjaScriptIndicatorNameMACD;
          Description = @"MACD";​
          Name = "MACD2";
          Last edited by dj22522; 07-30-2023, 02:57 AM.

          Comment


            #6
            That worked! Thank you! I can't believe it was that simple. I appreciate your help greatly.

            Comment


              #7
              Originally posted by trader07 View Post
              That worked! Thank you! I can't believe it was that simple. I appreciate your help greatly.
              Glad you sorted it

              BTW. I posted some additions to the MACD indicator a while back if it helps with the coding for what you might try for yourself.
              You can always re-name it ("Save As") now that you know how.

              https://forum.ninjatrader.com/forum/...10#post1193610

              Enjoy
              Last edited by dj22522; 07-29-2023, 03:06 PM.

              Comment


                #8
                Originally posted by dj22522 View Post

                Glad you sorted it

                BTW. I posted some additions to the MACD indicator a while back if it helps with the coding for what you might try for yourself.
                You can always re-name it ("Save As") now that you know how.

                https://forum.ninjatrader.com/forum/...10#post1193610

                Enjoy
                Awesome! I will check it out. Thank you again

                Comment


                  #9
                  Hello trader07,

                  Thanks for your post.

                  I am happy to hear you were able to resolve the issue with the help of dj22522.

                  Typically, if you want to create a copy of an indicator such as the MACD indicator, you could right-click in the MACD indicator's code, select 'Save as', name the copy of the script, and then run a compile to check for errors as dj22522 mentioned.

                  <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  557 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  324 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  545 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X