You are right absolutely right about it...!
One solution might be that above "X" number of accumulated Buy or Sell trades (after which they might become "toxic") the EA switches into "safe mode".
In "safe mode" the EA would use ALL new profits to offset (close) "toxic" trades.
In other word: when closed new profits = or > largest floating loss trade, the EA closes that toxic trade and counts the number of accumulated Buy/Sell trades again. If still above "X", then it continues in "safe mode" until all toxic trades are eliminated, then resumes "normal" profit-making mode.