OPEN-SOURCE SCRIPT
Momentum Structural Analysis

Momentum Structural Analysis (MSA‑style Oscillator)
This indicator implements a simple, MSA‑style momentum oscillator that measures how far price has moved above or below its own long‑term trend on the active timeframe, expressed in percentage terms. Instead of looking at raw price, it "oscillates" price around a timeframe‑appropriate simple moving average (SMA) and plots the percentage distance from that SMA as an orange line around a zero baseline. Zero means price is exactly at its structural trend; positive values mean price is extended above trend; negative values mean it is trading below trend.
The script automatically selects the SMA length based on the chart timeframe:
This approach is inspired by the ideas behind Momentum Structural Analysis (MSA), which studies where a market trades relative to long‑term moving averages and then treats the momentum line (the oscillator) as the primary object of analysis. The goal is to highlight structural overbought/oversold conditions and regime changes that are often clearer on momentum than on the raw price chart.
--------------------------------------------------
What the script computes and how it works
For each bar, the indicator:
This produces a momentum oscillator that oscillates around zero and reflects the "structural" position of price versus its own long‑term mean.
--------------------------------------------------
How to use it on index charts (e.g., NIFTY50)
On indices like NIFTY50, use the indicator to see how stretched the index is versus its structural trend.
Typical uses:
This is not a buy/sell signal generator by itself; it is a framework to understand where the index sits within its long‑term momentum structure and to support risk‑management decisions.
--------------------------------------------------
How to use it on ratio charts
Apply the same indicator to ratio symbols such as NIFTY50/GOLD, BANKNIFTY/NIFTY50, sector vs index, or any spread you plot as a ratio.
On a ratio chart:
This is very much in the spirit of MSA’s work on spreads between asset classes: it helps visualize major rotations (equities → gold, financials → commodities, etc.) and whether a relative‑performance trend is stretched, reverting, or breaking into a new phase.
--------------------------------------------------
Using multiple timeframes for better decisions
You can stack information across timeframes to get a more robust view:
Monthly: a). Use monthly charts to see secular/structural phases. b). Long multi‑year stretches above or below zero, and large bases or trendline breaks on the monthly oscillator, can mark major bull or bear cycles and big rotations between asset classes.
Weekly: a). Use weekly charts for the primary trend. b). Weekly structures (multi‑month highs/lows, channels, or trendlines on the oscillator) are useful for medium‑term positioning and for confirming or rejecting signals seen on the monthly view.
Daily: a). Use daily charts mainly for timing entries/exits once the higher‑timeframe direction is clear. b). Short‑term extremes on the daily oscillator that align with the larger weekly/monthly structure can offer better‑timed opportunities, while signals that contradict higher‑timeframe momentum are more likely to be noise.
--------------------------------------------------
This indicator implements a simple, MSA‑style momentum oscillator that measures how far price has moved above or below its own long‑term trend on the active timeframe, expressed in percentage terms. Instead of looking at raw price, it "oscillates" price around a timeframe‑appropriate simple moving average (SMA) and plots the percentage distance from that SMA as an orange line around a zero baseline. Zero means price is exactly at its structural trend; positive values mean price is extended above trend; negative values mean it is trading below trend.
The script automatically selects the SMA length based on the chart timeframe:
- On daily charts it uses the configurable Daily SMA Length (default 252 trading days, roughly 1 year).
- On weekly charts it uses Weekly SMA Length (default 208 weeks).
- On monthly charts it uses Monthly SMA Length (default 120 months).
This approach is inspired by the ideas behind Momentum Structural Analysis (MSA), which studies where a market trades relative to long‑term moving averages and then treats the momentum line (the oscillator) as the primary object of analysis. The goal is to highlight structural overbought/oversold conditions and regime changes that are often clearer on momentum than on the raw price chart.
--------------------------------------------------
What the script computes and how it works
For each bar, the indicator:
- Chooses an SMA length based on the current timeframe (daily/weekly/monthly).
- Calculates the SMA of the close.
- Computes the percentage distance:
- \text{Diff %} = \frac{\text{Close} - \text{SMA}}{\text{SMA}} \times 100
- Plots this Diff % as an orange line, with a dashed horizontal zero line as the base.
This produces a momentum oscillator that oscillates around zero and reflects the "structural" position of price versus its own long‑term mean.
--------------------------------------------------
How to use it on index charts (e.g., NIFTY50)
On indices like NIFTY50, use the indicator to see how stretched the index is versus its structural trend.
Typical uses:
- Identify extremes: a). Historically high positive readings can signal euphoric, late‑stage conditions where risk is elevated. b). Deep negative readings can highlight panic/capitulation zones where downside may be exhausted.
- Draw structural levels: a). Mark horizontal bands on the oscillator where past turns have occurred (e.g., +15%, −10%, etc. specific to NIFTY50). b). Watch how price behaves when the oscillator revisits these zones: repeated rejections can validate them as structural bounds; clean breaks can indicate a change of regime.
This is not a buy/sell signal generator by itself; it is a framework to understand where the index sits within its long‑term momentum structure and to support risk‑management decisions.
--------------------------------------------------
How to use it on ratio charts
Apply the same indicator to ratio symbols such as NIFTY50/GOLD, BANKNIFTY/NIFTY50, sector vs index, or any spread you plot as a ratio.
On a ratio chart:
- The oscillator now measures relative momentum: how far that ratio is above or below its own long‑term mean.
- High positive readings = strong outperformance of the numerator vs the denominator (e.g., equities strongly outperforming gold).
- Deep negative readings = strong underperformance (e.g., equities structurally lagging gold).
This is very much in the spirit of MSA’s work on spreads between asset classes: it helps visualize major rotations (equities → gold, financials → commodities, etc.) and whether a relative‑performance trend is stretched, reverting, or breaking into a new phase.
--------------------------------------------------
Using multiple timeframes for better decisions
You can stack information across timeframes to get a more robust view:
Monthly: a). Use monthly charts to see secular/structural phases. b). Long multi‑year stretches above or below zero, and large bases or trendline breaks on the monthly oscillator, can mark major bull or bear cycles and big rotations between asset classes.
Weekly: a). Use weekly charts for the primary trend. b). Weekly structures (multi‑month highs/lows, channels, or trendlines on the oscillator) are useful for medium‑term positioning and for confirming or rejecting signals seen on the monthly view.
Daily: a). Use daily charts mainly for timing entries/exits once the higher‑timeframe direction is clear. b). Short‑term extremes on the daily oscillator that align with the larger weekly/monthly structure can offer better‑timed opportunities, while signals that contradict higher‑timeframe momentum are more likely to be noise.
--------------------------------------------------
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。