I.e. if any of the different instances of my strategy has triggered a position for a certain instrument in a certain direction, I want to make sure that none of the other instances can enter a position for any instrument in any direction, until the existing position has been closed.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to make sure that only one position can exist
Collapse
X
-
How to make sure that only one position can exist
I use several instances of the same strategy for different instruments. How can I make sure that at any given time, only one position can exist over all instruments and directions?
I.e. if any of the different instances of my strategy has triggered a position for a certain instrument in a certain direction, I want to make sure that none of the other instances can enter a position for any instrument in any direction, until the existing position has been closed.Tags: None
-
Hello rafe0304,
Thank you for writing in.
You can utilize the UserDefinedMethods script and declare a static public boolean, for example.
Then, you'll want to check if the boolean is true or false in all of your strategies.
The UserDefinedMethods script can be accessed by clicking on Tools -> Edit NinjaScript -> Strategy.
As a simple example:
Code://User Defined Methods script partial class Strategy { static public bool inPosition = false; } // Strategy script protected override void OnBarUpdate() { if (!inPosition) { EnterLong(); inPosition = true; } }
Remember to place logic to switch that variable back to false when you're out of a position.Zachary G.NinjaTrader Customer Service
- Likes 1
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by geddyisodin, 04-25-2024, 05:20 AM
|
8 responses
58 views
0 likes
|
Last Post Yesterday, 10:45 AM | ||
Started by jxs_xrj, 01-12-2020, 09:49 AM
|
4 responses
3,285 views
1 like
|
Last Post
by jgualdronc
Today, 10:02 AM
|
||
Can someone turn this thinkscript into a ninjascript. 5PM CST OHL and Previous Day
by Option Whisperer
Started by Option Whisperer, Today, 09:55 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 09:55 AM | ||
Started by halgo_boulder, 04-20-2024, 08:44 AM
|
2 responses
22 views
0 likes
|
Last Post Today, 09:41 AM | ||
Started by mishhh, 05-25-2010, 08:54 AM
|
19 responses
6,189 views
0 likes
|
Last Post
by rene69851
Today, 09:29 AM
|
Comment