All-Time High with Percentage Drops for ETF's and Large Caps
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © str1nger
//@version=4

study(title="All-time high and percentage drops", shorttitle="ATH % Drops", overlay=true)
////////////////////////////////////////////////
//CALCULATE ALL-TIME HIGH AND PERCENTAGE DROPS//
////////////////////////////////////////////////

//Best Used for ETF's and Large Cap Stocks///

//ALL-TIME HIGH//
var highest = 0.0
var timeframe = ""
if (high >= highest )
    highest := high


minus1pct = (highest*0.99)
minus2pct = (highest*0.98)
minus3pct = (highest*0.97)
minus5pct = (highest*0.95)
minus7pct = (highest*0.93)
minus10pct = (highest*0.9)
minus20pct = (highest*0.8)

//PLOT ALL-TIME HIGH//
alltimehigh = input(title="Show Alltime High?", type=input.bool, defval=true)
ath = alltimehigh ? highest : na
plot(ath, show_last=1)


//PLOT PERCENTAGE DROPS//
percentdrops = input(title="Show percentage drops?", type=input.bool, defval=true)
pctdrops1 = percentdrops ? minus1pct : na
pctdrops2 = percentdrops ? minus2pct : na
pctdrops3 = percentdrops ? minus3pct : na
pctdrops5 = percentdrops ? minus5pct : na
pctdrops7 = percentdrops ? minus7pct : na
pctdrops10 = percentdrops ? minus10pct : na
pctdrops20 = percentdrops ? minus20pct : na

plot(pctdrops1, title="1% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops2, title="2% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops3, title="3% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops5, title="5% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops7, title="7% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops10, title="10% drop", color=color.white, style=plot.style_line, show_last=1)
plot(pctdrops20, title="20% drop", color=color.white, style=plot.style_line, show_last=1)


//PRE-MADE ALERTS//
alertcondition(condition=crossover(high,highest), title="New ATH", message="There is a new All-time high")
alertcondition(condition=crossunder(low,pctdrops1), title="1% Drop!", message="Price has dropped 1% from ATH")
alertcondition(condition=crossunder(low,pctdrops2), title="2% Drop!", message="Price has dropped 2% from ATH")
alertcondition(condition=crossunder(low,pctdrops3), title="3% Drop!", message="Price has dropped 3% from ATH")
alertcondition(condition=crossunder(low,pctdrops5), title="5% Drop!", message="Price has dropped 5% from ATH")
alertcondition(condition=crossunder(low,pctdrops7), title="7% Drop!", message="Price has dropped 7% from ATH")
alertcondition(condition=crossunder(low,pctdrops10), title="10% Drop!", message="Price has dropped 10% from ATH")
alertcondition(condition=crossunder(low,pctdrops20), title="20% Drop!", message="Price has dropped 20% from ATH")


