// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © relievedApple77224

//@version=5
indicator("1D Enter Alerts", overlay=true, max_bars_back = 5000, precision = 1)

hodLodRange = input.int(10, "HOD / LOD range", group = "Signal Settings")
showAddAlertCircle = input.bool(true, "Show Add Alert Circle", group = "Add Alert Circle")
addAlertCircleOffset = input.int(6, "Add Alert Circle Offset", group = "Add Alert Circle")
restrictIndicatorsRange = input.int(defval = 78, title = "Max indicator bars range", group = "Visibility")

defaultDisplay = display.all - display.status_line - display.price_scale

// Calculate the 8-period EMA
ema8 = ta.ema(close, 8)
ema3 = ta.ema(close, 3)
sma50 = ta.sma(close, 50)
sma100 = ta.sma(close, 100)
sma200 = ta.sma(close, 200)

exitCode = 0

// Initialize variables to track VWAP cross conditions
var float newHoD = na
var float newLoD = na
var int spyDir = 0
var bool lastBarWasHodLod = false

highestHigh = ta.highest(high[1], hodLodRange)
lowestLow = ta.lowest(low[1], hodLodRange)

halfATR = ta.atr(14) * 0.5

// Update the variables when there's a crossover or crossunder
if close > highestHigh
newHoD := close