Dip Buyer
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jumpr
// This was created for a friend and only has SPY in mind.
// This indicator gives signals based on the previous All-Time High
// Default values are Watch Signal: 4% from ATH, Buy Signal: 5% from ATH and Stop Loss: 13% from ATH
// All values are configurable
//@version=5
indicator('Dip Buyer', 'Dip Buyer', overlay=true)

// input
AthL = input.int(title='All-time-high period', defval=30, minval=0, maxval=365)
WatchSignal = input.int(title='Watch Signal (% Down from ATH)', defval=4, minval=0, maxval=100)
BuySignal = input.int(title='Buy Signal (% Down from ATH)', defval=5, minval=0, maxval=100)
SLSignal = input.int(title='Stop-Loss Signal (% Down from ATH)', defval=13, minval=0, maxval=100)


hiHighs = ta.highest(high, AthL)
watch = hiHighs * (100 - WatchSignal) / 100
buy = hiHighs * (100 - BuySignal) / 100
stoploss = hiHighs * (100 - SLSignal) / 100

// Plot values on the chart
plot(series=hiHighs, color=color.new(color.maroon, 100), linewidth=2)
plot(series=watch, color=color.new(color.yellow, 100), linewidth=2)
plot(series=buy, color=color.new(color.green, 25), linewidth=2)
plot(series=stoploss, color=color.new(color.red, 25), linewidth=2)

plotshape(ta.crossunder(low,watch), 'long', location=location.belowbar, color=color.new(color.yellow, transp=70), style=shape.triangleup, size=size.small)
plotshape(ta.crossunder(low,buy), 'long', location=location.belowbar, color=color.new(color.green, 0), style=shape.triangleup, size=size.small)
plotshape(ta.crossunder(low,stoploss), 'short', location=location.abovebar, color=color.new(color.red, transp=70), style=shape.triangledown, size=size.small)