Thank you very much in advance for any guidance you might provide.
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.Kate W.NinjaTrader Customer Service
-
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.htmBrandon H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by nicthe, 08-23-2023, 07:53 AM
|
7 responses
195 views
0 likes
|
Last Post
by nicthe
Today, 09:26 AM
|
||
Started by nicthe, Today, 09:24 AM
|
0 responses
5 views
0 likes
|
Last Post
by nicthe
Today, 09:24 AM
|
||
Started by stalt, 12-28-2015, 01:36 PM
|
6 responses
1,536 views
0 likes
|
Last Post
by giulyko00
Today, 09:16 AM
|
||
Started by Tburg1073, Today, 08:36 AM
|
0 responses
6 views
0 likes
|
Last Post
by Tburg1073
Today, 08:36 AM
|
||
Started by alexstox, 10-16-2018, 03:29 PM
|
10 responses
334 views
0 likes
|
Last Post
by Tburg1073
Today, 08:32 AM
|
Comment