Because your entry conditions have your exit conditions nested in them. Your code enters a trade the first time, but then exits the if flow because it doesn't get a sell signal until future bars. On the future bars, with an open position, strategy.opentrades == 1, so it doesn't go through the if log...