On your chart once the market started moving sideways, you should know to either think about exiting the trade or not getting into the trade.
There is no perfect way to trade without losses.
Let's assume you took the breakout:
1) Trend is strong, and market keeps going up.
2) Trend is over, and market moves down or sideways.
If your win % is over 60%, then risking even money on the trade over time, you don't need to change anything. If you win rate is lower, then you need to increase your reward for the risk that you are taking.
Also, the most important part is to identify what trade setups are you taking. Are you buying break outs, or doing something else. Determine what setups you want to take. Determine how many there are. Have patience to wait for the setup that you are wanting to take. Keep a log of your trades. For example win or loss, reason for getting into the trade, summary of the outcome. Was there anything you would change, and how would you improve on your trades going forward.
Yesterday, I was chasing trades, and ended up with a small loss which was smaller since on last trade I went for a bigger target.
Today, I recognized a trade setup I could take with a good risk vs reward in that I could place my stop where the market would tell me if I was wrong, and it was not too far away from my entry price to make me feel bad if I took a loss on the trade. This was the 2nd trade on CL. It was a short that hit target. I had buy on ES going on at the same time. My ES trade went against me 2 ticks and also I got in 1 tick too soon. I decided to set the target of this trade to BE and move my stop up 1 tick so that I would either make a small profit for the day, or if ES hit BE, I would be able to get out with a normal profit for the day and also make up all my losses from yesterday. ES hit BE, so I am happy. I also happy that I stopped trading yesterday since CL went sideways near the close and I would have been stopped out multiple times if I kept trying to catch a trend. The lesson here is you don't want to over trade especially on a day where you are taking some losses. Instead at end of day, determine what you were doing wrong and fix it for the next day like I did.. If you are digging your account into a hole as they say stop digging. Hope that helps.