Distance/Drawdown from a period high/low
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Cryptauk

//@version=5
indicator("Distance from High-Low")

prev_candles = input.int(title="Period (ie candles of selected timeframe)", defval=364, minval=1)
res = input.timeframe(title="Timeframe", defval="")
src = input.source(title="Source", defval=high)
high_or_low = input.string(title="from highest/lowest ?", defval="highest", options=["highest","lowest"])


x_est = request.security(syminfo.tickerid, res, high_or_low == "highest" ? ta.highest(src, prev_candles) : ta.lowest(src, prev_candles))

plot(-(x_est-src)/x_est*100, style = plot.style_columns)
