flâneur — a map of the web's best reading

Momentum Oscillator Calculation

chatgpt.com · saved by 1 readers

This little helper computes a classic “momentum oscillator” — basically how far price is from its own moving average, expressed as a percentage. Step‑by‑step: Compute the moving average window is your look‑back length (e.g. 10 bars for a 10‑period MA). min_periods=1 means it will start returning a value immediately (using whatever few points it has at the series start). Oscillator formula You take the difference between the current price and its moving average: price - MA. Divide by the MA to normalize it: (price - MA) / MA. Multiply by 100 to express it as a percentage. + 1e-10 on the denominator just guards against dividing by zero if MA ever hits exactly 0. Clean up NaNs Any initial NaN values (e.g. before there were enough points) get set to 0. So when you do: you’re creating three new series: momentum_osc_10m: % distance from the 10‑period MA momentum_osc_20m: % distance from the 20‑period MA momentum_osc_30m: % distance from the 30‑period MA How to read it: Positive values → pric

Explore this link on the map →

saved by