closing an opened order

 

Hello,

i am working on a code based on ema and stochastics indicators, it has take profit and stop loss already,

but i want the ea to close an existing order that has not gotten to take profit or stop loss, using only the stochastics signal.

i want it to close a buy order if (stocha1 is lower than(<) than stocha2)

and it should close a sell order if (stocha1 is greater than(>) stocha2).

please how can i write this instruction?.

any help will be highly appreciated.