Edit: Never mind! I figured it out - the method by which I was initializing my script was flawed, so that the KillSwitch bool was being reset. Fixed it by starting the script with an initialization condition of "if ((Bars.IsFirstBarOfSession == true) && (IsFirstTickOfBar == true))" instead of "if (marketPosition.MarketPosition == MarketPosition.Flat." I'd delete the post if I could figure out how.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How to prevent a strategy restarting after position exit?
Collapse
X
-
How to prevent a strategy restarting after position exit?
I'm at my wit's end. I've tried to use kill-switch booleans, and every version of the hallucinatory garbage that ChatGPT suggested. Every time an Exit Order gets hit, my strategy gleefully opens up a brand new position. Is there no way to kill the strategy from within?
Edit: Never mind! I figured it out - the method by which I was initializing my script was flawed, so that the KillSwitch bool was being reset. Fixed it by starting the script with an initialization condition of "if ((Bars.IsFirstBarOfSession == true) && (IsFirstTickOfBar == true))" instead of "if (marketPosition.MarketPosition == MarketPosition.Flat." I'd delete the post if I could figure out how.Last edited by Borogove; 01-31-2025, 08:15 AM.Tags: None
-
Hello Borogove,
That sounds like your condition to enter is remaining true so once it exits it is free to enter again. If the strategy should only place 1 trade total you could use a bool variable to stop it once it submits the order. For example:
Code:private bool doOnce = false; protected override void OnBarUpdate() { if(doOnce == false) { // do the entry order one time doOnce = true; }
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Mindset, 04-21-2026, 06:46 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
04-21-2026, 06:46 AM
|
||
|
Started by M4ndoo, 04-20-2026, 05:21 PM
|
0 responses
145 views
0 likes
|
Last Post
by M4ndoo
04-20-2026, 05:21 PM
|
||
|
Started by M4ndoo, 04-19-2026, 05:54 PM
|
0 responses
71 views
0 likes
|
Last Post
by M4ndoo
04-19-2026, 05:54 PM
|
||
|
Started by cmoran13, 04-16-2026, 01:02 PM
|
0 responses
125 views
0 likes
|
Last Post
by cmoran13
04-16-2026, 01:02 PM
|
||
|
Started by PaulMohn, 04-10-2026, 11:11 AM
|
0 responses
79 views
0 likes
|
Last Post
by PaulMohn
04-10-2026, 11:11 AM
|

Comment