Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to prevent a strategy restarting after position exit?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

    #2
    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;
       }

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    78 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    40 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    63 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    63 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    54 views
    0 likes
    Last Post CarlTrading  
    Working...
    X