Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Setting Strategy Defaults

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

    Setting Strategy Defaults

    When loading a strategy, you must enter the insturment type, value, start date, session begin/end, etc. every time. Is it possible to enter defaults for all of this in the code?

    #2
    Yes, for some of these. However you would need to find out by yourself on which ones it works. Please consult the docs for the accurate C# property names.

    Comment


      #3
      Thank you. I checked the documentation before I posted my question. I searched for "strategy properties" and some of the property descriptions but I found nothing. Perhaps you could point me in the right direction????

      Comment


        #4
        In the Help Guide.

        NinjaScript > NinjaScript Language Reference > Custom Strategy Methods and Properties
        RayNinjaTrader Customer Service

        Comment


          #5
          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
          Last edited by KBJ; 10-25-2007, 11:10 AM.

          Comment


            #6
            Thank you KBJ - I appreciate the code.

            Ray, I did check that first. I was hoping I could set all of the values like the chart interval,first date, session begin and end time, etc. I still don't see these so I will assume that it can't be done. Thx

            Comment


              #7
              If you use the code KBJ provided you should be able to set the default for that particular strategy to whatever you want. Unfortunately there is no way to set these options on a universal basis.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                I tried setting these values programatically in my Initialize method. When I check them in OnBarUpdate, they have reverted back to the values specified in the UI. Is there another step to be taken to make sure this doesn't happen? I am seeing this behavior on both backtesting & optimization.

                Comment


                  #9
                  >> Is there another step to be taken to make sure this doesn't happen?
                  Unfortunately this is not supported.

                  Comment


                    #10
                    I forgot. I wasn't able to set the EntryHandling and EntriesPerDirection.

                    However, I added some code to the OnBarUpdate method to make sure the values were set correctly...

                    Code:
                    if ((EntryHandling != EntryHandling.AllEntries)    // Correct setting?
                      || (EntriesPerDirection != 1))
                    {                                                  // No. Cause an error to abort this run.
                        Print( "**** Error - Entry handling is not set to AllEntries 1" );  // To output window.
                        throw new System.ApplicationException("EntryHandling must be AllEntries, 1"); // To log.
                    }
                    At least this way you get a reminder to set things right and it doesn't run a zillion optimizations with the wrong settings.

                    Comment


                      #11
                      That is very good if we can set the default also for:
                      Time frame: Form=2007/07/01,
                      Time Frame: To=Today,
                      Keep best result=2,
                      Optimize on=max. net profit.

                      Thanks

                      Comment


                        #12
                        Thanks for your suggestion. We'll add it to the list.

                        Comment


                          #13
                          Will next version include?
                          Good luck.
                          Thanks

                          Comment


                            #14
                            Unfortunately not.
                            RayNinjaTrader Customer Service

                            Comment


                              #15
                              This was sent to me as a PM. I'm posting it over here for everyone's benefit...

                              Originally posted by zoltran
                              Hi KBJ

                              In your post for setting defaults, you have this following code ...

                              Code:
                                   Print( String.Format( "Initialize for instrument {0} Period {1}({2}) Complete at {3}",
                                                         Instrument.FullName, Bars.Period.Id, Bars.Period.Value, DateTime.Now.TimeOfDay ));
                              Can you tell me what the {1} etc are doing here?

                              Also ..
                              Have you tried this verbatim on 6.5?
                              If i include this in Initialize.. the strategy doesn't execute ..
                              Sorry, I'm not running 6.5 yet, so I have not tried this on 6.5.

                              Check this page for how String.Format works: http://www.blackwasp.co.uk/StringFormat.aspx

                              To debug this, I'd suggest deleting each "{n}" designation in turn along with the matching parameter until the problem goes away.
                              Last edited by KBJ; 04-08-2008, 12:01 PM. Reason: Fixed illiterate looking typo

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              648 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
                              574 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X