Funds Inflow Near Closing Bell
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Qpxcaro
//@version=4
// Investment funds often execute their oreders in the last 30 minutes of a daily trading session
// This script approximates inflow/outflow of professionally managed money into a given security
// IMPORTANT! Must be plotted on a timeframe with DAILY resolution (can be applied to other timeframes as well, but results will be nonsensical)

study("Funds Inflow Near Closing Bell")

period = input(title="Minutes before closing bell", type=input.resolution, defval="30")

c = security(syminfo.tickerid, period, close)
o = security(syminfo.tickerid, period, open)
h = security(syminfo.tickerid, period, high)
l = security(syminfo.tickerid, period, low)
v = security(syminfo.tickerid, period, volume)

float todays_imbalance = 0.0
todays_imbalance := v * (c - o) / (h - l)  // previously (log(c) - log(o)) * v * (o + c) / 2.0

_series = 0.0
_series := nz(_series[1], 1) + todays_imbalance

plot(_series, style=plot.style_line)