Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Coding a strategy not to run based on parameters?
Collapse
X
-
Coding a strategy not to run based on parameters?
I'm wondering if there is a way to code into the init of a strategy for it not to run when some conditions based off the parameters are not met. An example would be if you were running an optimization on a moving average cross system with parameter sub sets that intersect and you didnt want the optimizer to run iterations where the short period was higher then the long period.Tags: None
-
darckeen,
Logic is not recommended to be placed in Initialize() because Initialize() is called several times at various points as you try to start up your strategy. From our past experience it generally causes issues with people's code. If you want to mess around in there you can, but we do not support it.Josh P.NinjaTrader Customer Service
Comment
-
Josh,
Your original reply was pretty clear, but I want to ask this again b/c my optimizing has A LOT of iterations...I have 5 variables with values like 2..4; 2..32; -32..32; etc. -- it ends up being 300,000+ iterations.
The thing is there are plenty of iterations that make no sense, so in my OnBarUpdate() code I am skipping it if "VAR1 > VAR2", etc.
BUT I would really like to just skip that iteration altogether - and it seems like the Initialize step is the right place. Is there really no code I can run that simply exits that iteration. I don't want a full code exit, just that iteration.
I thought I would ask this same question again and hope to get a different answer. It will save my optimizer A LOT of iterations .. right now that 300,000+ set of iterations just crashes NT, I get the Out of Memory error [I'm hoping NT7 fixes this?!?]
Anyway, any thoughts would be greatly appreciated. I'm a fairly new NT person, and I LOVE it! Great platform; great API/development environment; it's the best I've used.
Thanks.
Comment
-
No, I want to skip all iterations when two variables overlap.
Mock Example:
VAR1: 1..10
VAR2: 1..10
I only want to bother running through the whole iteration when VAR2 > VAR1 [or put the other way, SKIP the iteration if VAR2 <= VAR1].
Originally I ran with:
VAR1: 1..5
VAR2: 6..10
and that produces some results, but then I wondered how things performed when VAR2=9 && VAR1=8 or VAR2=4 && VAR1=2 etc.
So I want to run the full range of values 1..10 for VAR1 and VAR2 but only when VAR2 > VAR1.
I am currently accomplishing this by wrapping all of my code in OnBarUpdate() with this:
if (VAR2 > VAR1)
{
// normal logic here...
}
and this works! BUT I would love to have a way to bypass every iteration when VAR2 <= VAR1 ... the optimizer is still watsing time going through all the ticks/bars and will never initiate a order.
Anyway, I hope that all made sense...is there anything I can do to speed up the optimize and skip over iterations that I know won't produce any orders? I would think I could call something in Initialize()....I assume this gets called at the beginning of every iteration with new values in the Optimizer?
Thanks for any help.
Comment
-
It's not that simple. Basically what I want to do is:
- when VAR2 = 10, run iterations over when VAR1 is 1-9
- when VAR2 = 9, run iterations over when VAR1 is 1-8
- when VAR2 = 8, run iterations over when VAR1 is 1-7
- etc.
I can set the optimizer up to run over VAR1=1..9; VAR2=1..10 -- but I believe half the iterations are pointless, i.e. VAR2=8 && VAR1=9.
I only want the iterations when VAR2 > VAR1, but it's not as easy as setting one variable based on the other because I need iterations of one variable relative to the other.
Anyone from NT have any ideas if there is a line of NinjaScript that can simply exit when VAR1 >= VAR2? I'd love to put that line in the Initialize() method. I don't want the whole optimization to be killed, just that one iterations ... "System.Exit(0)" --- will something like that work?
Comment
-
Its exactly what I said. Think about it.
In optimizer you put:
var1 10;20;1
var2 1;10;1 //the adding fraction
The iterations will be:
var1 var3
10 11
10 12
10 13
...
10 10+10=20
11 12
11 13
...
11 21
....
20 21
....
20 30
Baruch
p.s.
Put the calculation of var3 in Initialize()
Comment
-
When I first read this, I thought that might work...but I still don't think it will.
The goal is to run iterations only when VAR2 > VAR1:
- when VAR2=10, run iterations over when VAR1=1-9
- when VAR2=7, run iterations over when VAR1=1-6
- when VAR2=2, run iterations over when VAR1=1
- when VAR2=1, don't run any iteration
Trying to adapt your example to this:
var2 1;10;1
var_add 1;8;1 //the adding fraction
In code:
var1 = var2+var_add
for iteration of var2=1, this works. But for iteration of var2=7, this certainly doesn't work.
I thought about this using a "var_diff" variable...the same problem occurs.
The problem is I want to run iterations over an n*n matrix, but only half of the possibilities and not when i=j [the diagnol].
Please excuse me if I'm getting my math terms wrong ... I'm not mathematician, but this seems like a somewhat common thing: to loop over two variables for values 1-10, but you only want to run the optimizer when VAR2 > VAR1 (or whatever math function you want to apply).
Is there anything I can put in OnBarUpdate() that exits the current iteration of the optimizer...something like:
if (CurrentBar == 0 && VAR2 <= VAR1)
Optimizer.SkipToEnd();
Baruch: thanks for your thoughts and ideas...I really do wish I could setup a couple variables and then compute the 3rd as I need it, but I just don't think that is possible given what I'm trying to do. I basically want to dynamically iterate over one variable as it relates to another, but it's not linear, so I can't just apply simple addition or subtraction. Right? [maybe I'm still thinking of this incorrectlly?!?]
Comment
-
I WISH YOU WERE RIGHT...but you're not. Look below as I walk through all the iterations and the values for var1, var_add, and the calculated value of var2. All the rows which begin and end with 'xxx' are iterations I want to skip altogether. That was the intent of this post: to ask and find out how I can skip over iterations where VAR1 >= VAR2 for the variables VAR1=1-10 and VAR2=1-10.
Mapping this out below:
(since I want VAR2 > VAR1, I am going to use var_add 1;9;1)
[Optimizer Setup]
var1 1;10;1
var_add 1;9;1
[In Code]
var2 = var1 + var_add;
Case "1/1": var1=1; var2=2
Case "1/2": var1=1; var2=3
Case "1/3": var1=1; var2=4
Case "1/4": var1=1; var2=5
Case "1/5": var1=1; var2=6
Case "1/6": var1=1; var2=7
Case "1/7": var1=1; var2=8
Case "1/8": var1=1; var2=9
Case "1/9": var1=1; var2=10
Case "2/1": var1=2; var2=3
Case "2/2": var1=2; var2=4
Case "2/3": var1=2; var2=5
Case "2/4": var1=2; var2=6
Case "2/5": var1=2; var2=7
Case "2/6": var1=2; var2=8
Case "2/7": var1=2; var2=9
Case "2/8": var1=2; var2=10
xxxCase "2/9": var1=2; var2=11xxx
Case "3/1": var1=3; var2=4
Case "3/2": var1=3; var2=5
Case "3/3": var1=3; var2=6
Case "3/4": var1=3; var2=7
Case "3/5": var1=3; var2=8
Case "3/6": var1=3; var2=9
Case "3/7": var1=3; var2=10
xxxCase "3/8": var1=3; var2=11xxx
xxxCase "3/9": var1=3; var2=12xxx
Case "4/1": var1=4; var2=5
Case "4/2": var1=4; var2=6
Case "4/3": var1=4; var2=7
Case "4/4": var1=4; var2=8
Case "4/5": var1=4; var2=9
Case "4/6": var1=4; var2=10
xxxCase "4/7": var1=4; var2=11xxx
xxxCase "4/8": var1=4; var2=12xxx
xxxCase "4/9": var1=4; var2=13xxx
...
Case "8/1": var1=8; var2=9
Case "8/2": var1=8; var2=10
xxxCase "8/3": var1=8; var2=11xxx
xxxCase "8/4": var1=8; var2=12xxx
xxxCase "8/5": var1=8; var2=13xxx
xxxCase "8/6": var1=8; var2=14xxx
xxxCase "8/7": var1=8; var2=15xxx
xxxCase "8/8": var1=8; var2=16xxx
xxxCase "8/9": var1=8; var2=17xxx
Case "9/1": var1=9; var2=10
xxxCase "9/2": var1=9; var2=11xxx
xxxCase "9/3": var1=9; var2=12xxx
xxxCase "9/4": var1=9; var2=13xxx
xxxCase "9/5": var1=9; var2=14xxx
xxxCase "9/6": var1=9; var2=15xxx
xxxCase "9/7": var1=9; var2=16xxx
xxxCase "9/8": var1=9; var2=17xxx
xxxCase "9/9": var1=9; var2=18xxx
xxxCase "10/1": var1=10; var2=11xxx
xxxCase "10/2": var1=10; var2=12xxx
xxxCase "10/3": var1=10; var2=13xxx
xxxCase "10/4": var1=10; var2=14xxx
xxxCase "10/5": var1=10; var2=15xxx
xxxCase "10/6": var1=10; var2=16xxx
xxxCase "10/7": var1=10; var2=17xxx
xxxCase "10/8": var1=10; var2=18xxx
xxxCase "10/9": var1=10; var2=19xxx
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by helpwanted, Today, 03:06 AM
|
1 response
5 views
0 likes
|
Last Post Today, 03:35 AM | ||
Started by Brevo, Today, 01:45 AM
|
0 responses
7 views
0 likes
|
Last Post
by Brevo
Today, 01:45 AM
|
||
Started by aussugardefender, Today, 01:07 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 01:07 AM | ||
Started by pvincent, 06-23-2022, 12:53 PM
|
14 responses
242 views
0 likes
|
Last Post
by Nyman
Today, 12:47 AM
|
||
Started by TraderG23, 12-08-2023, 07:56 AM
|
9 responses
384 views
1 like
|
Last Post
by Gavini
Today, 12:29 AM
|
Comment