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