Pullback Warning
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Amphibiantrading

//@version=5
indicator("Pullback Warning", overlay = true)

//constants
EMA9 =  ta.ema(close, 9)
EMA20 = ta.ema(close, 20)
SMA50 = ta.sma(close, 50)

//inputs
sensitivity =   input.string('Normal', 'Sensitivity', options = ['Normal', 'More', 'Less'])
bgFill =        input.bool(true, 'Highlight Backgrond', inline = '1')
bgCol =         input.color(color.new(color.red,85), ' ', inline = '1')
showShape =     input.bool(true, 'Show Symbol', inline = '2')
shapeLocation = input.string('Above Bar', ' ', options = ['Above Bar', 'Below Bar', 'Bottom', 'Top'], inline = '2')

//switches
senseNum = switch sensitivity
    'Normal' => 6
    'More'   => 5
    'Less'   => 7

loc = switch shapeLocation
    'Above Bar' => location.abovebar
    'Below Bar' => location.belowbar
    'Bottom'    => location.bottom
    'Top'       => location.top

//calculations
distMa1 =   math.round(((close / EMA9) -1 ) *100, 1)
distMas =   math.round(((EMA9 / EMA20) - 1) * 100, 1)
dist50 =    math.round(((close / SMA50) -1 ) *100, 1)

//condition
extended = distMa1 > distMas and dist50 >= senseNum

//plots
plotshape(extended and showShape ? 1 : 0, 'Extended', loc == location.abovebar or loc == location.top ? shape.triangledown : shape.triangleup, 
     loc, color.red, display = display.pane)
bgcolor(bgFill and extended ? bgCol : na)