Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Setting Strategy Defaults
Collapse
X
-
Here are some of the defaults that I use in a strategy I've been working on...
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.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 )); }
KBJLast edited by KBJ; 10-25-2007, 11:10 AM.
Comment
-
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
-
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...
At least this way you get a reminder to set things right and it doesn't run a zillion optimizations with the wrong settings.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. }
Comment
-
This was sent to me as a PM. I'm posting it over here for everyone's benefit...
Sorry, I'm not running 6.5 yet, so I have not tried this on 6.5.Originally posted by zoltranHi KBJ
In your post for setting defaults, you have this following code ...
Can you tell me what the {1} etc are doing here?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 ));
Also ..
Have you tried this verbatim on 6.5?
If i include this in Initialize.. the strategy doesn't execute ..
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.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment