Hammer / Shooting Star Scanner
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Hampeh

//@version=5
indicator(title="Hammer / Shooting Star Scanner", shorttitle="HSS Scanner", overlay=true)

csbody = math.abs(close - open)
bodyshadowratio = input(title="Minimum Ratio Shadow Over Body", defval=2.0)

//scanner algorithms

hammervalid() => (close[1] >= close and open[1] >= close) and (close[1] >= open and open[1] >= open) ? true : false
shootingstarvalid() => (close[1] <= close and open[1] <= close) and (close[1] <= open and open[1] <= open) ? true : false
hammer = hammervalid() and (csbody > 0) and (((close == high) and math.abs(open - low) > csbody * bodyshadowratio) or ((open == high) and math.abs(close - low) > csbody * bodyshadowratio)) 
shootingstar = shootingstarvalid() and (csbody > 0) and (((close == low) and math.abs(open - high) > csbody * bodyshadowratio) or ((open == low) and math.abs(close - high) > csbody * bodyshadowratio)) 

//chart plotters
plotshape(hammer, style=shape.arrowup, location=location.belowbar, color=color.green, text='H')
plotshape(shootingstar, style=shape.arrowdown, location=location.abovebar, color=color.red, text='SS')

alertcondition(shootingstar, title = "Alert Hammer / Shooting Star", message = 'ALERT : SHOOTING STAR DETECTED')
alertcondition(hammer, title = "Alert Hammer / Shooting Star", message = 'ALERT : HAMMER STAR DETECTED')