Oscillators
The oscillators: RSI, ATR, MACD, the Stochastic, CCI, momentum and the rest. What each computes, its lines, its parameters and how to read it in a rule.
The oscillators, by name: lines on a scale of their own, around zero or between fixed bounds, rather than on the price. What every indicator shares — reading a line and its position, the first value and the warm-up, the indicators that read volume — is on Indicators; each entry below says what is particular to it. Bars are counted from bar 0, the first bar the run loaded (the first value). Each entry is written in the strategy text with its parameters in the order its table gives, and a line of an indicator with several lines is read by its name or by its number, counted from 0 in the order the entry's table gives.
ATR
ATR in the strategy text · one line
The average true range. A bar's true range is the largest of high − low, |high − previous close| and |low − previous close|; the first bar's is high − low. Two smoothings, chosen in the editor:
- Wilder (preselected): the first value is the plain average of the first N true ranges, then (previous × (N − 1) + true range) ÷ N. It is recursive: its first values in a run depend on where the run started (recursive indicators).
- Sma: a sliding average of the last N true ranges. In the strategy text,
ATR(period, sma). - One line (number 0), so a read names no line:
atr[1]. First value on bar N − 1 in both smoothings. In price units, never negative.
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
| Smoothing | method, 2nd | Wilder | Wilder, Sma | No |
Reading it in a rule. It is in price units, so it sizes stops and targets: a stop price of ask − 2 × atr is an
Expression. In an On Tick rule atr[0] takes the bar in progress's range so far as its newest true range. Where the
true range has been 0 for a whole window, the Sma smoothing can hold a residue of a few 1e-17 rather than exactly 0.
Verified value by value against an independent reference (the record).
Bears Power
BearsPower in the strategy text · one line
How far the sellers pushed the bar below the trend: the bar's low less an exponential moving average of the close over the period (k = 2 ÷ (N + 1), started from the first close).
- One line (number 0), so a read names no line:
bears[1]. First value on bar N − 1; the bars before it have no value. In price units, around zero, unbounded: below zero the bar's low is under the average. - Always the close: it has no applied price. In the strategy text,
BearsPower(period).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 13 bars | 1 – 2,500 bars | Yes |
Reading it in a rule. Compare it with zero, or with its own earlier values: it is in price units, so a threshold
that suits one instrument means nothing on another. Bulls Power is the same calculation on the high; the two are read
together. In an On Tick rule bears[0] uses the bar in progress's low and close so far.
Verified value by value against an independent reference (the record).
Bulls Power
BullsPower in the strategy text · one line
How far the buyers pushed the bar above the trend: the bar's high less the same exponential moving average of the close as Bears Power's. On the same bars and period, Bulls Power − Bears Power is the bar's range.
- One line (number 0), so a read names no line:
bulls[1]. First value on bar N − 1; the bars before it have no value. In price units, around zero, unbounded: above zero the bar's high is over the average. - Always the close: it has no applied price. In the strategy text,
BullsPower(period).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 13 bars | 1 – 2,500 bars | Yes |
Reading it in a rule. Compare it with zero, or with its own earlier values. In an On Tick rule bulls[0] uses the
bar in progress's high and close so far.
Verified value by value against an independent reference (the record).
CCI
CCI in the strategy text · one line
The Commodity Channel Index: how far the applied price sits from its simple average over the last N bars, in units of 0.015 times the mean absolute deviation of those N prices: (price − average) ÷ (0.015 × mean deviation). The average is carried from bar to bar, previous + (incoming − outgoing) ÷ N.
- One line (number 0), so a read names no line:
cci[1]. First value on bar N − 1. Unbounded; most values fall between −100 and +100. - A window of N equal prices reads 0: its deviation is zero, and the window is checked itself, so a rounding residue in the carried average never turns it into a large value. A period of 1 always reads 0.
- In the strategy text,
CCI(period, appliedPrice).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
| Applied Price | appliedPrice, 2nd | Typical | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
Reading it in a rule. The usual guides are the levels −100 and +100. In an On Tick rule cci[0] uses the price so
far as the window's newest price.
Verified value by value against an independent reference (the record).
Chaikin Oscillator
ChaikinOscillator in the strategy text · one line
The momentum of the Accumulation/Distribution line: its moving average over the fast period less its moving average over the slow period, both by the chosen method. The line is the Accumulation/Distribution's own.
- One line (number 0), so a read names no line:
chaikin[1]. First value on bar max(fast, slow) − 1, every method; the bars before it have no value. Around zero, unbounded, in volume units: above zero the A/D line is rising faster than its slower average. - Equal fast and slow periods give 0 on every bar; a fast period longer than the slow one is accepted and gives the opposite sign.
- It reads the bar's volume; there is no volume parameter. In the strategy text,
ChaikinOscillator(fast, slow, method). - Unlike the A/D line, once its averages have settled it does not depend on the bar a run started on: the averages remove the A/D line's level (an exponential or smoothed average forgets its start at the slow period's rate, a simple or linear-weighted one after one slow window).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Fast Period | fastPeriod, 1st | 3 bars | 1 – 2,500 bars | Yes |
| Slow Period | slowPeriod, 2nd | 10 bars | 1 – 2,500 bars | Yes |
| Method | method, 3rd | Ema | Sma, Ema, Smma, Lwma | No |
Reading it in a rule. Compare it with zero, or with its own earlier values: its scale depends on the instrument and
on the bar's volume, its tick count (indicators that read volume,
volume). In an On Tick rule [0] is the bar in progress: what it adds to the
A/D line so far (its volume so far, weighted by where its close so far sits in its range so far) is added to the last
closed bar's total, and both averages take one more step on that total. It moves while the bar forms and is not
chaikin[1]; read [1] for the last closed bar. With the linear-weighted method the line carries a slowly growing rounding error
(the linear-weighted drift).
Verified value by value against an independent reference (the record).
DeMarker
DeMarker in the strategy text · one line, from 0 to 1
Buying against selling pressure, from the bars' highs and lows. A bar's DeMax is how far its high rose above the previous high (0 when it did not rise), its DeMin how far its low fell below the previous low (0 when it did not fall); the series' first bar counts as no move. DeMarker = average DeMax ÷ (average DeMax + average DeMin), both simple averages over N bars, carried from bar to bar.
- One line (number 0), so a read names no line:
demarker[1]. First value on bar N − 1. From 0 to 1: only rising highs read 1, only falling lows read 0. - A window in which no bar moved reads 0: the window's moves are counted, so rounding residues in the carried averages never turn it into an arbitrary number. Where only one side moved, the value can sit a residue away from 0 or 1 (such as −5e-17 or 1.0000000000000007).
- Highs and lows only: no applied price, no volume. In the strategy text,
DeMarker(period).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
Reading it in a rule. The usual guides are 0.3 and 0.7. The first window of any series counts its first bar as no move, so the first value averages N − 1 real moves and a zero.
Verified value by value against an independent reference (the record).
Force Index
ForceIndex in the strategy text · one line
A move weighed by the volume behind it: the bar's volume times the change, from the previous bar, of a moving average of the close over the period, by the chosen method.
- One line (number 0), so a read names no line:
force[1]. First value on bar N, every method; the bars before it have no value. Around zero, unbounded, in volume × price units: above zero the average rose. - Always the close: it has no applied price. It reads the bar's volume; there is no volume parameter. In the strategy
text,
ForceIndex(period, method).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 13 bars | 1 – 2,500 bars | Yes |
| Method | method, 2nd | Sma | Sma, Ema, Smma, Lwma | No |
Reading it in a rule. Compare it with zero, or with its own earlier values: its scale depends on the instrument and
on the bar's volume, its tick count (indicators that read volume,
volume). In an On Tick rule [0] is the bar in progress: its volume so far
times the change of the average taken with its close so far, so force[0] moves while the bar forms; read [1] for
the last closed bar. With the linear-weighted method the line carries a slowly growing rounding
error (the linear-weighted drift).
Verified value by value against an independent reference (the record).
MACD
MACD in the strategy text · two lines
The fast exponential moving average of the applied price less the slow one, and a simple average of that difference. Both exponential averages start from the first bar's price (k = 2 ÷ (period + 1)).
| Line (number, name) | What it is | Drawn | First value on bar |
|---|---|---|---|
0 main, Main | fast average − slow average, in price units around zero | on its own bar | max(fast, slow) − 1 |
1 signal, Signal | the simple average of the main line over the signal period | on its own bar | max(fast, slow) + signal − 2 |
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Fast EMA Period | fastPeriod, 1st | 12 bars | 1 – 2,500 bars | Yes |
| Slow EMA Period | slowPeriod, 2nd | 26 bars | 1 – 2,500 bars | Yes |
| Signal SMA Period | signalPeriod, 3rd | 9 bars | 1 – 2,500 bars | Yes |
| Applied Price | appliedPrice, 4th | Close | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
In the strategy text, MACD(fast, slow, signal, appliedPrice). The longer of the two averages plus the signal period,
less one, may not pass 2,500 bars: the signal line needs the longer average's history and
its own. A set beyond it is refused when you save.
Reading it in a rule. The usual tests are crossings: macd.main crosses above macd.signal, or the main line against
zero. Both lines are in price units, so a threshold that suits one instrument means nothing on another; crossings
carry over. A signal period of 1 makes the signal line the main line. A fast period longer than the slow one is
accepted: the main line is then the negative of the swapped pair's. In an optimization, a sweep whose largest periods
stack past the history limit is refused when you create it
(indicators in a sweep).
Verified value by value against an independent reference (the record).
Momentum
Momentum in the strategy text · one line
The applied price as a percentage of the same price N bars earlier: price ÷ price N bars ago × 100. A ratio around 100, not a difference: 100 means unchanged over the period, 101.5 means 1.5 % higher, 98 means 2 % lower.
- One line (number 0), so a read names no line:
momentum[1]. First value on bar N, the first bar with a price N bars before it. - The period is at least 1. An earlier price of 0 gives no value; only Volume as the applied price can be 0.
- In the strategy text,
Momentum(period, appliedPrice).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
| Applied Price | appliedPrice, 2nd | Close | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
Reading it in a rule. Compare it with 100, not with 0: mom > 100 is "higher than N bars ago". A rule written for a
momentum defined as a difference (price − price N bars ago, "above 0") is always true here. In an On Tick rule
mom[0] uses the price so far.
Verified value by value against an independent reference (the record).
OsMA
OsMA in the strategy text · one line
The MACD's main line less its signal line: the fast exponential average of the applied price, less the slow one, less
the simple average of that difference over the signal period. It is the MACD's own calculation, so it always equals
macd.main − macd.signal for the same parameters.
- One line (number 0), so a read names no line:
osma[1]. First value on bar max(fast, slow) + signal − 2. In price units, around zero: above zero while the MACD's main line is above its signal line. - A signal period of 1 gives 0 on every bar.
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Fast EMA Period | fastPeriod, 1st | 12 bars | 1 – 2,500 bars | Yes |
| Slow EMA Period | slowPeriod, 2nd | 26 bars | 1 – 2,500 bars | Yes |
| Signal SMA Period | signalPeriod, 3rd | 9 bars | 1 – 2,500 bars | Yes |
| Applied Price | appliedPrice, 4th | Close | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
In the strategy text, OsMA(fast, slow, signal, appliedPrice). The longer of the two averages plus the signal period,
less one, may not pass 2,500 bars, as for the MACD.
Reading it in a rule. Its sign and its zero crossings carry over between instruments; a threshold does not. In an optimization, a sweep whose largest periods stack past the history limit is refused when you create it (indicators in a sweep).
Verified value by value against an independent reference (the record).
RSI
RSI in the strategy text · one line, from 0 to 100
Wilder's RSI on the applied price. The first N price changes are averaged into an average gain and an average loss (the first value is at the N-th change), then each average is (average × (N − 1) + current) ÷ N; RSI = 100 − 100 ÷ (1 + average gain ÷ average loss). If the average loss is 0 the RSI is 100, including a completely flat window where both averages are 0; if only the average gain is 0 it is 0.
- One line (number 0), so a read names no line:
rsi[1]. First value on bar N. - It is recursive: its first values in a run depend on where the run started, and a run that starts later reads a line that converges to one started earlier (recursive indicators).
- In the strategy text,
RSI(period, appliedPrice).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 1 – 2,500 bars | Yes |
| Applied Price | appliedPrice, 2nd | Close | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
Reading it in a rule. The usual guides are 30 and 70. In an On Tick rule rsi[0] uses the price so far as the
newest change.
Verified value by value against an independent reference (the record).
RVI
RVI in the strategy text · two lines
The Relative Vigor Index: how firmly bars close away from their open, against their range. Each bar's close − open is smoothed over that bar and the three before it with weights 1, 2, 2, 1, and high − low the same way; the main line is the sum over N bars of the first divided by the sum of the second.
| Line (number, name) | What it is | Drawn | First value on bar |
|---|---|---|---|
0 main, Main | the RVI, in practice between −1 and 1 | on its own bar | N + 2 |
1 signal, Signal | the main line smoothed over four bars with weights 1, 2, 2, 1, divided by 6 | on its own bar | N + 5 |
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 10 bars | 1 – 2,494 bars | Yes |
In the strategy text, RVI(period). The signal line's first value needs N + 6 bars, which stay within
2,500. Where the summed range is 0 the main line is the summed body itself (0 on a flat
market).
Reading it in a rule. The usual tests are the main line crossing its signal line, or crossing zero.
Verified value by value against an independent reference (the record).
Stochastic Oscillator
Stochastic in the strategy text · two lines, from 0 to 100
Where the close sits inside the range of the last K bars, from 0 (on the window's lowest price) to 100 (on its highest).
Over the last slowing bars, the close's distances above the window's lowest are added up, and so are the window's
ranges (highest − lowest); the main line is the first sum ÷ the second × 100. The highest and lowest come from the
bars' highs and lows (Low/High) or from their closes (Close/Close). A summed range of 0 (a flat market) reads 100.
| Line (number, name) | What it is | Drawn | First value on bar |
|---|---|---|---|
0 main, Main | the %K line | on its own bar | K + slowing − 2 |
1 signal, Signal | a moving average of the main line over D values, by the signal method | on its own bar | K + slowing + D − 3, every method |
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| K Period | kPeriod, 1st | 5 bars | 1 – 2,500 bars | Yes |
| D Period | dPeriod, 2nd | 3 bars | 1 – 2,500 bars | Yes |
| Slowing | slowing, 3rd | 3 bars | 1 – 2,500 bars | Yes |
| Signal Method | method, 4th | Sma | Sma, Ema, Smma, Lwma | No |
| Price Field | priceField, 5th | LowHigh | LowHigh, CloseClose | No |
In the strategy text, Stochastic(k, d, slowing, method, priceField), the method sma, ema, smma or lwma and
the price field lowHigh or closeClose. With the exponential method the signal's first D − 1 values are empty, as
with every other method. K + slowing + D − 2 may not pass 2,500 bars: the three periods
stack. A set beyond it is refused when you save.
Reading it in a rule. The usual guides are 20 and 80. A flat market reads 100, not 50: a rule that sells "when the main line is above 80" fires in a dead market. A signal period of 1 makes the signal line the main line; K = 1 with Close/Close reads 100 on every bar. With the linear-weighted signal the signal line carries a slowly growing rounding error (the linear-weighted drift). In an optimization, a sweep whose largest periods stack past the history limit is refused when you create it (indicators in a sweep).
Verified value by value against an independent reference (the record).
TRIX
TRIX in the strategy text · one line
The applied price smoothed by three exponential moving averages of period N in a row (k = 2 ÷ (N + 1)); TRIX is the one-bar change of the third average divided by its previous value. It is a small fraction, not multiplied by 100: 0.0001 means the triple-smoothed price rose 0.01 % on that bar.
- One line (number 0), so a read names no line:
trix[1]. First value on bar 3 × (N − 1). 0 where the previous third average is 0. - The period is at least 2. In the strategy text,
TRIX(period, appliedPrice). - It is recursive: its first values in a run carry its starting point and fade over a few times N bars (recursive indicators).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 2 – 834 bars | Yes |
| Applied Price | appliedPrice, 2nd | Close | Close, Open, High, Low, Median, Typical, Weighted, Volume | No |
Reading it in a rule. Above zero the smoothed price is rising, below zero falling. A threshold is written as a
fraction (trix > 0.0002), not as a percentage.
Verified value by value against an independent reference (the record).
Williams' Percent Range
WPR in the strategy text · one line, from −100 to 0
Where the close sits inside the range of the last N bars, counted down from the top: −(highest high − close) × 100 ÷ (highest high − lowest low), over the last N bars, the current one included. A window whose highest high equals its lowest low (a flat market) reads 0.
- One line (number 0), so a read names no line:
wpr[1]. First value on bar N − 1. From −100 (the close on the lowest low) to 0 (on the highest high). - The period is at least 3; a smaller one is refused when you save. In the strategy text,
WPR(period).
| Field | In the text | Default | Values | Can be swept |
|---|---|---|---|---|
| Period | period, 1st | 14 bars | 3 – 2,500 bars | Yes |
Reading it in a rule. Negative values are the normal case: above −20 is commonly read as overbought, below −80 as
oversold. A flat market reads 0, the top of the scale, so a rule that sells "when wpr > -20" fires in a dead market.
It is the Stochastic's raw %K (K = N, slowing 1, Low/High) less 100.
Verified value by value against an independent reference (the record).
Questions?support@algotradinghub.io