Livelli Sensibili Orizzontali//@version=5
indicator("Livelli Sensibili Orizzontali", overlay=true)
// Funzione per trovare massimi/minimi SOLAMENTE sui punti più alti e più bassi raggiunti con almeno 3 candele decrescenti o crescenti dopo o prima
isSwingHigh(src) =>
ta.highestbars(src, 4) == 0 and high < high and high < high and high < high and ta.valuewhen(high == ta.highest(high, 10), high, 0) == high
isSwingLow(src) =>
ta.lowestbars(src, 4) == 0 and low > low and low > low and low > low and ta.valuewhen(low == ta.lowest(low, 10), low, 0) == low
// Identificazione dei livelli sensibili
var float lastHigh = na
var float lastLow = na
if isSwingHigh(high)
lastHigh := high
if isSwingLow(low)
lastLow := low
// Disegna linee orizzontali SOLO sui massimi e minimi effettivi
line.new(x1=bar_index , y1=lastHigh, x2=bar_index, y2=lastHigh, width=2, color=color.red)
line.new(x1=bar_index , y1=lastLow, x2=bar_index, y2=lastLow, width=2, color=color.green)