Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to create new classes in separate files?

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

    #16
    Andreas,

    Using your model below, how can I also keep parameters there which will show up in my dialog box upon adding the strategy to the chart or tab?

    In other words, I found that I could put my "centralized parameters" in the UserDefinedMethods under the partial class they provide, and they show up when I go to start a strategy.

    But if I put a class just below the partial class and instantiate it within my strategy as per your model below, everything works, but I can't see the parameters.

    What I want is to instantiate my class and then provide the parameters via the dialog box, but only for those parameters which are related to the class I am using.

    I will provide sample code in following posts

    Originally posted by zweistein View Post
    Instead of using the UserDefinedMethods.cs to extend the Strategy class

    I opted for having my classes having a constructor parameter "strategy s"

    I have a class for Trailing, a class for XmlHandling , etc. and these are al seperate files.

    I am happy with it.

    Hopefully NT 7 will use Net 3.5 which has a more advanced compiler and allows for extensions, etc.

    But for the time beeing NT 6.5 allows me to do what I need, but I am a discretionary trader that needs only to apply certain exit strategies.

    best regards




    Namespace NinjaTrader.Strategy {

    MyClass {
    strategy s;
    public MyClass(strategy S) {
    s=S;
    }
    }

    Comment


      #17
      Code:
      #region Using declarations
      using System;
      using System.ComponentModel;
      using System.Drawing;
      using NinjaTrader.Cbi;
      using NinjaTrader.Data;
      using NinjaTrader.Indicator;
      using NinjaTrader.Strategy;
      #endregion
      // This namespace holds all strategies and is required. Do not change it.
      namespace NinjaTrader.Strategy
      {
          /// <summary>
          /// This file holds all user defined strategy methods.
          /// </summary>
          partial class Strategy
          {
           #region Variables
               private bool this_works;
           #endregion
       
           #region Properties
              [Description("this parameter shows on all strategies?")]
              [Category("Parameters")]
              public bool This_works
              {
                  get { return this_works; }
                  set { this_works = value; }
              }
            #endregion
       
            } // strategy
       
      // I also tried putting this class inside of the partial class above
            public class MyClass 
            {
                  Strategy s;
       
             #region Variables
                  private bool doesnt_work;
             #endregion
       
            public MyClass(Strategy s)
            {
                  this.s = s;
            }
       
            public void testMethod()
            {
                  s.Print("Test");
            }
       
       #region Properties
              [Description("This property doesn't appear in my strategy dialog box?")]
              [Category("Parameters")]
              public bool Doesnt_work
              {
                  get { return doesnt_work; }
                  set { doesnt_work = value; }
              }
       #endregion
      } //MyClass
      } //namespace

      Comment


        #18
        Ralph replied to a similar question for me here: http://www.ninjatrader-support2.com/...9&postcount=15

        But I am not certain I will be able to see the properties as Parameters from the dialog box that appears when you implement a strategy.

        UPDATE: Also, I understand inheriting from a base class that inherits from Strategy can be problemsome. Particularly if I am passing a Strategy object to my class which is inheriting from the BaseClass which is inheriting from Strategy. Whew. OO is so much fun

        From what I can think out in my brain, it would seem that any parameters I want to have centralized, would need to be in a partial Strategy class so that it appears in my dialog box when I start the strategy. The problem with that is that ALL my strategies would see these parameters.

        I could reall use some help on this. Anyone? Ralph, Sefstrat, Andreas?
        Last edited by r2kTrader; 10-07-2009, 01:37 PM.

        Comment


          #19
          Originally posted by r2kTrader View Post
          ...Particularly if I am passing a Strategy object to my class which is inheriting from the BaseClass which is inheriting from Strategy...
          ... what problem do you see, could you describe with an example?

          Hi r2kTrader,

          the example you are refering to would work. If you need a common set of properties for a group of strategies, BaseStrat would be a proper location to hold them. Every instance of your strategy-group inherits from BaseStrat and exposes that property-set to the propertygrid and, of course, could use the properties' contents itself.

          Regards
          Ralph

          Comment


            #20
            Ralph,

            Regarding your first question, I don't see a problem, I was just referencing what Dierk stated as per this thread.



            1. So if I put the Properties code in the Partial Strategy class, then they will be available to all strategies, of course with the variables specific to that instance, correct? That's fine, and I tested that it works.

            2. The problem is that I have strategy specific properties that would only be applicable to some strategeis and not all. I don't want to litter my Properties dialog box with Parameters that are not even used in a given strategy.

            From what I can tell, if I want to have my parameters show up in the dialog box that appears when you go to start a strategy, I would need to include them in the strategy itself. I was trying to get around this and put those Parameters with my Class so I didn't have to litter my strategy via cut and paste every time.

            Any suggestions? Am I approaching this wrong? Can it be done? Should I create a custom Dialog box? Any help is appreciated.


            Thank you,



            Originally posted by Ralph View Post
            ... what problem do you see, could you describe with an example?

            Hi r2kTrader,

            the example you are refering to would work. If you need a common set of properties for a group of strategies, BaseStrat would be a proper location to hold them. Every instance of your strategy-group inherits from BaseStrat and exposes that property-set to the propertygrid and, of course, could use the properties' contents itself.

            Regards
            Ralph

            Comment


              #21
              class BaseStrat : Strategy
              {public Property1, public Property2, ...}

              class Application2 : BaseStrat
              {...}

              class Application1 : BaseStrat
              {...}

              I meant that BaseStrat example in particular. BaseStrat contains all property definitions you want to apply to a certain group of strategies only. You inherit the properties of BaseStrat to Application instead of copy-paste.

              Regards
              Ralph

              Comment


                #22
                Ralph,

                I got all that. (I think)

                And of course I can use intellisense to access the Properties as per your recommended solution.

                The problem is, or maybe it's not a problem, is that when you go to "start" the strategy from within a chart or on the strat tab, you can't see the properties that you want to set.

                You can only see them if you put them in a Partial Strategy class, and of course it will appear for ALL strats, not just a group of strats.

                Am I missing something? Again, it's about seeing them in the dialog box when you go to select the account you want to use, etc.

                I'm lost. You're my only hope obi wan.


                Originally posted by Ralph View Post
                class BaseStrat : Strategy
                {public Property1, public Property2, ...}

                class Application2 : BaseStrat
                {...}

                class Application1 : BaseStrat
                {...}

                I meant that BaseStrat example in particular. BaseStrat contains all property definitions you want to apply to a certain group of strategies only. You inherit the properties of BaseStrat to Application instead of copy-paste.

                Regards
                Ralph
                Last edited by r2kTrader; 10-08-2009, 08:29 AM.

                Comment


                  #23
                  What would Obi Wan recommend in this case? Did they trade or did they overcome this stage of development already?

                  I attached a test strategy, and I think it's doing what desired. Try it and let me know. At the little picture you see 2 variables under "Parameters". One is a property defined in the base class, the other one was defined in the derivated class.

                  Regards
                  Ralph
                  Attached Files

                  Comment


                    #24
                    Ralph,

                    Lol, good point. (Obi Wan)

                    Ok, I looked at what you posted, and I learned a couple of things.

                    The first was that the base class shouldn't be instantiated (not sure why, other than its sole purpose is to serve as a base class for our group of strats and as such shouldn't need to be instantiated?) and the proper way to go about that.

                    The second is that you used an actual Strategy template, whereas I was using the UserDefinedMethods file to try what you are doing.

                    In other words, I believe I used the same logic, but in the wrong place?

                    Well, I'm off to explore your code and implement it. I am excited to clean up all my test code and notes and integrate your kind contribution.

                    Please PM me when you have time as I would like to thank you personally.


                    Sincere regards,

                    Originally posted by Ralph View Post
                    What would Obi Wan recommend in this case? Did they trade or did they overcome this stage of development already?

                    I attached a test strategy, and I think it's doing what desired. Try it and let me know. At the little picture you see 2 variables under "Parameters". One is a property defined in the base class, the other one was defined in the derivated class.

                    Regards
                    Ralph

                    Comment


                      #25
                      Ralph,

                      Ok, what you provided was helpful, but it's not exactly what I am trying to do. (I had a version of this concept working fine)

                      What I am trying to do is get Parameters to show up in that dialog box, but from a Class after it is instantiated from within a strategy, where the code for said Class resides in UserDefinedMethods().

                      From what I can tell, you were able to get the parameters to appear because you ran the strategy called BaseStrat. I had that model working as well (which I believe may be the only way to do what I am trying to do and as such I will have to re-think my approach).

                      As it stands, I am trying to centralize my code in UserDefinedMethods()

                      Please review code in the following posts. I feel like I am chasing my tail in a circle

                      Comment


                        #26
                        Here is the UserDefinedMethods file:

                        Code:
                        #region Using declarations
                        using System;
                        using System.ComponentModel;
                        using System.Drawing;
                        using NinjaTrader.Cbi;
                        using NinjaTrader.Data;
                        using NinjaTrader.Indicator;
                        using NinjaTrader.Strategy;
                        #endregion
                        // This namespace holds all strategies and is required. Do not change it.
                        namespace NinjaTrader.Strategy
                        {
                            /// <summary>
                            /// This file holds all user defined strategy methods.
                            /// </summary>
                            partial class Strategy
                            {
                         
                          /// <summary>
                          ///  The parameter below appears in all Strategies
                          /// </summary>
                          #region Variables
                          private bool testAllStrats; 
                          #endregion
                          #region Properties
                          [Description("Test Properties All Strats")]
                          [Gui.Design.DisplayName("TestAllStrats")]
                          [Category("Parameters")]
                          public bool TestAllStrats
                          {
                           get { return testAllStrats; }
                           set { testAllStrats = value; }
                          }
                          #endregion
                         
                         
                         
                            }
                         
                         
                         
                         public class TestBase: Strategy
                         {
                          public Strategy s;
                         
                          #region Variables
                          private bool test; 
                          #endregion
                         
                          #region Properties
                          [Description("Test Properties?")]
                          [Gui.Design.DisplayName("Test")]
                          [Category("Parameters")]
                          public bool Test
                          {
                           get { return test; }
                           set { test = value; }
                          }
                          #endregion
                         
                         
                          public TestBase(Strategy s) : base(s)
                          {
                           this.s = s;
                         
                         
                          }
                         
                          public void testMethod()
                          {
                           s.Print("Test");
                          }
                         
                         
                         }
                         
                         public class TestStrat : TestBase
                         {
                          // constructor
                          public TestStrat(Strategy s) : base(s)
                          {
                         
                          }
                         
                          public void testMethod()
                          {
                           s.Print("Test");
                          }
                         }
                        }

                        Comment


                          #27
                          Here is the actual Strategy code.

                          Code:
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Using declarations[/SIZE][/FONT]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]//omitted to fit code[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT]
                          [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// This namespace holds all strategies and is required. Do not change it.[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]namespace[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] NinjaTrader.Strategy[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] This is the test Strategy that instantiates the TestStrat class[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][Description([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"This is the test Strategy that instantiates the TestStrat class"[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2])][/SIZE][/FONT]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]public [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]class[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TestStrategy : Strategy[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Variables[/SIZE][/FONT]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]TestStrat t;[/SIZE][/FONT]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]<summary>[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] This method is used to configure the strategy and is called once before any strategy method is called.[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]///[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][SIZE=2][COLOR=#808080]</summary>[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]t = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] TestStrat();[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#808080][FONT=Courier New][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                          [SIZE=2][FONT=Courier New]t.testMethod();[/FONT][/SIZE]
                          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#region[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Properties[/SIZE][/FONT]
                          [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]#endregion[/COLOR][/SIZE][/FONT]
                          [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]}[/SIZE][/FONT]
                          [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                          [/SIZE][/FONT]
                          When I go to run this strategy, no properties appear. which is starting to make sense to me because of the way NT handles everything. In other words, I can't get in front of the strategy itself. So I think I might need to re-think my entire approach.

                          Programming is a brain grind!

                          Comment


                            #28
                            Originally posted by r2kTrader View Post
                            The first was that the base class shouldn't be instantiated (not sure why, other than its sole purpose is to serve as a base class for our group of strats and as such shouldn't need to be instantiated?) and the proper way to go about that.

                            The second is that you used an actual Strategy template, whereas I was using the UserDefinedMethods file to try what you are doing.

                            In other words, I believe I used the same logic, but in the wrong place?
                            Thats correct, the protected constructor prevents instantiation of the base class only (whoever tries it), nothing else. Another important point: Since the base class inherits from Strategy, NT considers it as a fully qualified strategy. You can see that, because it appears in the list of selectable strategies, if you comment the constructor. I am personally prefer to avoid that.

                            Whenever you implement code in the framework provided by UserDefinedMethods (partial class), your code becomes a part of the Strategy-class implementation (variables, methods,...). I provided you with a base class implementation which serves as a NT-strategy (with your sub-class implementations). This is a fundamental difference and it is important to understand the difference.

                            Hope it clarifies things
                            Ralph

                            Comment


                              #29
                              Ralph,

                              I just came back to share my findings.

                              Wow am I learning a lot. This is really great. I truly appreciate all your help.

                              I have my classes all defined outside the brackets of the partial class secion of the UDM file. As a matter of fact, I am moving everything out of there anyway. There is no reason to put anything in there for what I am trying to do.

                              Ok, so it's funny because I was about to say I have it figured out. It came to me when on one hand I went to "edit" a strategy and I could see the strategy name, but then when I went to "run" a strategy, I saw the name of the class that was in my strategy (your StratTester or whatever). After scratching my head, I realized it picked up that class on the fly and I then connected the dots.

                              So essentially if I want to have a "group of strategies" that share a common set of parameters. Then all I need to do is setup my base class which inherits the Strategy class. Then define all my properties. Then make my strategy, and change the StrategyName : Strategy in the file to "StrategyName : MyBaseClass" and then code from there. I will then see all my parameters from my common BaseStrategy.

                              Whewee. Get me a doctor.

                              So I am thinking that I setup a BaseClass for my parameters, and then use the other model for managing my classes that I want to centralize.

                              I'm almost there. Once I wrap my head around this it should help to organize and manage everything. I'm close to cracking the case on this piece.


                              Thank you so much!

                              Comment


                                #30
                                Here are some comments to your UserDefinedMethods implementation, r2kTrader.

                                I described it already, implement the test classes in a strategy template. Think about this: You put the code of your 2 strategies into Strategy (by partial class). That's ok in general, but: class TestBase inherits from Strategy and is part of Strategy. I can't imagine what that means when executing.

                                For the reason mentioned I would keep the TestBase constructor protected.

                                Remove ":base(s)" from this statement: public TestBase(Strategy s) : base(s)
                                You should not pass data to the Strategy-constructor. This NT-baseclass is out of your control.

                                Of course I don't know your intention to pass a Strategy-instance to TestStrat: public TestStrat(Strategy s) : base(s). But just for printing you don't need to do that, because TestStrat inherits the complete Strategy-public interface already from "TestBase:Strategy".

                                Hope that helps
                                Ralph

                                PS: Haven't read your previous post yet.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                598 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                343 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                103 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                556 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                555 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X