Transferring control from one indicator to another

 
I've got an issue I can't really figure out. The EA I'm coding has multiple trades that open on H1 independent of a 30 period MA on D1 I'm using as a close signal. Ideally, a buy would open on the top side of it and close if it comes back to it, vice versa for sells. I don't want to discount the trades that open on the opposite side, however (since it's a breakout on H1 I'm looking for to anticipate a larger D1 trend). The idea I have is if it does open on the "bad" side, look at stochastics(20,5,1)mode main. If a sell order is open and it hits an oversold period, transfer control back to the MA trailing stop. Using stochastics gives me a decent cushion so that it doesn't transfer back to MA too soon and be stopped out by normal daily ranging, but other ideas are welcome as well. Thanks in advance!