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 burtoninlondon, Today, 12:38 AM
|
0 responses
5 views
0 likes
|
Last Post Today, 12:38 AM | ||
Started by AaronKoRn, Yesterday, 09:49 PM
|
0 responses
14 views
0 likes
|
Last Post
by AaronKoRn
Yesterday, 09:49 PM
|
||
Started by carnitron, Yesterday, 08:42 PM
|
0 responses
11 views
0 likes
|
Last Post
by carnitron
Yesterday, 08:42 PM
|
||
Started by strategist007, Yesterday, 07:51 PM
|
0 responses
13 views
0 likes
|
Last Post Yesterday, 07:51 PM | ||
Started by StockTrader88, 03-06-2021, 08:58 AM
|
44 responses
3,983 views
3 likes
|
Last Post
by jhudas88
Yesterday, 06:59 PM
|
Comment