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 argusthome, 03-08-2026, 10:06 AM
|
0 responses
116 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
61 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
40 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
43 views
0 likes
|
Last Post
|
||
|
Started by Mindset, 02-28-2026, 06:16 AM
|
0 responses
82 views
0 likes
|
Last Post
by Mindset
02-28-2026, 06:16 AM
|

Comment