//@version=5
indicator(title="枢轴高点与低点", shorttitle="枢轴点")
lengthL = input.int(11, title="左侧长度", minval=1)
lengthR = input.int(11, title="右侧长度", minval=1)
zigzagShow = input(false, "显示连线")
pivotLevelShow = input(false, "显示枢轴线")
bgcolorShow = input(false, "显示背景")
buySellShow = input(true, "显示买卖")
pivotH = ta.pivothigh(lengthL, lengthR)
pivotL = ta.pivotlow(lengthL, lengthR)
bgcolor(color = bool(pivotH) ? color.new(color.red, 70) : bool(pivotL) ? color.new(color.green, 70) : na, display = bgcolorShow ? display.all : display.none)
float pivotPoint = na
var float pivotLevel = na
if bool(pivotH)
pivotPoint := pivotH
pivotLevel := pivotPoint
if bool(pivotL)
pivotPoint := pivotL
pivotLevel := pivotPoint
plot(zigzagShow ? pivotPoint : na, offset = -lengthL, style = plot.style_line)
plot(pivotLevelShow ? pivotLevel : na, offset = -lengthL, style = plot.style_line, color = pivotLevel != pivotLevel[1] ? na : color.white)
plotshape(buySellShow ? pivotH : na, offset = 0-lengthL, text = "卖出", textcolor = color.red,
style = shape.arrowdown, color=color.new(color.red, 0), size = size.auto, location = location.abovebar)
plotshape(buySellShow ? pivotL : na, offset = 0-lengthL, text = "买入", textcolor = color.lime,
style = shape.arrowup, color=color.new(color.lime, 0), size = size.auto, location = location.belowbar)