Skip to content

How the numbers are calculated

Every indicator is written by hand and tested against values worked out independently. Here are the formulas.

1. The same calculation every time

Each indicator is a self-contained calculation: it takes a series of completed daily bars and its settings, and returns values. It does not read the clock, the network or the database, so the same history always gives the same answer.

  • Only completed trading days are used — never a day still in progress.
  • When a split, bonus or data correction is recorded, the history is restated and the readings are calculated again from it, so an older reading can change.

2. Relative Strength Index (RSI, 14 days)

RSI follows J. Welles Wilder Jr.’s original smoothing, not the simple-average shortcut some charting tools use.

Change = Close[t] − Close[t−1]

Gain = max(Change, 0), Loss = max(−Change, 0)

AvgGain[t] = (AvgGain[t−1] × 13 + Gain[t]) / 14

AvgLoss[t] = (AvgLoss[t−1] × 13 + Loss[t]) / 14

RSI = 100 − 100 / (1 + AvgGain / AvgLoss)

The first value needs 15 closes. Wilder smoothing settles over roughly the next 100 sessions, so a stock with a short history can show a slightly different RSI from a platform that holds more of it. When there were no losses at all, RSI is 100.

3. Moving averages (SMA and EMA)

Simple moving averages (20 and 50 days) are the plain average of the last N closes. Exponential moving averages (20, 50 and 200 days) weight recent closes more:

α = 2 / (N + 1)

EMA[t] = Close[t] × α + EMA[t−1] × (1 − α)

The first EMA value is the simple average of the first N closes — the convention charting platforms use.

4. MACD (12, 26, 9)

MACD line = EMA(12) − EMA(26)

Signal line = EMA(9) of the MACD line

Histogram = MACD line − Signal line

5. Average True Range (ATR, 14 days)

True range is the largest of: today’s high − low, |high − previous close| and |low − previous close|, so overnight gaps count. ATR is its 14-day Wilder average, in rupees.

6. Splits, bonuses and price history

Prices are stored as the exchange reported them and are never edited. A split or bonus is recorded separately, with its ex-date and exact ratio:

  • Every price before the ex-date is multiplied by the combined ratio when the history is read (a 1:5 split has a ratio of 0.2).
  • Volume is divided by the same ratio, so traded value stays comparable.
  • Adjusted prices are rounded to the nearest whole paisa.
  • Dividends are recorded but are not applied to prices.
Methodology: how the numbers are calculated | EquityWise