Jayadev Rana Get a custom script
Free Pine Script Indicators / Intrabar Delta (request.security_lower_tf)
Free indicator · Pine Script v6

Intrabar Delta (request.security_lower_tf)

Lesson 26 of the Pine Script course. request.security_lower_tf returns the 1 minute candles inside every chart candle as arrays, and the script uses them to estimate buying and selling volume, plot delta as columns and keep a cumulative delta that resets each day.

IndicatorPine Script v6Separate paneFree

Get the codeDownload .pine.txt

Snapshots

Intrabar Delta under Bitcoin 15m: teal and red delta columns, the orange cumulative delta line, and a table for the last candle with intrabar count, volume, estimated buy and sell volume, delta and buy share.
Intrabar Delta under Bitcoin 15m: teal and red delta columns, the orange cumulative delta line, and a table for the last candle with intrabar count, volume, estimated buy and sell volume, delta and buy share.
The first result: delta columns only, teal where up-closing minutes carried more volume.
The first result: delta columns only, teal where up-closing minutes carried more volume.
The complete script in the Pine Editor.
The complete script in the Pine Editor.

How it works

  1. One tuple call to request.security_lower_tf returns arrays of 1 minute opens, closes and volumes for each chart candle.
  2. A guarded loop counts up-closing minutes as buying and down-closing minutes as selling, and splits flat minutes half and half; with no intrabars delta is na, not zero.
  3. It is an estimate from one exchange's volume, not real order flow, and older candles return empty arrays once the intrabar history limit is reached.

Settings

SettingDefaultWhat it does
Intrabar timeframe1The lower timeframe read inside each candle

Source code

In TradingView: open the Pine Editor, create a new indicator, paste the code, then click "Add to chart".

intrabar-delta.pine.txtGitHubDownload
//@version=6
indicator("Intrabar Delta", overlay = false)

ltf = input.timeframe("1", "Intrabar timeframe")

[o, c, v] = request.security_lower_tf(syminfo.tickerid, ltf,
  [open, close, volume])

n = array.size(c)
float buyVol = 0.0
float sellVol = 0.0

if n > 0
    for i = 0 to n - 1
        vol = nz(array.get(v, i))
        oi = array.get(o, i)
        ci = array.get(c, i)
        if ci > oi
            buyVol += vol
        else if ci < oi
            sellVol += vol
        else
            buyVol += vol / 2
            sellVol += vol / 2

delta = n > 0 ? buyVol - sellVol : na
deltaCol = delta >= 0 ? color.teal : color.red
plot(delta, "Delta", deltaCol, style = plot.style_columns)
hline(0, "Zero", color.gray)

var float cvd = 0.0
if timeframe.change("D")
    cvd := 0.0
if not na(delta)
    cvd += delta
plot(n > 0 ? cvd : na, "Cumulative delta", color.orange, 2)

total = n > 0 ? array.sum(v) : na
fmt(float x) => str.tostring(x, format.volume)
var table panel = table.new(position.top_right, 2, 6,
  bgcolor = color.new(color.black, 15), border_width = 1,
  frame_width = 1, frame_color = color.gray)
if barstate.islast
    names = array.from("intrabars", "volume", "buy (est)",
      "sell (est)", "delta", "buy share")
    share = total > 0 ? str.tostring(100 * buyVol / total, "#") + "%" : "-"
    vals = array.from(str.tostring(n), fmt(total), fmt(buyVol),
      fmt(sellVol), fmt(delta), share)
    for i = 0 to 5
        table.cell(panel, 0, i, names.get(i), text_color = color.gray)
        table.cell(panel, 1, i, vals.get(i), text_color = color.white)

Watch it built

This script is written and explained step by step in the video lesson.

Need a custom indicator or strategy?

Non-repainting Pine Script v6, backtested with real costs, alert and webhook ready. Fixed quote within 24 hours.

Free and open source under the Mozilla Public License 2.0. Educational content only, not financial advice. Backtest results are historical and include the costs stated; past performance does not predict future results. © Jayadev Rana · Privacy · Terms