This script seems to find a trend change fairy well on the 4hr with the default settings. It is adjustable for other time frames, though it seems that 4hr seems the most profitable. Enjoy.
The long/short logic is the same as the study, though the strat plots yellow while the price is inside the MA range.
Tip: 1AseP4EbtAdoGa9jKv691XC5oiNMrLwire