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

The type "NinjaTrader.Strategy...." already contains a definition for...

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

    The type "NinjaTrader.Strategy...." already contains a definition for...

    Dear all,

    I have the following error message.
    The type "NinjaTrader.Strategy...." already contains a definition for...
    I just cant figure it out.

    I create an indicator: "NicoLondonBreakout3" that is being used in the strategy "NicoLondonBreakoutTRAD2"

    I attached the 2 files + screenshot of the error messages.

    Thank you very much,

    Nicolas
    Attached Files

    #2
    Hello Nicolas,

    The main Issue that I see is the the Private and Public version of your variables are not being used in the correct context. When you declare a variable inside the Variables sections it should be Private and the variable should be an lower case letter in the front. Inside of the Properties section when you declare the Public version you will want to have the first letter capitalized and then use the private variable inside the get and set. Then when you reference it inside of OnBarUpdate() you will use the Public version of it.

    For Example:
    Code:
    #region Variables
       // Wizard generated variables
          private int myInput0 = 1; // Default setting for MyInput0
          private int myInput1 = 1; // Default setting for MyInput1
          private int myInput2 = 1; // Default setting for MyInput2
          private int myInput3 = 1; // Default setting for MyInput3
       // User defined variables (add any user defined variables below)
    #endregion
    
    protected override void OnBarUpdate()
    {
          // Use MyInput0, MyInput1, MyInput2, MyInput3
    }
    
    
    #region Properties
    [Browsable(false)]	// this line prevents the data series from being displayed in the indicator properties dialog, do not remove
    [XmlIgnore()]		// this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
    public DataSeries Plot0
    {
           get { return Values[0]; }
    }
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput0
    {
           get { return myInput0; }
           set { myInput0 = Math.Max(1, value); }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput1
    {
           get { return myInput1; }
           set { myInput1 = Math.Max(1, value); }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput2
    {
            get { return myInput2; }
            set { myInput2 = Math.Max(1, value); }
    }
    
    [Description("")]
    [GridCategory("Parameters")]
    public int MyInput3
    {
            get { return myInput3; }
            set { myInput3 = Math.Max(1, value); }
    }
    #endregion
    JCNinjaTrader Customer Service

    Comment


      #3
      JC,

      Thanks for the clarification.
      Am quite new to the language and lesson learnt. Do you have any book, website where it is possible to learn these sort of pure language issues/framework?

      I have updated the strategy and am left with another error: "overload" on the indicator. It must be linked on how I call the variables for the indicator. I have checked examples but I cant figure it out.
      Could you help me on that ?

      Thank you very much,

      Nicolas
      Attached Files

      Comment


        #4
        Originally posted by nlaporte View Post
        JC,

        Thanks for the clarification.
        Am quite new to the language and lesson learnt. Do you have any book, website where it is possible to learn these sort of pure language issues/framework?

        I have updated the strategy and am left with another error: "overload" on the indicator. It must be linked on how I call the variables for the indicator. I have checked examples but I cant figure it out.
        Could you help me on that ?

        Thank you very much,

        Nicolas
        When you call NicoLondonBreakout3(), you must specify all the parameters that were defined when you coded the indicator: no more, no less.

        Comment


          #5
          Meaning all the 9 variables defined in the indicator? not sure I am following you

          Comment


            #6
            Originally posted by nlaporte View Post
            Meaning all the 9 variables defined in the indicator? not sure I am following you
            Just the exact number of properties that you have defined using public ... get ... set ... syntax in the Properties region of the file, or anywhere else for that matter. They must all be specified.

            Comment


              #7
              Ok... am on the edge of a nervous breakdown

              I simplified the indicator code (NicoLondonBreakout3TEST1), simplied the strategy code (NicoLondonBreakoutTRAD2) and it still does work.
              What I am missing?
              Thank you very much in advance

              Nicolas
              Attached Files

              Comment


                #8
                Hello ,

                This is because the user defined input is still not being setup correctly inside of your Indicator. Please view the following thread for an example on how this is done.




                You may also see the changes in the attached file.
                Attached Files
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Hi JC,

                  Thank you for taking the time to correct the file and the "tips".
                  Learning slowly but surely I am.
                  Best

                  Nicolas

                  Comment


                    #10
                    JC,

                    Follow-up on the previous case.

                    From a code perspective, I can compile but I noticed that the indicator values are different if I apply through a strategy (wrong data) versus if applied directly on a chart (correct data):
                    - highest high and lowest low are not matching each others
                    - their starting points are different from a timing perspective
                    - the vertical bars in the indicator are squeezed at the end of the day for the chart with a strategy that uses the indicator
                    I attached the two codes (indicator and strategy) as well as a snapshoot of what I see when comparing the indicator on a stand alone versus the indicator when called within a strategy.

                    What I am doing wrong?

                    Thank you very much.

                    Nicolas
                    Attached Files

                    Comment


                      #11
                      Hello Nicolas,

                      You may want to use the Print() method to see what values that you are getting and what values that you are expecting.

                      The following thread has some references on how to debug your NinjaScript code.
                      JCNinjaTrader Customer Service

                      Comment


                        #12
                        JC,

                        Genius idea to use the "Print" function.
                        The error was in the way the indicator was reading the variable from the strategy.
                        I sorted it out by "trial and error". It would be great if you could indicate me what is the logic behind ? how the variable in a strategy are read by indicators and then used within the indicator?

                        Thank you,

                        Nicolas

                        Comment


                          #13
                          Hello Nicolas,

                          The Strategy will call the Indicator like it would on a chart, so you would have to give it all of the User Defined Variable in order for the Indicator to know what to use. Once the calculation is done you will have access to the indicator like the Open, High, Low, Close price of an Instrument.

                          Let us know if we can be of further assistance.
                          JCNinjaTrader Customer Service

                          Comment


                            #14
                            JC,

                            That's the thing I am missing.

                            In the strategy, I call the arguments in the same order than the variables in the indicator (ref earlier attachments) but then, they are not used by the indicator in the same order...

                            Do the arguments for the indicator (used in the strategy) need to be same spelling than the variables of the indicator?

                            Thank you,

                            Nicolas

                            Comment


                              #15
                              Hello Nicolas,

                              They do not as long as they are the correct variable type (int, double, bool, etc...).
                              JCNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Haiasi, Today, 06:53 PM
                              1 response
                              3 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by ScottWalsh, Today, 06:52 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by ScottW, Today, 06:09 PM
                              1 response
                              4 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by ftsc2022, 10-25-2022, 12:03 PM
                              5 responses
                              256 views
                              0 likes
                              Last Post KeyonMatthews  
                              Started by Board game geek, 10-29-2023, 12:00 PM
                              14 responses
                              244 views
                              0 likes
                              Last Post DJ888
                              by DJ888
                               
                              Working...
                              X