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:
In my example, I set inPosition to true once I enter. In other scripts, when checking for inPosition, this variable is already true because my example strategy entered and set the variable to true. Because of this, the other strategy will not enter.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 argusthome, 03-08-2026, 10:06 AM
|
0 responses
86 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
48 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
30 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
33 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
67 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment