Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to add a new parameter to an indicator?

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

    #16
    Please open the code for MACD indicator as an example and scroll to the Properties region. Any parameters you add into this region as "public" will be required for passing into the indicator when calling it. If you have variables and such that do not need passing in, do not create a public component for that variable and just leave it as a private variable in the Variables region of the code up near the top.
    Josh P.NinjaTrader Customer Service

    Comment


      #17
      Josh,

      I see the MACD code -- it looks pretty vanilla. Is there a teaching point that I am missing?

      My question is that there are two different calling contexts.

      1) There are some parameters that are needed all the time. They are needed to compute the indicator.

      2) There are others that are needed only when the plot will be displayed, such as color. They are useless when the indicator is used programmatically, and not displayed.

      Is there a way to set things up so that instantiating the indicator for a chart will get all of the parameters, but programmatic calls do not need to pass in things that are needed only to display the indicator, not to calculate its value?

      --EV

      Comment


        #18
        rt6176,

        Sorry -- did not work for me. I tried a totally vanilla custom indicator (except my name for the indicator). I compiled and verified that the generated code picked up myInput0. I then changed MyInput0 in the Properties region to be grid category "General" and recompiled. I even added a MyInput1, also in General, so I could be sure the generated code was re-generated. Sure enough, the newly generated code uses both MyInput0 and MyInput1

        --EV

        Comment


          #19
          EV,

          Any parameter you list in the Properties region will always need to be added with your indicator call. Any parameter you do not include in that list will not. That is how you achieve what you want.
          Josh P.NinjaTrader Customer Service

          Comment


            #20
            Code generation is very fragile?

            I am keeping this in the same thread, since it is essentially more of the same.

            I have another custom indicator that has started to give trouble -- when I try to include it on a chart it crashed NT (got the message about having to restart and emailing them the log).

            OK -- so I next tried saving the indicator class code, deleting and re-creating the indicator (so there would be nothing corrupted). The vanilla code compiles fine, whether or not I remove the MyInput0 parameter.

            Replacing the body (everything between the Using declarations and the generated code, but not including either of those) is very touchy. I have had cases where the result looked good to my eye, but attempting to compile it crashes NT. I have had other cases where replacing it compiles, but the code at the bottom is not regenerated. What I have not yet been able to do is to get a recompile that also regenerates the code at the bottom.

            I'll keep experimenting -- I know it can be done, because I did the same thing with my other indicator, earlier in this thread.

            Just reporting that this process is amazingly fragile. I sure wish I knew exactly what triggers the generated code not recompiling. I have not been modifying it at all.

            --EV

            Comment


              #21
              Josh,

              OK -- thanks -- that confirms what I thought. It is not possible to get both kinds of constructors automatically (no surprise -- that would be hard, more like a DWIM request).

              Is there any problem with me adding other constructors of my own (outside of the generated code region)? I would hope that, provided I observed the correct namespace, they should be valid and usable. I only ask because of the other surprises I encounter with some of this Magic.

              --EV

              Comment


                #22
                EV,

                You should not be copying, touching, modifying anything at all ever in the automatically generated code. This section should never be touched.

                If you are trying to make a copy of the indicator to another file the only thing that should be copied is the actual trade logic. Do not copy and paste the whole thing. That will not work. In fact the recommended route of doing this is to copy each individual component separately meaning copy Variables region to Variables region Initialize() method to the other Initialize() method, copy OnBarUpdate() to OnBarUpdate(), copy Properties region to Properties region, but do not copy anything besides actual user code.
                Josh P.NinjaTrader Customer Service

                Comment


                  #23
                  Originally posted by NinjaTrader_Josh View Post
                  EV,

                  You should not be copying, touching, modifying anything at all ever in the automatically generated code. This section should never be touched.

                  If you are trying to make a copy of the indicator to another file the only thing that should be copied is the actual trade logic. Do not copy and paste the whole thing. That will not work. In fact the recommended route of doing this is to copy each individual component separately meaning copy Variables region to Variables region Initialize() method to the other Initialize() method, copy OnBarUpdate() to OnBarUpdate(), copy Properties region to Properties region, but do not copy anything besides actual user code.
                  Josh,

                  I must not have been clear. I have been very careful to not touch the generated code. What I have been doing is copy/paste everything in between the Using region and the generated code. I have not touched either one of those.

                  As to finer grained copying -- that is the next thing I am going to try.

                  The need to do that makes me think that there is more than the generated code region at the bottom that is precious and must not be touched. is that right?

                  --EV
                  Last edited by ETFVoyageur; 02-21-2014, 08:55 PM.

                  Comment


                    #24
                    Yes, you cannot be copying the public class names. Those must be maintained unique per script.
                    Josh P.NinjaTrader Customer Service

                    Comment


                      #25
                      Originally posted by NinjaTrader_Josh View Post
                      Yes, you cannot be copying the public class names. Those must be maintained unique per script.
                      That is not a problem. I am keeping my copy on Notepad, because I had already noted the duplication problem if I tried to save a copy in a test custom indicator.

                      Comment


                        #26
                        Not sure what you mean by keeping it in notepad. I am referring to the line of code that starts with "public class ______ : Indicator" where the _____ is the name of the indicator.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Well, I found one thing that causes failure to regenerate the code at the bottom.

                          I changed the description. I have tinkered around and am still not sure what about changing the description triggers problems. Sometimes I think it is length. Sometimes I think it is just changing it.

                          Josh, or anyone else -- what are the rules about the description? Surely I can edit it? Playing around indicates that I can, at least to a degree, but something there seems fragile.

                          --EV

                          Comment


                            #28
                            Originally posted by NinjaTrader_Josh View Post
                            Not sure what you mean by keeping it in notepad. I am referring to the line of code that starts with "public class ______ : Indicator" where the _____ is the name of the indicator.
                            I am careful to avoid duplicate identifiers, both in the script and (where appropriate) globally. If I fail to do that, the compiler gives an error -- nothing subtle about it. That means it cannot be related to a successful compile that fails to regenerate the code at the bottom.

                            My current candidate, as you can see from my previous posting, is the Description. I do not fully understand that one, but I do know that it can get me into trouble. I need to do some more experimenting.

                            --EV

                            Comment


                              #29
                              More on the description

                              If I have this code, then everything works fine:
                              Code:
                              [Description("Slope of the linear regression line.  This is the standard indicator with two additions:")]
                              public class RwbLinRegSlope : Indicator
                              If I have this code, then it compiles fine, but the code at the bottom does not get regenerated:
                              Code:
                              [Description("Slope of the linear regression line." + "This is the standard indicator with two additions:")]
                              public class RwbLinRegSlope : Indicator
                              Unless there is some nice logical explanation, this seems to me to be an out-and-out bug that editing the description should cause the problem.

                              (By the way, that was done with hand editing -- not cutting and pasting of anything.)

                              --EV
                              Last edited by ETFVoyageur; 12-31-2010, 03:34 PM.

                              Comment


                                #30
                                Using a + sign in the Description field serves no purpose. Please do not use it.
                                Josh P.NinjaTrader Customer Service

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                607 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                353 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                105 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                560 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                561 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X