I would like to code an indicator that would do like on my screen, that is to say find the high and low and in a precise way and when a high or low is touched that it changes the position of the other. Example : We are bearish, the low is touched, the high will change automatically.
I would like to know if it is possible and if I am on the right track?
I found as a base this script, but I do not know if it is a good idea?
Thanks in advance for your help.
//@version=5
indicator(title='Fractals Alerts', shorttitle='Fractals Alerts', overlay=true)
n = input.int(title='Periods', defval=2, minval=2)
upFractal = high[n - 1] < high[n] and high[n + 1] < high[n]
dnFractal = low[n - 1] > low[n] and low[n + 1] > low[n]
ufh = ta.valuewhen(upFractal, ta.highest(3), 0)
dfl = ta.valuewhen(dnFractal, ta.lowest(3), 0)
sh_broke = ta.crossover(high, ufh)
sl_broke = ta.crossunder(low, dfl),
plot(upFractal ? ufh: na, "High Broken", style=plot.style_stepline, offset=-2, color=color.new(color.green, 0))
plot(dfl, "Low Broken",style=plot.style_stepline, offset=-2, color=color.new(color.red, 0))