Add resolution to reduce the noise of each bar (you still can use the original timeframe if you want too).
Can use in any timeframe (5m, 15m, 1H, 1D, 1W, ...) to see the trend.
Note: this script has a small side affect of repainting as it uses resolution. Thus, you might want to wait a little bit before entering a trade.