Direct answer: the formulas, parameters, and data inputs
Bollinger Bands and RSI are both computed from a single time series (typically closing prices):
- Bollinger Bands create an upper band and lower band around a middle band. The middle band is usually a moving average; the distance between bands comes from a standard deviation of prices over a lookback window.
- RSI (Relative Strength Index) is an oscillator that summarizes recent momentum by comparing average gains to average losses over a lookback window, then mapping the result into a value between 0 and 100.
You can calculate both indicators if you have (1) a sequence of prices ordered by time and (2) the chosen parameters (lookback lengths and, for Bollinger Bands, the moving-average type and standard-deviation multiplier).
Mechanics: what each indicator needs and how it is computed
Bollinger Bands: definition and step-by-step calculation
Assume you have a price series (P_t) at times (t) (common input is the closing price). Choose parameters:
- (n): lookback window length (number of periods)
- (k): standard-deviation multiplier for the bands
- (\text{MA}): the moving-average method used for the middle band (often simple moving average, SMA)
For each time (t) where enough history exists (i.e., (t) has at least (n) prior observations):
-
Middle band (basis) [ \text{MB}t = \text{MA}(P{t-n+1},\dots,P_t) ] If you use SMA, then [ \text{MB}t = \frac{1}{n}\sum{i=0}^{n-1} P_{t-i} ]
-
Standard deviation over the window [ \sigma_t = \text{stdev}(P_{t-n+1},\dots,P_t) ] Standard deviation is computed from deviations from the mean of the same window.
-
Upper and lower bands [ \text{Upper}_t = \text{MB}_t + k,\sigma_t ] [ \text{Lower}_t = \text{MB}_t - k,\sigma_t ]
Key data requirement: Bollinger Bands use the same price series consistently. Changing from closes to highs/lows (or changing the sampling frequency) changes (\text{MB}_t) and (\sigma_t), so the bands change.
RSI: definition and step-by-step calculation
RSI uses price changes and distinguishes between upward and downward movement.
Assume the same price series (P_t) and choose:
- (n): lookback window length
Compute one-period changes: [ \Delta_t = P_t - P_{t-1} ] Then compute gains and losses: [ \text{Gain}_t = \max(\Delta_t, 0) ] [ \text{Loss}_t = \max(-\Delta_t, 0) ]
There are multiple smoothing conventions used in practice. The most important point for independent verification is: use the same averaging method as whatever tool you are comparing against.
A common approach starts by computing average gains and losses over the first (n) periods, then applies smoothing (often similar to Wilder’s method). Conceptually:
-
Average gain over the window (or smoothed series) [ \text{AvgGain}_t \approx \text{average of Gain over the last } n \text{ periods (with the chosen smoothing)} ]
-
Average loss [ \text{AvgLoss}_t \approx \text{average of Loss over the last } n \text{ periods (with the chosen smoothing)} ]
-
Relative strength [ \text{RS}_t = \frac{\text{AvgGain}_t}{\text{AvgLoss}_t} ]
-
RSI transform to the range 0–100 [ \text{RSI}_t = 100 - \frac{100}{1+\text{RS}_t} ]
Handling edge cases: If (\text{AvgLoss}_t = 0), then (\text{RS}_t) becomes very large; some implementations return RSI near 100. If (\text{AvgGain}_t = 0), RSI tends toward 0. Different platforms handle these divisions carefully, so exact numeric results can vary.
Evidence or example: recomputing values from a small dataset
Here is a concrete, checkable mini-example structure. (Numbers are placeholders for the method; the key is the calculation flow.)
Assume you have 6 ordered prices (P_1) to (P_6).
Example workflow for Bollinger Bands
Choose (n=3) and (k=2), and use SMA as the moving average.
- For (t=3):
- Compute (\text{MB}_3) as the mean of (P_1,P_2,P_3).
- Compute (\sigma_3) as the standard deviation of (P_1,P_2,P_3).
- Then (\text{Upper}_3=\text{MB}_3+2\sigma_3) and (\text{Lower}_3=\text{MB}_3-2\sigma_3).
- Repeat for (t=4,5,6) using rolling windows ((P_2,P_3,P_4)), etc.
Example workflow for RSI
Choose (n=3).
- Compute changes (\Delta_t=P_t-P_{t-1}) for (t=2..6).
- Convert each (\Delta_t) into (\text{Gain}_t) and (\text{Loss}_t).
- For the first RSI output, compute average gain and average loss over the first (n) eligible periods (e.g., related to (t=2..4), depending on your implementation’s indexing).
- Compute (\text{RS}=\frac{\text{AvgGain}}{\text{AvgLoss}}) and then (\text{RSI}=100-\frac{100}{1+\text{RS}}).
Why this is “evidence”: if you apply the same formulas to the same ordered data and use the same parameter and smoothing choices, you should reproduce the same indicator trajectory. If you do not, the mismatch is usually caused by different parameter settings, different price inputs, or a different RSI smoothing convention.
Limitations and failure modes: what can go wrong and why it matters
Parameter and input sensitivity
Both indicators are deterministic functions of their inputs, but the inputs are choices:
- Price series choice: using closes vs another price changes the values.
- Lookback length: changing (n) changes responsiveness.
- Bollinger moving average and multiplier: different (\text{MA}) types or different (k) values change band width.
- RSI smoothing convention: different smoothing methods can produce different RSI curves even with the same (n).
RSI division-by-zero and near-zero stability
RSI depends on ratios. When average loss is zero (or nearly zero), RSI approaches the upper bound; when average gain is zero, it approaches the lower bound. Small numerical differences (for example, how an implementation handles exact zeros) can cause noticeable RSI differences.
Regime shifts and volatility spikes
Indicators do not “know” future behavior. Bollinger Bands widen or tighten based on recent volatility, and RSI can spend extended time at extreme readings when the underlying pattern persists. During regime shifts (sustained trend changes or abrupt volatility changes), historical relationships can stop being informative.
Data and computation alignment problems
Independent verification can fail due to practical issues rather than indicator flaws:
- inconsistent time zone or session boundaries when constructing (P_t)
- different sampling frequency
- missing data points or corporate-action adjusted prices that change the series definition
Verification or next question: how to check the calculations yourself
To verify Bollinger Bands and RSI independently:
- Fix the input series: decide exactly what (P_t) is (e. g. , unadjusted closes, adjusted closes) and use the same ordering. 2) Fix the parameters: record (n), (k), the Bollinger moving-average type, and the RSI averaging/smoothing method.