language(1)
indicator(
"Volume", id = "core.volume",
description = "Displays total or buy/sell volume, with optional highlighting when candle direction conflicts with volume.",
source = "https://github.com/flowsurface-rs/flowsurface/blob/main/data/indicators/sources/volume.ind",
sourceable = true,
optional_trades = true, max_bars_back = 1)
format(precision = "base_ticker_min_qty", axis_labels = "abbreviated", header_labels = "commas", scale = "fit_visible_include_zero")
highlight_divergence = input.bool(false, "Highlight candle/volume divergence", group = "display", requires = "directional_volume")
has_directional_volume = chart.directional_volume_available
buy = select(has_directional_volume, chart.buy_qty, na)
sell = select(has_directional_volume, chart.sell_qty, na)
signed = select(has_directional_volume, buy - sell, na)
divergence = select(highlight_divergence && has_directional_volume, (chart.buy_qty > chart.sell_qty && chart.close < chart.open) || (chart.sell_qty > chart.buy_qty && chart.close > chart.open), false)
plot(chart.volume, id = "value", title = "Volume", precision = "instrument", style = "histogram", color_slot = "main", mark = "histogram_signed_overlay", overlay = false)
plot(buy, id = "volume.buy", title = "Buy", precision = "instrument", color_slot = "positive", overlay = false, layer = false)
plot(sell, id = "volume.sell", title = "Sell", precision = "instrument", color_slot = "negative", overlay = false, layer = false)
plot(signed, id = "signed_overlay", title = "Signed overlay", precision = "instrument", overlay = false, layer = false)
plot(divergence, id = "divergence", title = "Candle/volume divergence", display = "none", overlay = false, layer = false)
style("main", title = "Line")
style("bars", title = "Bars", role = "secondary")
style("positive", title = "Positive overlay", role = "success")
style("negative", title = "Negative overlay", role = "danger")
style("warning", title = "Candle/volume divergence", role = "warning", requires = "directional_volume")
mark(title = "Line", source = "value", kind = "line", color_slot = "main")
mark(title = "Bars", source = "value", kind = "histogram", color_slot = "bars", highlight_by = "divergence", highlight_color_slot = "warning")
mark(title = "Overlay bars", source = "signed_overlay", kind = "histogram_signed_overlay", color_slot = "positive", true_color_slot = "positive", false_color_slot = "negative", highlight_by = "divergence", highlight_color_slot = "warning", requires = "directional_volume", fallback = "histogram")
readout(title = "B", source = "volume.buy", color_slot = "positive", mark = "histogram_signed_overlay")
readout(title = "S", source = "volume.sell", color_slot = "negative", mark = "histogram_signed_overlay")