I've based the script on my MACDs/r indicator.
I think it works better on higher timeframes, this is just an experiment, please feel free to modify it.
I have been testing it with parabolic SARS to know when to exit the trades.
Exit condition: if I'm in a log position and the price is below the last bearish parabolic SARS dot I exit the trade and the opposite for shorts
DISCLAIMER: Is just an experiment and I haven't test it with real money, be careful