Advertisement
DaMfingCaptain

Pinescript Candle Highlight

Dec 8th, 2024
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | Money | 0 0
  1. //@version=6
  2. indicator("Count of Candlesticks >1% Change (Visible Range)", overlay=true)
  3.  
  4. // Calculate the percentage change from open to close
  5. float percentChange = (close - open) / open * 100
  6.  
  7. // Check if the percentage change is greater than 1% or less than -1%
  8. bool highlightCondition = math.abs(percentChange) > 1
  9.  
  10. // Highlight the candlesticks
  11. bgcolor(highlightCondition ? color.new(color.yellow, 80) : na)
  12.  
  13. // Initialize a counter for visible candlesticks
  14. int visibleCount = 0
  15.  
  16. // Reset the counter at the start of each iteration through visible bars
  17. if (barstate.isnew)
  18. visibleCount := 0
  19.  
  20. // Increment the counter for highlighted candlesticks
  21. if (highlightCondition)
  22. visibleCount += 1
  23.  
  24. // Display the count as a label in a fixed position on the chart
  25. if (barstate.islast)
  26. label.new(
  27. bar_index,
  28. high + 5 * syminfo.mintick,
  29. "Visible Candles >1%: " + str.tostring(visibleCount),
  30. xloc.bar_index,
  31. yloc.price,
  32. style = label.style_label_up,
  33. color = color.new(color.black, 90),
  34. textcolor = color.white,
  35. size = size.normal
  36. )
Tags: pinescript
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement