Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting Strategy Defaults

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

    #16
    Please include this in v7... I want to set
    Bars.Period.Value = 1; Bars.Period.Id = PeriodType.Day;
    just like I do
    CalculateOnBarClose = true; BarsRequired = 1;
    As well as Time from/to, Exclude weekend, and Session begin/end times for intraday. It gets really annoying to have to remember to change them via the menu because the NT defaults are different.

    You should also update your help to say this Bars & therefore Bars.Period object is invalid in the Initialize() and changing it in the OnBarUpdate() is overridden and lost.

    Thanks.

    Comment


      #17
      Thanks for your suggestion. We'll add it to the list o future considerations.

      Comment


        #18
        Thanks for this thread (and code to get me started KBJ), I was able to default everything I set in my strategies except the Instrument (which I dont want to default anyhow). Below is the code I am using for your reference.

        Code:
         
        protected override void Initialize()
        {
        CalculateOnBarClose = true;
        DefaultQuantity = 1;
        QuantityType = QuantityType.DefaultQuantity;
        EntriesPerDirection = 10;
        EntryHandling = EntryHandling.AllEntries;
        ExitOnClose = true;
        ExitOnCloseSeconds = 50;
        TimeInForce = Cbi.TimeInForce.Day;
        ExcludeWeekend = true;
        SessionBegin = DateTime.Parse("09:30 AM");
        SessionEnd = DateTime.Parse("04:00 PM");
        IncludeCommission = true;
        BarsRequired = 2;
        }

        Comment


          #19
          KJB,

          Thanks, this was helpful. Do you perhaps know how to set Default Account to use?

          Also, Default Instrument?

          Can these be done programatically? I want to eliminate as much room for error as possible from the launching of a strategy.

          Thanks,


          r2kTrader
          Originally posted by KBJ View Post
          Here are some of the defaults that I use in a strategy I've been working on...

          Code:
          protected override void Initialize()
          {
             CalculateOnBarClose = false;       // If 'false' then OnBarUpdate will be called for every tick; 'true' for just once per bar.
           
             DefaultQuantity = 1;               // Order size in number of contracts per trade.
           
             EntriesPerDirection = 1;           // Only 1 short and/or 1 long position at a time.
          // EntryHandling = EntryHandling.UniqueEntries; // Count EntriesPerDirection separately for each uniquely named EnterLong or EnterShort.
             EntryHandling = EntryHandling.AllEntries;    // Process all order entry methods until the maximum allowable entries set by the EntriesPerDirection property has been reached.
           
             ExitOnClose        = true;         // Cancel all orders & all open positions at end of session.
             ExitOnCloseSeconds = 1200;         // Cancel all orders & all open positions 1200 seconds (20 min) before end of session.
           
             IncludeCommission = true;          // Include commission on historical backtest.
           
             AccountSize = 2500;                // Assume we start with a small amount of money.
           
             Slippage = 2;                      // Amount of slippage in ticks during backtests.
           
             TimeInForce = Cbi.TimeInForce.Day; // Set day orders (as opposed to gtc = good till cancelled.)
           
             TraceOrders = true;                // Display order information in Output window for debugging.
           
             Print( String.Format( "Initialize for instrument {0} Period {1}({2}) Complete at {3}",
                                   Instrument.FullName, Bars.Period.Id, Bars.Period.Value, DateTime.Now.TimeOfDay ));
          }
          Please note that this is just a sample, and if you copy this, make sure you review each setting and pick values that make sense for your particular situation and strategy design.

          KBJ

          Comment


            #20
            Get Default Settings In real Time

            Is there a way to see ALL the parameters for a given strategy as it is running, or can this only be done by the print/debug features?

            I am envisioning something like the strategy tab where it shows the Instrument, Data Seris, and Custom Parameters. Where can you see the rest of the info so you can feel more secure about which parameters are actually active.

            Comment


              #21
              Setting default account and instrument are not supported. You will have to print to see all default settings as you run a strategy.
              Josh P.NinjaTrader Customer Service

              Comment


                #22
                Originally posted by NinjaTrader_Josh View Post
                Setting default account and instrument are not supported. You will have to print to see all default settings as you run a strategy.
                r2kTrader, although you cannot set the values, you can test to make sure your strategy has been passed expected values, by using code similar to what's found in my earlier posting # 10 (but check for expected values of "Instrument.Fullname" and/or "Account.Name" in OnBarUpdate and if it's not what you wanted, Print an error message, and Throw an exception.)

                Not as good as what you asked for, but perhaps better than nothing.

                Comment


                  #23
                  Default Instrument

                  I came up with a workaround to hard code the default instrument.

                  I did it using the add() under the initialize and manually selected that contract and time frame.

                  Now it doesn't care if I run a 60m, 10m, or which Instrument I select under the UI as it will only execute if BarsInProgress =1 or that which represents my add().

                  I hope this helps anyone trying to "nail" up a strategy with as little intervention as possible.

                  I can't tell you how many times I fired up the strategy with the wrong contract or timeframe, etc. It's very expensive when it doesn't go your way. Nothing stinks worse than losing because of a pilot error. I can handle losses, but not due to an oversight. That is the whole purpose of going algo to begin with!! lol.

                  NT7 is much anticipated. I hope this key issues all get resolved as they are paramount to algo trading.


                  Thanks

                  Comment


                    #24
                    It was helpful, another layer won't hurt!

                    Thank you

                    Originally posted by KBJ View Post
                    r2kTrader, although you cannot set the values, you can test to make sure your strategy has been passed expected values, by using code similar to what's found in my earlier posting # 10 (but check for expected values of "Instrument.Fullname" and/or "Account.Name" in OnBarUpdate and if it's not what you wanted, Print an error message, and Throw an exception.)

                    Not as good as what you asked for, but perhaps better than nothing.

                    Comment


                      #25
                      Default Instrument

                      If anyone can lend a hand, and in reference to my work around posted earlier using the Add() method to hard code an instrument into the strategy in combination with BarsInProgress, I am trying to code the current front month contract for the ES, TF, etc.

                      Looking for a code snippet to setup a programmatic/dynamic setting which will set the current month/year for the contract ES.

                      Example:
                      Add("ES 06-09", PeriodType.Minute, 1);

                      the above is under initialize() (of course).

                      I want to get this setup so that I can plug the month / year programatically. For me to figure this out will be pain, but I am sure someone who knows C# has this syntax in their sleep.

                      My train of thought is to parse a date method return and then build a custom string. Which is not brain surgery, but is for someone who is not a programmer.

                      Anyway, if someone could post a link to an example, that would help or provide direction.


                      Regards,

                      UPDATE:
                      Will this work?
                      Add("ES " + DateTime.Now.Month.ToString + "-" + DateTime.Now.Year.ToString, PeriodType.Minute, 1);

                      UPDATE II:
                      Or this I think, forgot the ()'s.

                      UNDER VARIABLES:

                      privatestring contractDate = "ES " + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year.ToString();

                      UNDER INITIALIZE():
                      Add(contractDate, PeriodType.Minute, 1);

                      Will this fly?

                      UPDATE III:
                      Ok, obviously it will give the current month, not the contract month (duh, lol) and it won't add the 0 leading the month if single digit, so my guess is that the above will give something like this:

                      ES 5-2009 (if month is May).

                      So now I just need to do an if statement or Case and test for which Quarter month is in. Should I do something like an enum with 4 contract months, 1 for each quarter, and then do a case test?

                      I can kludge through, but if someone can help, great!

                      Thanks,
                      Last edited by r2kTrader; 05-20-2009, 03:00 PM. Reason: Adding Sample Code

                      Comment


                        #26
                        You may or may not need to do more string manipulations then that. Print those out and see what it returns. Year most likely returns 2009 instead of 09 and you will want to cut just the part you want out.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #27
                          Josh,

                          It gets more complex. I have to take current date and see if it fits in between the last contract expiration and the current expiration. As you are aware, this is not a constant as it expires the 3rd Friday of that last month. So It gets complicated.

                          There has to be some kind of code out there for this. For now, set it to default to current month manually and use Outlook to remind me to rollover etc. Furthermore, I don't rollover on the same timeframe every month, rather I watch the volume roll from last contract to front month contract.

                          If anyone could help with this, I would appreciate it.


                          Thanks,

                          Comment


                            #28
                            As a last resort you may also want to consider bringing your requirements to a 3rd party NinjaScript Consultant here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #29
                              Originally posted by NinjaTrader_Josh View Post
                              As a last resort you may also want to consider bringing your requirements to a 3rd party NinjaScript Consultant here: http://www.ninjatrader.com/webnew/pa...injaScript.htm
                              I am just going to code the contract manually for the front month. This is subjective for my system anyway. I decide when to start trading the front month when I see the volume where it needs to be.

                              Also, I am noticing that even when you hard code the parameters like ExitOnClose etc. in the code, when you go to fire up the strategy from the strategy tab, it doesn't use those hard coded parameters to overwrite the last used settings. Seems "flaky" as it feels like sometimes they change, sometimes it doesn't. Can you provide some insight as to what my expectation should be using hard coded parameters? Particularly as it relates to firing strats from the strat tab in control?


                              Thanks,

                              Comment


                                #30
                                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.
                                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
                                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