//@version=6 indicator("Workshop 03 Stretch", overlay=false) length = input.int(20, "Reference bars", minval=2) threshold = input.float(2.0, "Distance", minval=0.1) center = ta.sma(close, length)[1] spread = ta.stdev(close, length, true)[1] z = spread > 0 ? (close - center) / spread : na plot(z, "Distance in deviations", color=color.blue) hline(0, "Reference", color=color.gray) hline(threshold, "Upper distance", color=color.gray) hline(-threshold, "Lower distance", color=color.gray) lowExtreme = z < -threshold and barstate.isconfirmed plotshape(lowExtreme, "Low extreme", shape.circle, location.bottom, color=color.orange, size=size.tiny)