you could use the min/max function to achieve that.
so in the end, your final code could look like this:
//@version=4
study("My Script",overlay=true)
lookbackres= input(3,title="Res Lookback")
lookbacksup= input(3,title="Sup Lookback")
res=highest(max(open,close),lookbackres)
sup=lowest(min(open,close),lookbacksup)
plot(series=res, color=color.green, linewidth=2)
plot(series=sup, color=color.red, linewidth=2)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…