Help with close sell/buy orders on trend change

 

My EA makes buy or sell orders according to the trend. Orders are executed on different indicator data but it allways follows the trend. Have small TP and big SL.

The problem is that if the trend goes from an uptrend to a down trend or the other way around, there are allways orders left open that goes into SL and I loose money because of the big SL.

Cant change the SL to smaller value, because this is the way the EA works.

Is there a good way to close all open buy orders if a trend changes to the downside?

And close all open sell orders if the trend changes to the upside?

Im no master in coding but I managed to create the trend following in the EA with some help from mrtools.

Would be very greatfull if somebody could help me with the close order code Im looking for.

//Thomas