Indicator · Pine Script v6 · On the chart

Delta Break and Retest Stage 1 Delta Engine

by rosijay17-cmd

An indicator that estimates per-bar delta from open, high, low, close and volume, scaling volume by where the close sits within the bar range.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code197
Settings6inputs
LicenceGPL-3.0
Last update7 days ago22 Oct 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

197 lines of Pine Script v6 from delta_break_retest/Stage1_DeltaEngine.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Stage1_DeltaEngine.pine
//@version=6

// ============================================================================
// DELTA BREAK & RETEST -- STAGE 1: DELTA ENGINE (Revision 1)
// ----------------------------------------------------------------------------
// Per the build spec (Section 9), Stage 1: "Port the histogram as a pure
// function. Plot it. Sanity-check against a known session by eye."
//
// Revision 1 per request: instead of a per-bar-over-TIME histogram, the
// delta is now shown as a PRICE-BINNED profile (teal/orange horizontal bars
// at price, like the old script's right-side histogram) plus a dashboard.
// This pulls forward the price-binning piece of Stage 2 ("Delta profile +
// POI extraction") a bit early for the visual -- flagged here explicitly so
// the staged-build boundary stays clear. NOT pulled forward: POI extraction
// itself (POC/flip-level/absorption-node typing, contamination counters,
// zone merging, freshness expiry) -- that is still genuine Stage 2 work and
// is not in this file.
//
// SCOPE DISCIPLINE (Section 0) unchanged: the ONLY thing inherited from the
// old strategy is f_delta() -- a pure function taking nothing but OHLCV.
// The profile-binning and dashboard code below are freshly written for this
// rebuild, not copied from the old script's histogram/dashboard code (which
// was entangled with P0/acceptance-rejection state this rebuild is
// deliberately leaving behind).
//
// STILL NO TRADING LOGIC of any kind -- indicator only.
// ============================================================================

indicator(title = "Delta Break & Retest - Stage 1 Delta Engine", shorttitle = "DBR Stage1", overlay = true)

// ============================================================================
// PURE DELTA FUNCTION
//-----------------------------------------------------------------------------
// delta(bar) -> float, in spec terms. Nothing enters this function but
// price/volume data -- no globals, no strategy state, no filter variables.
// Ported unchanged from the old script's f_delta().
// ============================================================================

f_delta(float o, float h, float l, float c, float v) =>
    float safeRange = math.max(h - l, syminfo.mintick)
    float pressure = math.max(math.min((c - o) / safeRange, 1.0), -1.0)
    v * pressure

float barDelta = f_delta(open, high, low, close, nz(volume, 0.0))

// ============================================================================
// INPUTS
// ============================================================================

int profileRowsInput = input.int(40, "Profile Rows", minval = 10, maxval = 120, group = "Delta Profile")
int maxSessionBarsInput = input.int(300, "Max Bars Scanned Per Session", minval = 20, maxval = 2000, group = "Delta Profile", tooltip = "Safety cap on how far back the profile rebuild looks each bar. A normal intraday session should stay well under this.")
int histogramOffsetInput = input.int(6, "Histogram Offset (Bars)", minval = 1, maxval = 60, group = "Delta Profile")
int histogramWidthInput = input.int(30, "Histogram Max Width (Bars)", minval = 5, maxval = 100, group = "Delta Profile")
color positiveDeltaColorInput = input.color(color.teal, "Positive Delta Color", group = "Delta Profile")
color negativeDeltaColorInput = input.color(color.orange, "Negative Delta Color", group = "Delta Profile")

// ============================================================================
// SESSION TRACKING
// ============================================================================

bool newSession = ta.change(time("D")) != 0

var int sessionStartBar = bar_index

if newSession
    sessionStartBar := bar_index

int barsIntoSession = bar_index - sessionStartBar + 1
int scanBars = math.min(barsIntoSession, maxSessionBarsInput)

var float cumulativeDelta = 0.0

if newSession
    cumulativeDelta := 0.0

cumulativeDelta := cumulativeDelta + barDelta

// ============================================================================
// PRICE-BINNED DELTA PROFILE (current session, rebuilt on the last bar)
// ----------------------------------------------------------------------------
// Simplification flagged explicitly: each bar's delta is attributed to the
// single row containing that bar's CLOSE, not distributed proportionally
// across the bar's full high/low range. That range-proportional version is
// Stage 2 POI-construction territory (Section 3 of the spec) -- this stage
// is the plain, by-eye sanity check only.
// ============================================================================

var array<box> profileBoxes = array.new_box()
var float sessionHigh = na
var float sessionLow = na
var float deltaPocPrice = na
var float totalPositiveDelta = 0.0
var float totalNegativeDelta = 0.0

if barstate.islast

    if array.size(profileBoxes) > 0
        for i = 0 to array.size(profileBoxes) - 1
            box.delete(array.get(profileBoxes, i))
    array.clear(profileBoxes)

    float scanHigh = -1.0e20
    float scanLow = 1.0e20

    for i = 0 to scanBars - 1
        scanHigh := math.max(scanHigh, high[i])
        scanLow := math.min(scanLow, low[i])

    sessionHigh := scanHigh
    sessionLow := scanLow

    float rowStep = math.max((scanHigh - scanLow) / profileRowsInput, syminfo.mintick)

    array<float> rowDelta = array.new_float(profileRowsInput, 0.0)
    array<float> rowVolume = array.new_float(profileRowsInput, 0.0)

    for i = 0 to scanBars - 1
        float barD = f_delta(open[i], high[i], low[i], close[i], nz(volume[i], 0.0))
        int row = int(math.floor((close[i] - scanLow) / rowStep))
        row := math.max(0, math.min(profileRowsInput - 1, row))
        array.set(rowDelta, row, array.get(rowDelta, row) + barD)
        array.set(rowVolume, row, array.get(rowVolume, row) + nz(volume[i], 0.0))

    float maxAbsDelta = 0.0
    float maxAbsDeltaValue = 0.0
    int pocRow = 0
    float posSum = 0.0
    float negSum = 0.0

    for row = 0 to profileRowsInput - 1
        float d = array.get(rowDelta, row)
        if d > 0
            posSum += d
        if d < 0
            negSum += d
        if math.abs(d) > maxAbsDelta
            maxAbsDelta := math.abs(d)
            maxAbsDeltaValue := d
            pocRow := row

    totalPositiveDelta := posSum
    totalNegativeDelta := negSum
    deltaPocPrice := scanLow + (pocRow + 0.5) * rowStep

    int centerX = bar_index + histogramOffsetInput

    for row = 0 to profileRowsInput - 1
        float d = array.get(rowDelta, row)
        if d != 0
            float rowLow = scanLow + row * rowStep
            float rowHigh = rowLow + rowStep
            int barWidth = maxAbsDelta > 0 ? int(math.round(histogramWidthInput * math.abs(d) / maxAbsDelta)) : 0
            if barWidth > 0
                color barColor = d >= 0 ? positiveDeltaColorInput : negativeDeltaColorInput
                box rowBox = box.new(
                     left = centerX,
                     top = rowHigh,
                     right = centerX + barWidth,
                     bottom = rowLow,
                     xloc = xloc.bar_index,
                     bgcolor = color.new(barColor, 15),
                     border_color = color.new(barColor, 40)
                )
                array.push(profileBoxes, rowBox)

// ============================================================================
// DASHBOARD
// ============================================================================

var table statusTable = table.new(position.top_right, 2, 6, bgcolor = color.new(color.rgb(15, 20, 27), 10), border_width = 1)

if barstate.islast
    table.cell(statusTable, 0, 0, "STAGE 1 DELTA ENGINE", text_color = color.white, bgcolor = color.rgb(22, 52, 86))
    table.cell(statusTable, 1, 0, "", text_color = color.white, bgcolor = color.rgb(22, 52, 86))

    table.cell(statusTable, 0, 1, "Bars Scanned (Session)", text_color = color.white)
    table.cell(statusTable, 1, 1, str.tostring(scanBars), text_color = color.white)

    table.cell(statusTable, 0, 2, "Session High / Low", text_color = color.white)
    table.cell(statusTable, 1, 2, str.tostring(sessionHigh, format.mintick) + " / " + str.tostring(sessionLow, format.mintick), text_color = color.white)

    table.cell(statusTable, 0, 3, "Delta POC Price", text_color = color.white)
    table.cell(statusTable, 1, 3, str.tostring(deltaPocPrice, format.mintick), text_color = color.aqua)

    table.cell(statusTable, 0, 4, "Total Pos / Neg Delta", text_color = color.white)
    table.cell(statusTable, 1, 4, str.tostring(totalPositiveDelta, "#") + " / " + str.tostring(totalNegativeDelta, "#"), text_color = color.white)

    table.cell(statusTable, 0, 5, "Session Net Delta", text_color = color.white)
    table.cell(statusTable, 1, 5, str.tostring(cumulativeDelta, "#"), text_color = cumulativeDelta >= 0 ? positiveDeltaColorInput : negativeDeltaColorInput)

// ============================================================================
// DATA WINDOW
// ============================================================================

plot(barDelta, title = "Per-Bar Delta", display = display.data_window)
plot(cumulativeDelta, title = "Cumulative Session Delta", display = display.data_window)
plot(newSession ? 1 : 0, title = "New Session", display = display.data_window)

Overview

Delta Break and Retest Stage 1 Delta Engine rebuilds a session profile binned by price and draws it as teal and orange horizontal bars to the right of price, plus a small dashboard. Rows, scan depth, offset, width and colours are adjustable. The code states it is a first build stage with no trading logic.

Details

Published by

rosijay17-cmd on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Volume

Markets

Any symbol

Timeframes

M15-H1

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Profile Rowsint40profileRowsInput
Max Bars Scanned Per Sessionint300maxSessionBarsInput
Histogram Offset (Bars)int6histogramOffsetInput
Histogram Max Width (Bars)int30histogramWidthInput
Positive Delta Colorcolorcolor.tealpositiveDeltaColorInput
Negative Delta Colorcolorcolor.orangenegativeDeltaColorInput
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Calculates an Elastic Volume Weighted Moving Average (EVWMA), incorporating trading volume to dynamically adjust moving average responsiveness over a specified lookback length. It plots directly on the price chart as a single moving average line. Optional colo

Indicator v4 Moving averagesVolume
Updated 11 days ago · GPL-3.0 GitHub repository of Elastic Volume Weighted Moving Average

This overlay indicator screens a pasted list of up to forty symbols and draws a table on the price chart. It classifies bullish or bearish setups from the percent change between the current candle and the candle 250 bars back, then shows RSI with a simple movi

Indicator v5 Oscillators & momentumVolume
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - Ankush Bajaj Momentum Investing Setup

This overlay indicator draws a fixed-range volume profile on the price chart, splitting traded activity into up and down volume at each price level. It also plots a sentiment profile, a developing point of control, and value-area high and low around a configur

Indicator v5 VolumeSupport & resistance
Updated 2 months ago · MIT GitHub repository of Volume Profile and Indicator by DGT

META-tracker

by Allen1212
303 stars

This indicator overlays historical ARK Invest buy and sell events for META on the price chart. It places green labels below bars for purchases and red labels above bars for sales, with a same-day count of how many selected ARK ETFs traded the stock. The ETF in

Indicator v4 Volume
Updated 2 years ago · None stated GitHub repository of META-tracker
219 stars

An educational Pine Script v4 indicator demonstrating how to plot volume histograms on the main price chart using unscaled axes. The code includes examples and commented templates for creating vertical line markers at specific dates or time zones, such as mark

Indicator v4 Sessions & timeVolume
Updated 5 years ago · None stated GitHub repository of 教學-畫垂直線1

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers