protected override void Initialize()
{
AccountSize = 10000;
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Is it possible to limit total position size for all strategies?
Collapse
X
-
Is it possible to limit total position size for all strategies?
I see the help for AccountSize:
I'm wondering if I have a strategy running on 2 different instruments, can I configure it so that it will only buy 1 contract at a time for all strategies? For example, if I have $10k account and I'm trying futures, I will only be able to buy 1 contract at a time. I'm not sure how to configure this.Code:Tags: None
-
Hi cunparis,
Accessing your brokerage account values is not supported in the current 6.5 release, however we will add it in our upcoming NinjaTrader 7 release.
Also - it is not possible to push the current strategy position over to another strategy, therefore both cannot 'talk' to each other...
If you only want to trade for example one contract per signal, you could explicitly code this in with -
Code:EnterLong(1)
-
Bertrand,
I guess this is another feature request for NT7... but something like GetStrategies(), which returns a set of all currently (started) strategies would be very helpful.
We should then be able to cast the objects in the strategy to the native class type, and then make calls back and forth.
Comment
-
The problem is once a strategy enters a long position, I don't want the other strategies to enter any positions. My account size won't allow it. I can't figure out how to do this.Originally posted by NinjaTrader_Bertrand View PostHi cunparis,
Accessing your brokerage account values is not supported in the current 6.5 release, however we will add it in our upcoming NinjaTrader 7 release.
Also - it is not possible to push the current strategy position over to another strategy, therefore both cannot 'talk' to each other...
If you only want to trade for example one contract per signal, you could explicitly code this in with -
Code:EnterLong(1)
The solution of just trading one strategy doesn't work for me because I don't get many trades so I like to trade ES & NQ so that I get more trades.
Comment
-
Hi cunparis,
Then I would suggest coding it into a MultiInstrument strategy, so you have one strategy and have the option to add 2 different entry signals and go from there...
Please see this link - http://www.ninjatrader-support.com/H...struments.html
Comment
-
This would make it really complicated because each strategy has its own conf, and each strategy runs on several timeframes. So making it into one big strategy would make it hard to backtest.Originally posted by NinjaTrader_Bertrand View PostHi cunparis,
Then I would suggest coding it into a MultiInstrument strategy, so you have one strategy and have the option to add 2 different entry signals and go from there...
Please see this link - http://www.ninjatrader-support.com/H...struments.html
All that is really 1 strategy that I run multi-instrument. I have another strategy that I'm working on, so as you can see once one has several different strategies that are each multi-instrument and multi-timeframe it'd be really complicated to combine them all into one big strategy.
Heech - I thought of this, but there could be race conditions if two strategies tried to go long at the same time. Worst case I'd end up with 2 contracts OR the broker would refuse the 2nd order due to insufficient margin. This seems more elegant than the monolithic strategy suggestion. I will look into this. I suppose the real way to do it would be using a database and transactions. That's way beyond my C# knowledge.
Comment
-
That's fine, you do quite a lot as it is.Originally posted by NinjaTrader_Josh View Postcunparis,
We cannot offer you any other solutions at this point in time. Sometimes you just have to buck down and code it out if that is the behavior you want.
Maybe with NT 7 being able to get the account balance that would solve the problem. Hopefully.
I think I'll code heech's idea of writing to a file. Seems simple enough.
Comment
-
Yep, as I mentioned in a different thread, I just had an epiphany and decided that's the behavior I need.Originally posted by cunparis View PostI suppose the real way to do it would be using a database and transactions. That's way beyond my C# knowledge.
FWIW, working with a simple database like MySQL is pretty trivial. And if nothing else, engineers who can code up a simple+reliable query/insert system for you should be a dime a dozen. I'll probably code it myself, but if you want help with something like this, look into something like rentacoder... many C# programmers in the developing world who'll work for cheap. ($100-$250 for what you want?)
Comment
-
I'm a Java developer but so far I've been able to figure everything out in C# all by myself. Well myself and google.Originally posted by heech View PostYep, as I mentioned in a different thread, I just had an epiphany and decided that's the behavior I need.
FWIW, working with a simple database like MySQL is pretty trivial. And if nothing else, engineers who can code up a simple+reliable query/insert system for you should be a dime a dozen. I'll probably code it myself, but if you want help with something like this, look into something like rentacoder... many C# programmers in the developing world who'll work for cheap. ($100-$250 for what you want?)
So hitting MySQL in Java or PHP is quite easy, but C# I'd have to learn the APIs. The equivalent of JDBC for Java. I'll look into and if it's not much more effort than writing to a file then I can try that. I think it'd be cleaner than a file, and it'd be transactional.
Thanks for sharing your ideas. You seem to be a bit further along than I am. I'm going to look for your other threads.
Comment
-
As it happens, I'm a Java guy too.Originally posted by cunparis View PostI'm a Java developer but so far I've been able to figure everything out in C# all by myself. Well myself and google.
So hitting MySQL in Java or PHP is quite easy, but C# I'd have to learn the APIs. The equivalent of JDBC for Java. I'll look into and if it's not much more effort than writing to a file then I can try that. I think it'd be cleaner than a file, and it'd be transactional.
Thanks for sharing your ideas. You seem to be a bit further along than I am. I'm going to look for your other threads.
My experience with C# is limited to this + another trading platform, about 2 months worth. The learning curve hasn't been bad, Microsoft did a good job.
I'm actually not that comfortable in raw JDBC, having always used a framework (Hibernate) in my past professional life. I'm thinking about using a framework in C# too... let's trade notes, if you find anything useful.
Comment
-
Exactly, this is what I do with all my strategies now so they can talk to each other.Originally posted by heech View PostAnother possibility.. use C# to read/write a file on the local hard-drive. Look into C# file handling examples (widely available online... just google). Your two strategies can coordinate that way.
Not perfect code but quick example:
string dailylimitlogfile = @"c:\windows\temp\ninja\dailylimit (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";
string longpositionlogfile = @"c:\windows\temp\ninja\position_es_long (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";
string shortpositionlogfile = @"c:\windows\temp\ninja\position_es_short (" + Time[0].Month + "-" + Time[0].Day + "-" + Time[0].Year + ").txt";
-------------------------
// create file to indicate daily limit reached
TextWriter dailylimitlog = new StreamWriter(dailylimitlogfile);
dailylimitlog.WriteLine(DateTime.Now + " - Daily limit reached");
dailylimitlog.Close();
--------------------------
// when flat
// delete position file
if (File.Exists(longpositionlogfile)) File.Delete(longpositionlogfile);
---------------------------
// when about to enter new position
if (File.Exists(shortpositionlogfile)) { Print (logprefix + "In a short position it seems, doing nothing."); return; }
if (File.Exists(dailylimitlogfile)) { Print (logprefix + "Daily limit reached on another strategy it seems, doing nothing."); return; }
---------------------------
// when entered position
// create file to indicate in long position for es
TextWriter position = new StreamWriter(longpositionlogfile);
position.WriteLine(DateTime.Now + " - In long position");
position.Close();
Comment
-
Thank you for posting your code. I was thinking last night while in the shower: Can't I just use a static variable to hold this information? Do I really need to use files? I can make a class full of static members to hold the information that needs to be shared. Since it's static, it's available to all the strategies.Originally posted by ctrlbrk View PostExactly, this is what I do with all my strategies now so they can talk to each other.
Not perfect code but quick example:
The question is each strategy run in the same "JVM" (not sure what the C# equivalent is), or is each one totally separate (with its own copy of the static variables)? If they're separate then the file approach is the next choice.
heech - I love Hibernate and the ORM idea in general. But in this case if I only had 1 table I'd just use JDBC to keep it simple. I imagine .NET has something similar to JDBC for simplicity.
I have to do a test for the static idea and if it doesn't work then my next goal is the file and eventually database.
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
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment