OPEN-SOURCE SCRIPT

RRG Sector Snapshot

46
RRG Sector Snapshot · Clear UI — User Guide

What this indicator does

Purpose: Visualize sector rotation by comparing each sector’s Relative Strength (RS-Ratio) and RS-Momentum versus a benchmark (e.g., VNINDEX).
Output: A quadrant map (table overlay) that positions each sector into one of four regimes:
LEADING (top-right): Strong and accelerating — leadership zone.
WEAKENING (bottom-right): Strong but decelerating — may be topping or consolidating.
LAGGING (bottom-left): Weak and decelerating — avoid unless mean-reverting.
IMPROVING (top-left): Weak but accelerating — candidates for next rotation into leadership.
How it works (under the hood)

X-axis (Strength): RS-Ratio = Sector Close / Benchmark Close, then normalized with a Z-Score over a lookback (normLen).
Y-axis (Momentum): Linear-regression slope of RS-Ratio over rsLen, then normalized with a Z-Score (normLen).
Mapping to grid: Both axes are Z-Scores scaled to a square grid (rrgSize × rrgSize) using a zoom factor (rrgScale). The center is neutral (0,0). Momentum increases upward (Y=0 is the top row in the table).
Quick start (3 minutes)

Add to chart:
TradingView → Pine Editor → paste the script → Save → Add to chart.
Set a benchmark: In inputs, choose Benchmark (X axis) — default INDEX:VNINDEX. Use VN30 or another index if it better reflects your universe.
Load sectors: Fill S1..S10 with sector or index symbols you track (up to 10). Set Slots to Use to the number you actually use.
Adjust view:
rrgSize (grid cells): 18–24 is a good starting point.
rrgScale (zoom): 2.5–3.5 typically; decrease to “zoom out” (points cluster near center), increase to “zoom in” (points spread to edges).
Read the map:
Prioritize sectors in LEADING; shortlist sectors in IMPROVING (could rotate into LEADING).
WEAKENING often marks late-cycle strength; LAGGING is typically avoid.
Inputs — what they do and how to change them
General

Analysis TF: Timeframe used to compute RRG (can be different from chart’s TF). Daily for swing, 1H/4H for tactical rotation, Weekly for macro view.
Benchmark (X axis): The index used for RS baseline (e.g., INDEX:VNINDEX, INDEX:VN30, major ETFs, or a custom composite).
RRG Calculation

RS Lookback (rsLen): Bars used for slope of RS (momentum).
Daily: 30–60 (default 40)
Intraday (1H/4H): 20–40
Weekly: 26–52
Normalization Lookback (Z-Score) (normLen): Window for Z-Score on both axes.
Daily: 80–120 (default 100)
Intraday: 40–80
Weekly: 52–104
Tip: Shorter lookbacks = more responsive but noisier; longer = smoother but slower.
RRG HUD (Table)

Show RRG Snapshot (rrgEnable): Toggle the table on/off.
Position (rrgPos): top_right | top_left | bottom_right | bottom_left.
Grid Size (Cells) (rrgSize): Table dimensions (N×N). Larger = more resolution but takes more space.
Z-Scale (Zoom) (rrgScale): Maps Z-Scores to the grid.
Smaller (2.0–2.5): Zoom out (more points near center).
Larger (3.5–4.0): Zoom in (emphasize outliers).
Appearance

Tag length (tagLen): Characters per sector tag. Use 4–6 for clarity.
Text size (textSizeOp): Tiny | Small | Normal | Large. Use Large for presentation screens or dense lists.
Axis thickness (axisThick): 1 = thin axis; 2 = thicker double-strip axis.
Quadrant alpha (bgAlpha): Transparency of quadrant backgrounds. 80–90 makes text pop.
Sectors (Max 10)

Slots to Use (sectorSlots): How many sector slots are active (≤10).
S1..S10: Each slot is a symbol (index, sector index, or ETF). Replace defaults to fit your market/universe.
How to interpret the map

Quadrants:
Leading (top-right): Relative strength above average and improving — trend-follow candidates.
Weakening (bottom-right): Still strong but momentum cooling — watch for distribution or pauses.
Lagging (bottom-left): Underperforming and still losing momentum — avoid unless doing mean-reversion.
Improving (top-left): Early recovery — candidates to transition into Leading if the move persists.
Overlapping sectors in one cell: The indicator shows “TAG +n” where TAG is the first tag, +n is the number of additional sectors sharing that cell. If many overlap:
Increase rrgSize, or
Decrease rrgScale to zoom out, or
Reduce Slots to Use to a smaller selection.
Suggested workflows
Daily swing

Benchmark: VNINDEX or VN30
rsLen 40–60, normLen 100–120, rrgSize 18–24, rrgScale 2.5–3.5
Routine:
Identify Leading sectors (top-right).
Spot Improving sectors near the midline moving toward top-right.
Confirm with price/volume/breakout on sector charts or top components.
Intraday (1H/4H) tactical

rsLen 20–40, normLen 60–100, rrgScale 2.0–3.0
Expect faster rotations and more noise; tighten filters with your own entry rules.
Weekly (macro rotation)

rsLen 26–52, normLen 52–104, rrgScale 3.0–4.0
Great for portfolio tilts and sector allocation.
Tuning tips

If everything clusters near center: Increase rrgScale (zoom in) or reduce normLen (more contrast).
If points are too spread: Decrease rrgScale (zoom out) or increase normLen (smoother normalization).
If the table is too big/small: Change rrgSize (cells).
If tags are hard to read: Increase textSizeOp to Large, tagLen to 5–6, and consider bgAlpha ~80–85.
Troubleshooting

No table on chart:
Ensure Show RRG Snapshot is enabled.
Change Position to a different corner.
Reduce Grid Size if the table exceeds the chart area.
Many sectors “missing”:
They’re likely overlapping in the same cell; the cell will show “TAG +n”.
Increase rrgSize, decrease rrgScale, or reduce Slots to Use.
Early bars show nothing:
You need enough data for rsLen and normLen. Scroll back or reduce lookbacks temporarily.
Best practices

Use RRG for context and rotation scouting, then confirm with your execution tools (trend structure, breakouts, volume, risk metrics).
Benchmark selection matters. If most of your watchlist tracks VN30, use INDEX:VN30 as the benchmark to get a truer relative read.
Revisit settings per timeframe. Intraday needs more responsiveness (shorter lookbacks, smaller Z-Scale); weekly needs stability (longer lookbacks, larger Z-Scale).
FAQ

Can I use ETFs or custom indices as sectors? Yes. Any symbol supported by TradingView works.
Can I track individual stocks instead of sectors? Yes (up to 10); just replace the S1..S10 symbols.
Why Z-Score? It standardizes each axis to “how unusual” the value is versus its own history — more robust than raw ratios across different scales.



[
i]
How to Set Up (Your Market Template)

This is the most important part for customizing the indicator to any market.

Step 1: Choose Your TF & Benchmark
Open the indicator's Settings.

Analysis TF: Set the timeframe you want to analyze (e.g., D for medium-term, W for long-term).

Benchmark (Trục X): This is the index you want to compare against.

Vietnamese Market: Leave the default INDEX:VNINDEX.

US Market: Change to SP:SPX or NASDAQ:NDX.

Crypto Market: Change to TOTAL (entire market cap) or BTC.D (Bitcoin Dominance).

Step 2: Input Your "Universe" (The 10 Slots)
This is where you decide what to track. You have 10 slots (S1 to S10).

For Vietnamese Sectors (Default):

Leave the default sector codes like INDEX:VNFINLEAD (Finance), INDEX:VNREAL (Real Estate), INDEX:VNIND (Industry), etc.

Template for Crypto "Sectors":

S1: BTC.D

S2: ETH.D

S3: TOTAL2 (Altcoin Market Cap)

S4: TOTAL.DEFI (DeFi)

S5: CRYPTOCAP:GAME (GameFi)

...and so on.

Template for Blue Chip Stocks:

Benchmark: INDEX:VN30

S1: HOSE:FPT

S2: HOSE:VCB

S3: HOSE:HPG

S4: HOSE:MWG

...and so on.

Template for Commodities:

Benchmark: TVC:DXY (US Dollar Index)

S1: TVC:GOLD

S2: TVC:USOIL

S3: TVC:SILVER

S4: COMEX:HG1! (Copper)

...and so on.

Step 3: Fine-Tuning
RS Lookback: A larger number (e.g., 100) gives a smoother, long-term view. A smaller number (e.g., 20) is more sensitive to short-term changes.

Z-Scale (Zoom): This is the "magnification" of the map.

If all your sectors are crowded in the middle, increase this number (e.g., 4.0) to "zoom in."

If your sectors are stuck on the edges, decrease this number (e.g., 2.0) to "zoom out."

Tag length: How many letters to display for the ticker (e.g., 4 will show VNFI).

免責事項

これらの情報および投稿は、TradingViewが提供または保証する金融、投資、取引、またはその他の種類のアドバイスや推奨を意図したものではなく、またそのようなものでもありません。詳しくは利用規約をご覧ください。