Momentum and oscillators¶
Momentum functions describe price change, strength or location within a recent range. Their scales differ: compare RSI with an RSI threshold, MACD with a price-unit value, and ROC with percentage points.
RSI¶
rsi(14) calculates Relative Strength Index from close using a 14-bar period and Wilder smoothing. It returns a series on a 0–100 scale. rsi(close, 14) is the explicit equivalent; rsi(close) uses the default period of 14.
rsi(14) > 50
rsi(14) < 30
rsi(14) > rsi(14)[1]
rsi(high, 14) > 50
The first test selects readings above 50. The second selects readings below 30; it does not mean price must rebound. The third asks whether the reading rose since the previous bar. The final call changes the input from close to high.
In rsi(14) < 30, 14 is the calculation period; 30 is your rule's threshold. A reading of 30 is not a 30% loss. RSI starts with a missing first reading; in this implementation a completely flat price sequence subsequently reads 0, while gains without losses read 100. Check warmup rather than treating an initial extreme as a mature signal.
See RSI mean reversion for a complete strategy with explained entry and exit rules.
MACD, signal and histogram¶
The three functions use the same arguments: fast EMA period, slow EMA period, signal EMA period. Defaults are 12, 26, 9. Each returns one series in price units.
| Function | Meaning | Call |
|---|---|---|
macd |
Fast EMA minus slow EMA. | macd(12, 26, 9) |
macd_signal |
EMA of the MACD line. | macd_signal(12, 26, 9) |
macd_hist |
MACD minus its signal. | macd_hist(12, 26, 9) |
macd(12, 26, 9) > macd_signal(12, 26, 9)
macd(12, 26, 9) crosses over macd_signal(12, 26, 9)
macd_hist(12, 26, 9) > 0
Use the same settings on both lines when describing one MACD system. A positive histogram means MACD is above signal; it does not necessarily mean MACD itself is positive. For default settings with an explicit input, use macd(close), macd_signal(close) or macd_hist(close). Empty calls do not select close. Do not use .signal or tuple unpacking.
Price change: ROC, momentum and PPO¶
| Function | Form and defaults | Result |
|---|---|---|
roc |
roc(14) or roc(close, 14); default period 14. |
100 × (current − earlier) / earlier, in percentage points. |
momentum |
momentum(14) or momentum(close, 14); supply the period explicitly. |
Current price minus price N bars ago, in price units. |
ppo |
ppo(12, 26) or ppo(close, 12, 26); defaults 12, 26 with explicit input. |
100 × (fast EMA − slow EMA) / slow EMA. |
If price rises from 100 to 105 over 14 bars, ROC is 5 and momentum is 5 price units. If it rises from 1,000 to 1,050, ROC is still 5, while momentum is 50. To compare price-relative change across instruments, use ROC rather than absolute momentum. momentum_rank is a separate portfolio-ranking function.
roc(14) > 5
momentum(14) > 0
ppo(12, 26) > 0
Use momentum, not the catalog-only abbreviation mom; the standard runtime does not bind mom. Momentum at offset N requires N+1 prices. The helpers page explains why pct_change uses 0.05 for the same 5% change.
Stochastic and Williams %R¶
These compare close with the recent high–low range and therefore need complete bars.
| Function | Form and defaults | Result |
|---|---|---|
stochastic, stochastic_k |
stochastic(14, 3, 1); lookback 14, %D smoothing 3, multiplier 1. |
The %K series, normally 0–100 at multiplier 1. Both names select the same line. |
stochastic_d |
stochastic_d(14, 3, 1) |
The 3-bar SMA of %K with those settings. |
williams_r |
williams_r(14); default 14. |
Series from −100 to 0. Near 0 is near the range high. |
stochastic_k(14, 3) crosses over stochastic_d(14, 3)
stochastic(14) < 20
williams_r(14) < -80
The stochastic multiplier scales both lines: changing it changes the appropriate thresholds. Williams %R uses negative readings; writing williams_r(14) < 80 is a very different test from < -80. Both ranges include the current bar. Empty calls use default settings and automatically select the complete bars for this family.
CCI and other oscillators¶
| Function | Form | Meaning and settings |
|---|---|---|
cci |
cci(20, 0.015) |
Commodity Channel Index: typical-price deviation from its average, scaled by mean absolute deviation and the constant. Defaults 20 and 0.015. Unbounded series; ±100 are reference levels, not limits. |
tsi |
tsi(25, 13) |
True Strength Index: double-smoothed price change divided by double-smoothed absolute change, ×100. Periods default to 25, 13 with explicit close. |
rmi |
rmi(bars, 14, 5) |
Relative Momentum Index: 14-period smoothing of 5-bar price changes. Defaults 14, 5 after explicit bars; normally 0–100. |
awesome |
awesome(bars, 5, 34) |
Fast minus slow SMA of midpoint (high + low) / 2, in price units. Defaults 5, 34 after explicit bars. |
stc |
stc(bars, 23, 50, 10) |
Schaff Trend Cycle: fast EMA period, slow EMA period, cycle window. Defaults 23, 50, 10; a normalised, smoothed cycle series. |
modified_stochastic |
modified_stochastic(bars, 14) |
Applies extra smoothing to %K, using %D period 3 internally; default lookback 14 after explicit bars. May overshoot. |
cci(20) > 100
tsi(25, 13) > 0
rmi(bars, 14, 5) > 50
awesome(bars, 5, 34) > 0
stc(bars, 23, 50, 10) > 50
modified_stochastic(bars, 14) > 50
Keep the explicit bars argument on rmi, awesome, stc and modified_stochastic: period-only shorthand is not implemented for those names. Unlike a bounded oscillator, CCI can exceed 100 or fall below −100. Extra smoothing does not make a threshold equivalent to that of the unsmoothed indicator.
modified_rsi is an exposed extra-smoothed RSI function, but it currently produces missing readings on ordinary close history, even after a long warmup. Use rsi for working rules until that calculation is corrected. Its period default is 14.
trix currently returns multiple lines without an exposed single-line TradeScript function. See special cases before using that name.