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 adeelshahzad, Today, 11:49 AM
|
1 response
3 views
0 likes
|
Last Post Today, 11:56 AM | ||
Started by spottysallrite, Today, 11:31 AM
|
1 response
5 views
0 likes
|
Last Post Today, 11:43 AM | ||
Started by johnMoss, 03-04-2024, 01:53 PM
|
2 responses
32 views
0 likes
|
Last Post
by Overnhou
Today, 11:21 AM
|
||
Started by Padan, Today, 02:02 AM
|
5 responses
17 views
0 likes
|
Last Post Today, 11:14 AM | ||
Started by Lele2k24, Yesterday, 11:24 AM
|
8 responses
29 views
0 likes
|
Last Post
by Lele2k24
Today, 11:00 AM
|
Comment