Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting Strategy Defaults

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

    #31
    Originally posted by NinjaTrader_Josh View Post
    Anything you hard code will be shown on a NEW instance of your strategy. Anything you change it to from a UI level will persist till you start another new instance.
    Assuming I just started up NT and I have my settings hard coded.

    I am at the strategy tab. I go to start a strategy, I drop down to my strategy, I select. I see the IU change my settings. Ok, good so far. I then do nothing else except say ok, to load strategy, then I start it.

    Now, if I go to ADD ANOTHER STRATEGY, and select a NEW strategy from the drop down, will it keep my other settings persistant or draw from the hard coded settings. And if it does keep settings persistant, can I assume that my hard coded settings will override and take priority or is this not a good idea?

    Please advise. I am looking forward to NT 7 because as much as I can tell, the strategy management piece of NT 6.x is just not feasible for the real world in regards to algo trading. I will remain faithful to the cause and looking forward to 7, but this is very frustrating. It should not be this complicated I should think. <end of rant>

    Comment


      #32
      r2kTrader,

      The behavior is easiest understood if you just observe it. Please just try it. When you select a new strategy the hard coded settings will take over. Depending on which other strategy you select and if they hard coded anything or not the settings may or may not persist.

      For example, CalculateOnBarClose will not take hard coded values unless specifically hard coded to false.
      Josh P.NinjaTrader Customer Service

      Comment


        #33
        Josh,

        That is frustrating. It was through observation that I was unsure about what works and what doesn't. For example, how in the heck are we supposed to know that COBC won't take hard coded unless false? I mean is that documented anywhere?

        What takes precendence?

        What are the rules?

        Please give us a scope as I am doing all this so as to avoid accidentally setting the wrong settings prior to starting the system.

        <extremely frustrated>

        Originally posted by NinjaTrader_Josh View Post
        r2kTrader,

        The behavior is easiest understood if you just observe it. Please just try it. When you select a new strategy the hard coded settings will take over. Depending on which other strategy you select and if they hard coded anything or not the settings may or may not persist.

        For example, CalculateOnBarClose will not take hard coded values unless specifically hard coded to false.

        Comment


          #34
          Everything you define in
          Initialize() will override the settings from the UI.

          This is meant by hardcoded.
          example

          protectedoverridevoid Initialize()
          {
          CalculateOnBarClose =
          false;
          BarsRequired=100;
          ExitOnClose=false;
          }

          the rest is set by the UI, and the UI keeps the last selected value in memory and shows this.



          Oh, I am just rreading the previous post better,

          He is right and I am wrong!

          NT team, please document better

          There is a trick though:

          Define the following property in your strategy class

          [Description("Calculate on bar close")]
          [Category(
          "General")]
          publicbool CalculateOnBarClose
          {
          get { return true; }
          set { base.CalculateOnBarClose=true;}

          }

          should coerce to always true

          and the UI will reflect this also!

          same for the other Properties




          Last edited by zweistein; 05-21-2009, 12:48 PM.

          Comment


            #35
            It is very simple. New instance means hard coded. Selecting a different strategy with hard coded settings will set those as well otherwise it will use whatever was there before. CalculateOnBarClose is kind of like an exception where it will take on the prior value unless explicitly set to false.

            Also, please realize that hard setting many of these values is not officially supported.
            Josh P.NinjaTrader Customer Service

            Comment


              #36
              zweistein,

              Do I do that for all the properties I want to site? Will that force a UI override of the persist settings from last strategy loaded?

              By the way, do you know how to auto-select the account you want it to trade off of? Ideally I would like it to default to my broker, UNLESS, global sim mode is set. Any ideas welcomed.

              Thanks for the help by the way.




              Originally posted by zweistein View Post
              Everything you define in
              Initialize() will override the settings from the UI.

              This is meant by hardcoded.
              example

              protectedoverridevoid Initialize()
              {
              CalculateOnBarClose =
              false;
              BarsRequired=100;
              ExitOnClose=false;
              }

              the rest is set by the UI, and the UI keeps the last selected value in memory and shows this.



              Oh, I am just rreading the previous post better,

              He is right and I am wrong!

              NT team, please document better

              There is a trick though:

              Define the following property in your strategy class

              [Description("Calculate on bar close")]
              [Category(
              "General")]
              publicbool CalculateOnBarClose
              {
              get { return true; }
              set { base.CalculateOnBarClose=true;}

              }

              should coerce to always true

              and the UI will reflect this also!

              same for the other Properties




              Comment


                #37
                Originally posted by NinjaTrader_Josh View Post
                It is very simple. New instance means hard coded. Selecting a different strategy with hard coded settings will set those as well otherwise it will use whatever was there before. CalculateOnBarClose is kind of like an exception where it will take on the prior value unless explicitly set to false.

                Also, please realize that hard setting many of these values is not officially supported.

                So is ExitOnClose, that is not overriden by the hard coded settings. If you manually set to True, then it will auto-fill the values you have hard coded for number of seconds to exit before close on, but not the boolean itself. My spidey sense tells me that I want to use zweistein's work around. Will try now.
                Last edited by r2kTrader; 05-21-2009, 01:34 PM.

                Comment


                  #38
                  I cannot provide further support on this. Please use zweistein's suggestion.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #39
                    Josh and Zweisstein,

                    This is what I did. It seems to hard code and force the settings. Apparently the booleans need to be hard coded. Zweis, I made one change and you had publicbool without a space. I changed "General" to Order Handling so that it showed under the right area. What I like is that 1. I get the overriding behavior, and 2. you can't change it if you set it in the variables to the preferred setting.

                    here is the code. Josh, please let me know if this will work. It seems to behave correctly, I just want to make sure what I am seeing is what will occur. Please advise,


                    [Description(
                    "Calculate on bar close")]
                    [Category(
                    "Order Handling")]
                    publicbool CalculateOnBarClose
                    {
                    get { returntrue; }
                    set { base.CalculateOnBarClose=true;}
                    }

                    [Description(
                    "Exit On Close")]
                    [Category(
                    "Order Handling")]
                    publicbool ExitOnClose
                    {
                    get { returntrue; }
                    set { base.ExitOnClose=true;}
                    }

                    Comment


                      #40
                      Unfortunately I cannot provide you any guidance on this. This is unsupported and you guys will have to play with it on your own.
                      Josh P.NinjaTrader Customer Service

                      Comment


                        #41
                        r2kTrader

                        I had the exact same problems as you and for me my proposed solution works. The UI display corresponds the strategy behaviour
                        As I understand the calling sequence of a strategy is
                        1. Setters are called
                        2. Getters are called (or viceversa)
                        3. Variable section ist called
                        4. Initialize() is called
                        5. OnBarUpdate() is called

                        I am using this on my strategies (only simple exit strategies) for almost 2 weeks and I do 5 to 10 real trades a day (DAX, GBL, 6E, ES) and so far it seems to work

                        regards

                        Andreas


                        P.S. I liked the mental exercise, so here I wrote the


                        FrontContract() function:


                        static string FrontContract(string symbol)
                        {
                        string s=symbol;
                        DateTime NextExpiry=new DateTime();
                        DateTime t = DateTime.Now;
                        //DateTime t = new DateTime(2009,12,27);
                        int quarterend;
                        for(quarterend=3;quarterend<=12;quarterend+=3){
                        if (t.Month <= quarterend) break;
                        }
                        DateTime firstdayofquarter = new DateTime(t.Year,quarterend,1);
                        DateTime thirdfriday = firstdayofquarter.AddDays(14 + (DayOfWeek.Friday - firstdayofquarter.DayOfWeek));
                        if (t.CompareTo(thirdfriday) >= 0){
                        firstdayofquarter=firstdayofquarter.AddMonths(3);
                        thirdfriday = firstdayofquarter.AddDays(14 + (DayOfWeek.Friday - firstdayofquarter.DayOfWeek));
                        quarterend += 3;
                        quarterend = quarterend % 12;
                        }
                        NextExpiry = thirdfriday;
                        s += " " + quarterend.ToString("D2") + "-" + (thirdfriday.Year - 100 * (int)(thirdfriday.Year / 100)).ToString("D2");
                        return s;
                        }
                        Last edited by zweistein; 05-21-2009, 02:37 PM.

                        Comment


                          #42
                          I have this in my code, but I havn't worked on it yet. I use a Multibroker Licence, but I usually choose the account by hand

                          This is your starting point, let me know your results...
                          Be advised that in the getter/ setter functions you have VERY LIMITED access to the NinjaTrader functions, so always check for null, etc, or do what you can with standard .Net

                          I would use a debugger (CLR) to find out about the exposed functions of the Account class





                          [XmlIgnore()]
                          [Description("Account.")]
                          [Category("General")]
                          public Account Account {
                          get {returnbase.Account;}
                          set {
                          base.Account=value;
                          // Print("Andreas.Account="+base.Account.Name.ToStrin g());
                          }
                          }

                          Comment


                            #43
                            Crash

                            This causes NT to lock up when you attempt to start a strategy.

                            [Description("Entries Per Direction")]
                            [Category(
                            "Order Handling")]
                            publicint EntriesPerDirection
                            {
                            get { return EntriesPerDirection; }
                            set { base.EntriesPerDirection=1;}
                            }

                            I duplicated the problem and this was the code that caused the system to freeze (and also corrupt databases).

                            Comment


                              #44
                              This will always crash because your function EntriesPerDirection is calling itself

                              => stack overflow

                              so, before I turn off the PC

                              #Variables
                              int entriesperdirection=2;




                              publicint EntriesPerDirection
                              {
                              get { return
                              entriesperdirection; }
                              set { base.EntriesPerDirection=entriesperdirection
                              ;}
                              }


                              should work
                              Last edited by zweistein; 05-21-2009, 02:50 PM.

                              Comment


                                #45
                                Zweistein,

                                Lol, that makes sense. I was just copying the initial logic, lol. and didn't think it through, thank you so much for your help.

                                Do you know how to access all the variables? I want to lock down as much as a I can as I lost real money making a mistake with wrong market, etc. It was brutal, lol. Funny now, but it was a couple of NT licenses!


                                Thanks again!

                                Originally posted by zweistein View Post
                                This will always crash because your function EntriesPerDirection is calling itself

                                => stack overflow

                                so, before I turn off the PC

                                #Variables
                                int entriesperdirection=2;




                                publicint EntriesPerDirection
                                {
                                get { return entriesperdirection; }set { base.EntriesPerDirection=entriesperdirection;}
                                }


                                should work

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                                0 responses
                                647 views
                                0 likes
                                Last Post Geovanny Suaza  
                                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                                0 responses
                                369 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by Mindset, 02-09-2026, 11:44 AM
                                0 responses
                                108 views
                                0 likes
                                Last Post Mindset
                                by Mindset
                                 
                                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                                0 responses
                                572 views
                                1 like
                                Last Post Geovanny Suaza  
                                Started by RFrosty, 01-28-2026, 06:49 PM
                                0 responses
                                573 views
                                1 like
                                Last Post RFrosty
                                by RFrosty
                                 
                                Working...
                                X