In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.
study(title="HiLo Activator", overlay=true) length = input(3, minval=1) displace = input(0, minval=0) highsma = sma(high, length) lowsma = sma(low, length) swing = iff(close > highsma[displace], 1, iff(close < lowsma[displace], -1, 0)) mah = highest(high, length) mal = lowest(low, length) stop = iff(swing==1, mal, iff(swing==-1, mah, stop)) linecolor = iff(stop < low, green, red) plot(stop, style=line, linewidth=2, color=linecolor)