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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
78 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
40 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
63 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
63 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
54 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment