Thank you very much in advance for any guidance you might provide.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to Make a NinjaScript Strategy Disable Itself?
Collapse
X
-
How to Make a NinjaScript Strategy Disable Itself?
I'm coding a NinjaScript strategy in NT8, and I'm looking for a way that the strategy can use to disable itself. Per the NT8 Help Guide the CloseStrategy procedure does three things, as follows: (1) it cancels all working orders, (2) it closes existing positions, and (3) it disables the strategy. I'd like my strategy to do just 1 & 3, or 3 only. Do I need to override CloseStrategy to accomplish this, or is there some other approach that I could use? If I'll need to override CloseStrategy, then what NinjaScript code fragment would I use to accomplish part 3 (that is, to disable the strategy)?
Thank you very much in advance for any guidance you might provide.Tags: None
- Likes 1
-
Hello NtFan,
Thank you for your post.
Yes, you would need to override Close Strategy to accomplish this and would not want to call the default close action at all, since that's the bit that cancels working orders and closes existing positions. You could do something like the below, replacing // custom close logic with your own logic to simply cancel the working orders. Once that's done then you can call CloseStrategy from OnBarUpdate and your custom logic will execute before the strategy disables.
public override void CloseStrategy(string signalName)
{
Print("Executing Custom Close Logic");
// custom close logic
}
Please let us know if we may be of further assistance to you.
-
Is it possible to execute a stop on the strategy based on current P/L for that strategy? For example if P/L is more than -$40 stop running
Comment
-
I understand the part where we need to override the method but do you have any hints how to disable the strategy (Part 3 of the original question)?
I don't find anything in the reference guide.
Thanks!
Comment
-
Hello davidfrechette,
Thanks for your notes.
CloseStrategy() could be used to cancel all working orders, close any existing positions, and finally disable the strategy as noted by NinjaTrader_Kate in post # 2.
See this help guide page for more information about CloseStrategy() and sample code: https://ninjatrader.com/support/help...sestrategy.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
52 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
130 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
70 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
43 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
47 views
0 likes
|
Last Post
|

Comment