Volume Flow

All functions · nseries package

FiniteVolumeElements

func (s Series) FiniteVolumeElements(h, l, c, v Series, n int, cutoff float64) Series

FiniteVolumeElements returns Markos Katsanos’s finite volume elements (FVE) with his fixed cut-off, from “Detecting Breakouts” (Technical Analysis of Stocks & Commodities, April 2003). A bar’s money flow is the close’s distance above the middle of the bar plus the change in its typical price (the mean of the high, the low and the close). A bar scores its volume when the money flow exceeds the cut-off, minus its volume when the money flow is below the negated cut-off, and 0 otherwise (a flow exactly on the band scores 0). The result is the sum of the scores over n bars as a percentage of the total volume of the same n bars, the bars that scored 0 included, so with non-negative volumes it lies between -100 and 100.

The cut-off is cutoff times the close: cutoff is a fraction of the close, not a percentage. Katsanos uses n = 22 and cutoff = 0.003 on daily bars, and in his September 2003 article scales the fixed cut-off by sqrt(T/390) for T-minute bars. The receiver is not used. h, l, c and v must have the same length; otherwise the result is empty. The call is valid when n is at least 2 and less than the length and cutoff is finite and not negative; an invalid call gives a series of zeros. The warm-up reads 0, not NaN: the first valid index is n (bar 0 has no previous typical price, so the first full window of scores ends at bar n), and bars 0 to n - 1 are 0.

The method is window-local: a NaN or infinite high, low or close gives NaN in every window that holds its bar or the next one (whose money flow reads the previous typical price), a NaN or infinite volume in every window that holds its bar, as does a window whose volumes sum to exactly 0, and later bars recover. With cutoff = 0 each bar’s volume is signed by the sign of its money flow.

FiniteVolumeElementsVolatility

func (s Series) FiniteVolumeElementsVolatility(h, l, c, v Series, n int, coef float64) Series

FiniteVolumeElementsVolatility returns Markos Katsanos’s finite volume elements (FVE) with his volatility cut-off, from “Detecting Breakouts In Intraday Charts” (Technical Analysis of Stocks & Commodities, September 2003). The money flow and the scoring are those of FiniteVolumeElements, but the cut-off is coef times the sum of the interday volatility (the n-bar standard deviation of the log return of the typical price) and the intraday volatility (the n-bar standard deviation of the log of the high over the low), times the close, so the band follows the market instead of being fixed for one bar size. The result is the sum of the scores over n bars as a percentage of the total volume of the same n bars, the bars that scored 0 included, so with non-negative volumes it lies between -100 and 100.

Katsanos uses coef = 0.1, with n = 22 on daily bars. The receiver is not used. h, l, c and v must have the same length; otherwise the result is empty. The call is valid when n is at least 2, coef is finite and not negative and 2n - 1 is less than the length; an invalid call gives a series of zeros. The warm-up reads 0, not NaN: the first valid index is 2n - 1 (the volatilities need n bars before the first scored bar, bar n, and the first full window of scores ends n - 1 bars later), and every earlier bar is 0.

The method is window-local: a NaN or infinite high, low or close at bar p, or a high, low or typical price without a finite logarithm, gives NaN from bar p up to bar p + 2n - 1 (the scores of bars p to p + n read it through their volatility windows or money flow, and each stays in the n-bar sum for n - 1 more bars); a NaN or infinite volume gives NaN while the n-bar window holds its bar, as does a window whose volumes sum to exactly 0; and later bars recover.

VolumeFlowIndicator

func (s Series) VolumeFlowIndicator(h, l, c, v Series, n int, coef, vcoef float64) Series

VolumeFlowIndicator returns Markos Katsanos’s volume flow indicator (VFI) from “Using Money Flow To Stay With The Trend” and “Volume Flow Indicator Performance” (Technical Analysis of Stocks & Commodities, June and July 2004). A bar scores its volume, capped at vcoef times the average volume of the n bars before it, with the sign of the change in its typical price (the mean of the high, the low and the close) when that change exceeds the cut-off, coef times the 30-bar standard deviation of the log return of the typical price times the close; a change inside the band, or exactly on it, scores 0. The scores are summed over n bars, the sum is divided by the average volume of the n bars before the current bar, and the ratio is smoothed with a 3-bar exponential average (a weight of one half on the new value). The 30-bar volatility window and the 3-bar smoothing are fixed, as in the articles. The smoothing is seeded with the mean of the first three raw ratios. MetaStock’s Mov(…, E) is understood to seed with the first value instead (a MetaStock forum formula; Katsanos does not state it), so MetaStock’s early bars differ, by half as much on each later bar.

The receiver is not used. h, l, c and v must have the same length; otherwise the result is empty. Katsanos uses n = 130, coef = 0.2 and vcoef = 2.5 on daily bars, with n = 26 on weekly bars in his 2004 tests (26 to 30 in his 2023 code). The call is valid when n is at least 2 and at most the length, coef is finite and not negative and vcoef is positive (+Inf lifts the cap; NaN is invalid); an invalid call gives a series of zeros, as does a series too short to seed the smoothing. The warm-up reads 0, not NaN: the first valid index is 2n + 1 for n >= 30 (max(n, 30) + n + 1 in general, since the volatility needs 30 bars), and every earlier bar is 0.

The method is recursive, so it does not recover: a NaN or infinity that reaches a raw ratio (through the volatility, the scores or the lagged average) gives NaN from that bar on, because the smoothing feeds each value into the next. A lagged average volume of exactly 0 at bar max(n, 30) + n - 1 or later gives NaN from that bar, or from the first valid index if that is later, to the end; an earlier one, with a finite vcoef, caps that bar’s volume at 0. A +Inf volume is capped on its own bar and gives NaN from the next bar on. A NaN or +Inf volume that reaches only the lagged average of the cap, before bar max(n, 30) + n - 1, lifts the cap on the bars that read it instead of giving NaN. To re-seed, start a fresh slice of the inputs at a later bar.

VolumePriceConfirmationIndicator

func (s Series) VolumePriceConfirmationIndicator(v Series, short, long int) Series

VolumePriceConfirmationIndicator returns Buff Pelz Dormeier’s volume price confirmation indicator (VPCI), from “Between Price And Volume” (Technical Analysis of Stocks & Commodities, July 2007). The receiver s is the price and v the volume. The VPCI is the volume price confirmation (the long-window VWMA of the price minus its SMA, computed as the population covariance of the price and the volume over the long window divided by the mean volume, which equals it in exact arithmetic and gives exactly 0 on a constant volume), times the volume price ratio (the short-window VWMA over the short-window SMA), times the volume multiplier (the short-window mean volume over the long-window mean volume). Dormeier’s test setting is short = 7 and long = 28.

v is right-aligned with s: the trailing min(len(s), len(v)) bars of each overlap, the result has len(s) bars, and the bars of s before the overlap are 0. The call is valid when short is at least 1, long is at least 2, short is at most long and long is at most the overlap; an invalid call gives a series of zeros. The warm-up reads 0, not NaN: the first valid index is long - 1 within the overlap, and every earlier bar is 0.

The method is window-local: a NaN or infinite price or volume gives NaN in the windows that hold it, as does a window whose long-window mean volume is exactly 0, a short window of two or more bars whose volumes sum to exactly 0, a short window whose mean price is exactly 0, a product that overflows, or a short-window volume sum or VWMA sum that overflows, and later bars recover. A short-window price sum or a long-window volume sum that overflows while the other factors stay finite gives 0, not NaN, since a finite value over an infinite mean is 0. The long-window covariance is exact, so it overflows only when its own value is beyond the binary64 range. With a constant positive volume the VPCI is exactly 0 wherever it is not NaN, and scaling the price by a power of two scales the VPCI by the same factor, bit for bit, unless a scaled price, product or sum leaves the binary64 range (by other factors, to rounding).

The signal line, Dormeier’s VPCI smoothed, is a recipe rather than a method: vpci.VWMA(v, 20), the volume-weighted average of this result (Dormeier’s form; he gives no length, and 20 is the setting of the AmiBroker, TradeStation and Wealth-Lab ports in the July 2007 Traders’ Tips), with the bars before long + 18 of the overlap masked, since until then the average reads the warm-up zeros. The dollar-volume variant passes c.Mul(v), the close times the volume, as v.

The long-window covariance is computed exactly, from exact sums over the window, and rounded once (to the nearest float64, ties to even), so a call costs O(len(s)) time whatever long is, and O(len(s) + long) memory. The covariance is start-invariant: dropping leading bars of both inputs leaves its later values unchanged bit for bit. The VPCI as a whole is start-invariant only to rounding, since Average and VWMA sum each window in an order that depends on the bar’s index. On volumes that span many binades a later bar can move by a few ulps once leading bars are dropped (prices 2, 3, 5, 7, 11 and volumes 1, 1, 2^53, 1e-16, 1e-16 with short = long = 4 move bar 4 by 3 ulps), and a window sum that overflows in one order and not the other turns a value into NaN; on ordinary prices and volumes no such bar has been found. The covariance differs from the package’s Covariance, which centres each window and rounds as it goes, by Covariance’s rounding: within about 1e-12 times the product of the two standard deviations on ordinary data, and where cancellation leaves the covariance near 0, Covariance can read a nonzero value where the exact one is 0. A constant volume or a constant price gives a covariance of exactly 0. The exact sums grow with the spread of exponents in the overlap, and the cost with them: when 5e-324 and 1e308 both occur, the price and volume sums reach about 2100 bits, and the product sum about 4200 when one pair holds both.