SavingFace

Price Action Pivots

May 3rd, 2025
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | Cryptocurrency | 0 0
  1. //@version=6
  2. indicator('PA Pivots', overlay = true)
  3.  
  4. // === Inputs
  5. pivotLen = input.int(5, 'Pivot Length', minval = 1)
  6. lineLen = input.int(100, 'Line Length', minval = 1)
  7. 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)')
  8. downColor = input.color(#b6a16f, 'Uptrend Pivot')
  9.  
  10. pivotHigh = ta.pivothigh(high, pivotLen, pivotLen)
  11. pivotLow = ta.pivotlow(low, pivotLen, pivotLen)
  12.  
  13. var float lastHigh = na
  14. var int lastHighBar = na
  15. var float lastLow = na
  16. var int lastLowBar = na
  17.  
  18. if not na(pivotHigh)
  19. lastHigh := pivotHigh
  20. lastHighBar := bar_index - pivotLen
  21.  
  22. if not na(pivotLow)
  23. lastLow := pivotLow
  24. lastLowBar := bar_index - pivotLen
  25.  
  26. var string pivotLabel = '—'
  27. var float pivotValue = na
  28. var color trendColor = color.teal
  29. var line activeLine = na
  30.  
  31. if not na(lastLow) and close < lastLow
  32. if not na(lastHigh)
  33. line.delete(activeLine)
  34. activeLine := line.new(x1 = lastHighBar, y1 = lastHigh, x2 = lastHighBar + lineLen, y2 = lastHigh, color = downColor, style = line.style_dashed, width = 2)
  35. pivotLabel := 'High\nPivot'
  36. pivotValue := lastHigh
  37. trendColor := downColor
  38.  
  39. if not na(lastHigh) and close > lastHigh
  40. if not na(lastLow)
  41. line.delete(activeLine)
  42. activeLine := line.new(x1 = lastLowBar, y1 = lastLow, x2 = lastLowBar + lineLen, y2 = lastLow, color = upColor, style = line.style_dashed, width = 2)
  43. pivotLabel := 'Low\nPivot'
  44. pivotValue := lastLow
  45. trendColor := upColor
  46.  
  47. // === Table: Single visible row
  48. var table unified = table.new(position.top_right, 2, 1, frame_color = color.black, frame_width = 1, border_width = 1)
  49. table.cell(unified, 0, 0, pivotLabel, text_color = color.white, bgcolor = #363a45, text_halign = text.align_center)
  50. table.cell(unified, 1, 0, na(pivotValue) ? '—' : str.tostring(pivotValue, '#,##0.00'), text_color = color.white, bgcolor = trendColor, text_halign = text.align_left)
  51.  
Advertisement
Add Comment
Please, Sign In to add comment