Volume indicators
Accumulation/Distribution, Money Flow Index, On Balance Volume, Volumes and VWAP: what each computes, its lines and parameters, and how to read it.
The five volume indicators: Accumulation/Distribution, the Money Flow Index, On Balance Volume, Volumes and VWAP. Each one reads the bar's volume, its tick count (what that volume is), so its readings change with the symbol and the price feed a strategy runs on. None takes a parameter for the kind of volume: each reads the bar's volume. The rules every indicator shares are on Indicators: reading a line, the first value, indicators that read volume, colour lines and what is refused.
Accumulation/Distribution
AD in the strategy text · one line, in its own pane
A running total of volume weighted by where each bar closes in its range. Every bar adds ((close − low) − (high − close)) ÷ (high − low) × its volume: the whole volume when it closes on its high, minus the whole volume when it closes on its low, nothing when it closes mid-range. A bar whose high equals its low adds nothing.
- One line (number 0), so a read names no line:
ad[1]. Unbounded, either sign, in units of volume. The text isAD(): no parameters. - First value on bar 0: the first bar's own contribution.
- Its level depends on the first bar the run loaded. It is a total since that bar. Two runs on the same data that start on different bars hold levels that differ by a constant, while their changes from bar to bar are the same: two backtests, or this platform and a chart started elsewhere on the same ticks. A backtest and a live deployment read different tick counts (volume), so their changes differ too.
No parameters.
Reading it in a rule.
- Write rules on the change, never on a fixed level:
ad > ad[1](accumulation on the last bar), or the line against its own earlier values. A rule written elsewhere against a fixed level reads a different level here; write it as a comparison of changes. - In an On Tick rule
ad[0]isad[1]plus what the bar in progress adds so far: where its close so far sits in its range so far, times its volume so far. It moves while the bar forms. Read[1]for the last closed bar.
Verified value by value against an independent reference (the record).
Money Flow Index
MFI in the strategy text · one line, in its own pane, from 0 to 100
A volume-weighted RSI. Over the last N bars, each bar's money flow is its typical price, (high + low + close) ÷ 3, times its volume. The flow is rising when the bar's typical price rose against the previous bar's, falling when it fell, and counts in neither when it did not move. MFI = 100 − 100 ÷ (1 + rising flow ÷ falling flow), over the N changes ending on the bar.
- One line (number 0), so a read names no line:
mfi[1]. The text isMFI(period); a period below 1 is refused. - First value on bar N, the first bar with N changes behind it.
- A window with no falling flow reads 100, and so does a window with no flow at all: a market whose typical price did not move for N bars. Only rising flow reads 100, only falling flow reads 0.
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
Reading it in a rule.
- Above 80 is commonly read as overbought, below 20 as oversold. A 100 with no flow looks like "overbought", so a rule
such as
mfi > 80fires there too; where the price can stand still for N bars, add a condition that rules such a window out. - In an On Tick rule
mfi[0]is computed over the last N − 1 closed changes plus the move into the bar in progress, whose flow is its typical price so far times its volume so far. It is notmfi[1], and it moves while the bar forms. Read[1]for the last closed bar.
Verified value by value against an independent reference (the record).
On Balance Volume
OBV in the strategy text · one line, in its own pane
A running total of volume signed by the close. Each bar adds its volume when it closes above the previous close, subtracts it when it closes below, and leaves the total unchanged when the close is the same.
- One line (number 0), so a read names no line:
obv[1]. Unbounded, either sign, in units of volume. The text isOBV(): no parameters. - First value on bar 0: the first bar has no previous close, and the total starts at its own volume.
- Its level depends on the first bar the run loaded. Two runs on the same data that start on different bars hold levels that differ by a constant from the later start on, while their changes from bar to bar are the same on every bar both have seen: two backtests, or this platform and a chart started elsewhere on the same ticks. A backtest and a live deployment read different tick counts (volume), so their changes differ too.
No parameters.
Reading it in a rule.
- Write rules on the change, never on a fixed level:
obv > obv[1](the last bar closed up on its volume), or the line against its own earlier values. - In an On Tick rule
obv[0]isobv[1]moved by the bar in progress's volume so far: added while its close so far is above the last closed bar's close, subtracted while it is below, nothing while the two are equal. Read[1]for the last closed bar.
Verified value by value against an independent reference (the record).
Volumes
Volumes in the strategy text · the bar's volume and its colour, in their own pane
The bar's volume as a histogram, with a colour that says whether it rose or fell. The text is Volumes(): no
parameters.
| Line (number, name) | What it is | Drawn | First value on bar |
|---|---|---|---|
0 volume, Volume | the bar's volume | on its own bar | 1 |
1 color, Colour | 0 when the volume rose from the previous bar, 1 when it fell, the previous colour when it did not change | on its own bar | 1 |
- Both lines start on bar 1: a series' first bar is left empty. The colour on bar 1 is 0 whatever the volume did against bar 0, since it is the line's first value and has no earlier value to compare with. A run never reads that 0: a colour line warms up one bar more.
- The colour is a number to compare, not a line on the chart (colour lines).
Because an unchanged volume keeps its colour,
color == 0means "the last change was a rise", not "the volume rose on this bar".
No parameters.
Reading it in a rule.
- For a Volumes named
vols,vols.volume[0]in a candle-close rule (vols.volume[1]in an On Tick rule) is the last closed bar's volume;vols.color[0] == 1([1]in an On Tick rule) is "the last closed bar's volume fell". - In an On Tick rule
vols.volume[0]is the bar in progress's volume so far, which grows while the bar forms (live, it can also step when your broker's count replaces the prices received: volume). Its colour compares that volume with the last closed bar's: 1 (fell) while it is lower, 0 (rose) once it is higher, the last closed bar's colour while the two are equal. Read[1]for the last closed bar.
Verified value by value against an independent reference (the record).
VWAP
VWAP in the strategy text · three lines over the candles
The volume-weighted average price since the anchor: Σ(price × volume) ÷ Σ(volume) over every bar from the first bar of
the current session, week or month to the current bar, the price being the bar's applied price (the typical price,
(high + low + close) ÷ 3, by default). The text is VWAP(anchor, appliedPrice, deviation), the anchor session,
week or month.
| Line (number, name) | What it is | Drawn | First value on bar |
|---|---|---|---|
0 vwap, VWAP | the volume-weighted average price since the anchor | on its own bar | the first bar of a period the run has seen |
1 upper, Upper | the VWAP plus the deviation times the volume-weighted standard deviation of the price around it since the anchor | on its own bar | as the VWAP |
2 lower, Lower | the VWAP minus the same distance | on its own bar | as the VWAP |
- The anchor. The session (the day), the week (from Monday) or the month (from the 1st), each starting at midnight in the strategy's time zone, daylight-saving changes included. The time zone is the strategy's, never a parameter of the indicator, so a strategy whose time zone is a broker's server time anchors on that server's day. The sums restart on the first bar of every new period: nothing carries from one period to the next.
- A bar with no volume adds nothing. While the volume since the anchor is 0, all three lines have no value.
- The first value of a run. A run has no VWAP until it has seen the first bar of a period: a bar in another period than the bar before it, or a first bar that opens exactly on its period's start. The warm-up loads one whole anchor period of bars before the start, so a backtest and a live deployment read the same value on the same bar wherever they start.
- The timeframes each anchor accepts. The warm-up is the most bars one period can hold, and a strategy loads at most 2,500 bars of a series: a week needs bars of M5 or longer, a month M20 or longer. A bar as long as its anchor or longer would make every bar a period of its own, so a session needs bars shorter than D1, a week shorter than W1, a month shorter than MN1. Either kind of set is refused when you save, with a message naming the anchor, the timeframe and the nearest timeframe that works.
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Anchor | anchor, 1st | Session | Session, Week, Month | No |
| Applied Price | appliedPrice, 2nd | Typical | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
| Deviation | deviation, 3rd | 1 | ≥ 0 | Yes |
Reading it in a rule.
- The text names the line:
v.vwap[1],v.upper[1],v.lower[1](for a VWAP namedv). No line is drawn forward or back. close > v.vwapis "the close above the day's volume-weighted price" with the session anchor.- In an On Tick rule
[0]includes the bar in progress: its applied price so far, weighted by its volume so far, so all three lines move while the bar forms. On the first bar of a new period[0]is that bar's own price so far, and both bands equal it. Read[1]for the last closed bar. - In an optimization, a sweep of the timeframe that reaches bars too short for the anchor (a weekly VWAP on one-minute bars) is refused when you create it, naming the timeframe and the values of the axis that work (indicators in a sweep). A swept timeframe whose bar is as long as the anchor or longer is not refused there: those combinations run with a VWAP equal to each bar's own price.
Verified value by value against an independent reference (the record).
Questions?support@algotradinghub.io