Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- indicator('PA Pivots', overlay = true)
- // === Inputs
- pivotLen = input.int(5, 'Pivot Length', minval = 1)
- lineLen = input.int(100, 'Line Length', minval = 1)
- upColor = input.color(#b13e00, 'Downtrend Pivot',tooltip ='A break **below** a prior low = bearish (Downtrend Pivot)\n⢠A break **above** a prior high = bullish (Uptrend Pivot)')
- downColor = input.color(#b6a16f, 'Uptrend Pivot')
- pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
- pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
- var float lastHigh = na
- var int lastHighBar = na
- var float lastLow = na
- var int lastLowBar = na
- if not na(pivotHigh)
- lastHigh := pivotHigh
- lastHighBar := bar_index - pivotLen
- if not na(pivotLow)
- lastLow := pivotLow
- lastLowBar := bar_index - pivotLen
- var string pivotLabel = 'ā'
- var float pivotValue = na
- var color trendColor = color.teal
- var line activeLine = na
- if not na(lastLow) and close < lastLow
- if not na(lastHigh)
- line.delete(activeLine)
- activeLine := line.new(x1 = lastHighBar, y1 = lastHigh, x2 = lastHighBar + lineLen, y2 = lastHigh, color = downColor, style = line.style_dashed, width = 2)
- pivotLabel := 'High\nPivot'
- pivotValue := lastHigh
- trendColor := downColor
- if not na(lastHigh) and close > lastHigh
- if not na(lastLow)
- line.delete(activeLine)
- activeLine := line.new(x1 = lastLowBar, y1 = lastLow, x2 = lastLowBar + lineLen, y2 = lastLow, color = upColor, style = line.style_dashed, width = 2)
- pivotLabel := 'Low\nPivot'
- pivotValue := lastLow
- trendColor := upColor
- // === Table: Single visible row
- var table unified = table.new(position.top_right, 2, 1, frame_color = color.black, frame_width = 1, border_width = 1)
- table.cell(unified, 0, 0, pivotLabel, text_color = color.white, bgcolor = #363a45, text_halign = text.align_center)
- table.cell(unified, 1, 0, na(pivotValue) ? 'ā' : str.tostring(pivotValue, '#,##0.00'), text_color = color.white, bgcolor = trendColor, text_halign = text.align_left)
Advertisement
Add Comment
Please, Sign In to add comment