Flat Tops & Botttoms
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aryanarora33

//@version=5
indicator("AR#C1 Flat Tops & Botttoms", shorttitle = "AR#C1 FT&B", overlay = true, max_bars_back = 500, max_labels_count = 500, max_lines_count = 500)

showFlatTops = input.bool(true, 'Show Flat Tops', group = 'Inputs')
showFlatBottoms = input.bool(true, 'Show Flat Bottoms', group = 'Inputs')
enableAlerts = input(true, title="Enable Alerts", group = 'Inputs')

flat_top = (high == open and showFlatTops) ? true : false
flat_bottom = (low == open and showFlatBottoms) ? true : false

label_below_bar = low - (ta.atr(10) * 0.6)
label_above_bar = high + (ta.atr(10) * 0.6)

plotshape(flat_top, text = '.', style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0), textcolor=color.new(color.black, 0), size=size.tiny)
plotshape(flat_bottom, text = '.', style=shape.triangleup, location=location.belowbar, color=color.new(color.orange, 0), textcolor=color.new(color.black, 0), size=size.tiny)

alertcondition(flat_top and enableAlerts, "Flat Top Detected", "Flat Top")
alertcondition(flat_bottom and enableAlerts, "Flat Bottom Detected", "Flat Bottom")