Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Setting Strategy Defaults
Collapse
X
-
zweistein,
I was re-visiting this issue today. I found a better way to hard code.
Basically don't put in the Description and the Category, rather just set the value of the part you want to "harden". The benefit is:
1. Less typing!
2. Categories like "Time frame" will not let you overwrite, rather 2 categories show up. It's not clean.
3. By not putting in a description or category, you still harden the value you want to preset, but it will preseve the description, etc. It's working fine for me.
Thought someone else may benefit from this.
Originally posted by zweistein View PostEverything 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
-
Zweistein,
This is almost working. I don't think we can get better than this:
If you go to strategy tab and then click add strategy, then go to your strategy that has this code, then select instrument from the list and no matter what you select it will snap back to whatever you have between the Quotes. (The key was .Contains() with a partial string, that grabbed the right id.Code:[FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000] // [XmlIgnore()] // [Description("Instrument")] // [Category("Data series")] [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][/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][FONT=Courier New][SIZE=2] Instrument Instrument { [/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]get[/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]return[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]base[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Instrument ;} [/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]set[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] { NinjaTrader.Cbi.InstrumentList il =NinjaTrader.Cbi.InstrumentList.GetObject([/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]"Default"[/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=#008000][FONT=Courier New][SIZE=2][COLOR=#008000][FONT=Courier New][SIZE=2][COLOR=#008000]// other lists also possible [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]foreach[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](Instrument i [/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]in[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] il.Instruments) { [/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]if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2](i.FullName.Contains([/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]"TF 09-09"[/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]base[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Instrument=i; Print([/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]"Startup Instrument "[/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]base[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Instrument.MasterInstrument.Name.ToString()); } } } } [/SIZE][/FONT][/SIZE][/FONT]
I don't have a debugger setup yet, but if you could get the list for "Account" that would be great. I tried hard setting the account, but it only changes the name and it screws up the database. I looked at the mdb file and their is an Id with each account (see the table in the mdb file).
So we need to loop through the accounts and then grab the account we want to use. It should work like the other property settings.
Anyway, the code worked. But it's a little flaky. I also tried running similar code in a method and then calling the method on initialize, but it clearly doesn't want to let you change the Master nstrument during the initialization method.
I hope this helps. Thanks for your startup code. With a debugger, I could get a better look under the hood. If you could provide a simple how to for how you would go about getting the methods for a class that is not typically exposed, that would be great. I could use a bump!
Originally posted by zweistein View PostSo,
just to mention: I will not contribute more, because usually I see the questions from other people, then I become curious and I want to try out and I want to help also. But fact is that when I am active in this forum I am NOT disciplined enough for trading.
In the end of the day I loose concentration on my own trades, - today I was waiting for the FGBL to break the 120, entered 2 times but always out of the trades with nothing, and now finally 10 minutes ago the expected move, offcours without me.
Please understand that I have:
My own trading first,
my own strategy development second ( my questions are more scientific as I am trying to find a clustering algoritm that reproduces my trade experience. Currently QT Clustering stuff, we will see..
my private life also
So ,
r2kTrader,
you can do the following, it should work: I used a NetObject Spy to find out and a lot of common sense:
[XmlIgnore()]
[Description("Instrument.")]
[Category("Data series")]
public Instrument Instrument {
get {returnbase.Instrument ;}
set {
NinjaTrader.Cbi.InstrumentList il =NinjaTrader.Cbi.InstrumentList.GetObject("Default"); // other lists also possible
foreach(Instrument i in il.Instruments) {
if(i.FullName=="ES 06-09") base.Instrument=i;
}
}
}
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
651 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
577 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment