highest_bars_ago

Bars ago when highest value occurred

highest_bars_ago(source, period)

Parameters

Name Type Description
source field Data series
period int Lookback period

Formula

highest_bars_ago = sample_number - sample_number of ARG_MAX(source) over the trailing period window

Examples

// highest close right now (fresh 20-bar high)
highest_bars_ago(close, 20) == 0;
// highest occurred more than 10 bars ago (weakening)
highest_bars_ago(high, 50) > 10;
// highest within last 5 bars (recent strength)
highest_bars_ago(close, 20) < 5;

Returns

int

Range

period must be 2-400

Notes

NULL when source is NULL on every bar of the trailing window -- e.g. a nested indicator source still in its own warm-up

See Also

lowest_bars_ago