Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=6
- indicator("Count of Candlesticks >1% Change (Visible Range)", overlay=true)
- // Calculate the percentage change from open to close
- float percentChange = (close - open) / open * 100
- // Check if the percentage change is greater than 1% or less than -1%
- bool highlightCondition = math.abs(percentChange) > 1
- // Highlight the candlesticks
- bgcolor(highlightCondition ? color.new(color.yellow, 80) : na)
- // Initialize a counter for visible candlesticks
- int visibleCount = 0
- // Reset the counter at the start of each iteration through visible bars
- if (barstate.isnew)
- visibleCount := 0
- // Increment the counter for highlighted candlesticks
- if (highlightCondition)
- visibleCount += 1
- // Display the count as a label in a fixed position on the chart
- if (barstate.islast)
- label.new(
- bar_index,
- high + 5 * syminfo.mintick,
- "Visible Candles >1%: " + str.tostring(visibleCount),
- xloc.bar_index,
- yloc.price,
- style = label.style_label_up,
- color = color.new(color.black, 90),
- textcolor = color.white,
- size = size.normal
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement