Price Levels
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tomorme88

//@version=5
indicator('Price Levels', overlay=true)

g = bar_index == 1
ath() =>
    a = 0.0
    a := g ? high : high > a[1] ? high : a[1]
    a

a = request.security(syminfo.tickerid, 'M', ath(), lookahead=barmerge.lookahead_on)
plot(a, title='ATH', linewidth=2, trackprice=true, color=color.new(color.maroon, 0), offset=-9999)

atl() =>
    r = 0.0
    r := g ? low : low < r[1] ? low : r[1]
    r

r = request.security(syminfo.tickerid, 'M', atl(), lookahead=barmerge.lookahead_on)
plot(r, title='ATL', linewidth=2, trackprice=true, color=color.new(color.maroon, 0), offset=-9999)
plot((a-r)*0.5,title='50%',linewidth=2, trackprice=true, color=color.maroon, offset=-9999)
plot((a-r)*0.166,title='16.6%%',linewidth=2, trackprice=true, color=color.maroon, offset=-9999)
plot((a-r)*0.382,title='38.2%%',linewidth=2, trackprice=true, color=color.maroon, offset=-9999)
plot((a-r)*0.618,title='61.8%',linewidth=2, trackprice=true, color=color.maroon, offset=-9999)
plot((a-r)*0.786,title='78.6%',linewidth=2, trackprice=true, color=color.maroon, offset=-9999)

 

