Close Over/Under Level
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ddctv

//@version=5
indicator("Close Over/Under Level", overlay=true)


// Inputs
closeAboveLevel = input(0.0)
closeBelowLevel = input(0.0)
plotLines = input(true)


// Logic
closedAbove = closeAboveLevel > 0 and close[1] > closeAboveLevel
closedBelow = closeBelowLevel > 0 and close[1] < closeBelowLevel


// Plots
plot( closeAboveLevel > 0 and plotLines ? closeAboveLevel : na, color = color.new(color.red,50), style=plot.style_circles, offset=-1 )
plot( closeBelowLevel > 0  and plotLines ? closeBelowLevel : na, color = color.new(color.blue,50), style=plot.style_circles, offset=-1 )


// Alerts
alertcondition(closedAbove, title="Close Over", message="{{ticker}} closed above {{plot_0}}.")
alertcondition(closedBelow, title="Close Under", message="{{ticker}} closed below {{plot_1}}.")