OPEN-SOURCE SCRIPT
更新済 S&R + Trends | Polytrends Method (gracefultrading)

SUPPORT & RESISTANCE + TRENDS | POLYTRENDS METHOD
Maps market structure automatically: every trend is detected, classified, and turned into support/resistance levels that know their own state. Built around the polytrends method of reading structure through trends and progression. This is my own independent, open-source interpretation of the framework, coded from scratch based on publicly available material. For educational purposes only — not financial advice.
TRENDS AND CONTAINMENT
Every pivot is compared against the previous pivot in the same direction. A swing that pushes past the prior trend is a valid continuation and draws in the trend colour. A swing that fails to exceed it — a lower high on the way up and or a lower low on the way down — is a containment trend, drawn in its own colour and style.
The current in-progress leg draws dashed, so you always see the swing being built. Pivot detection reacts to wick pullbacks, close-breaks of the prior candle, structural breaks, and same-bar reversals — not fixed-length lookbacks.
LEVELS WITH STATE
Each trend leaves a level at the candle body, committed only after the next opposite pivot confirms it. Every label shows the level's current state at a glance:
G — gained
SG — support gained
L — lost
RL — resistance lost
State updates bar by bar as price closes through or reclaims a level. An optional break/test offset (in ticks or percent) means a level only counts as gained, lost, or tested once price clears it by your buffer.
PAIRED STRUCTURE
Levels come from trends and draws in colour-matched pairs from a 12-colour set, each pair originating from the same piece of structure.
Tested levels draw in a different line style from untested ones and can be hidden entirely; when hidden, you choose whether each pair still shows its tested partner so pairs stay intact. At high relevance settings, clustered tested levels within a tick distance thin down to the strongest one.
POLYBOUNDS
Experimental.
A corner readout that reduces the chart to the two prices that matter:
▲ hold above — the key gained level below price. Bulls are in control while price holds above it.
▼ hold below — the key lost level above price. Bears are in control while price holds below it.
Each line is coloured to match its pair on the chart, and the box only quotes levels that are actually drawn. A Trend Day row (1H and below) reads whether the session is shaping up bullish, bearish, or rangebound based on where price sits against the bounds.
SETTINGS
Levels above/below counts. A relevance dial controlling how deep into history levels are pulled from (50 bars to full history). Independent colours, styles, and widths for trends, containment trends, and levels. Configurable label background and twelve pair colours. A right-offset so all level rays align cleanly ahead of price.
HOW TO READ IT
The market is always in progression — always attempting either a new high or a new low. Every swing this indicator draws is one attempt in that sequence, and every level is the footprint it leaves behind.
Progression rule: in an uptrend, price should not lose the previous swing low if it intends to go higher — losing it shifts probability toward the opposite objective. Mirror logic in a downtrend. Watch the level states: a support flipping from SG to L is that shift happening in real time.
Containment is the early warning. A containment trend (lower high in an uptrend, higher low in a downtrend) means the progression is failing before any level has broken. Trend weakness is the warning; level failure is the confirmation.
Levels mark accepted value. They're built from candle bodies, not wicks — the goal is to see where the market accepted or rejected value, which is why the break/test offset exists to filter wick noise.
Untested levels react first. Fresh levels are the highest-priority reaction zones; tested levels remain valid structure and become targets when price is nearer to them. The pair colours show you which structure each level came from.
Timeframes nest. Higher-timeframe levels are destinations; lower-timeframe levels are the navigation between them. Significant trends typically start from higher-timeframe pivots — the biggest swings on your chart usually trace back to them. RTH-formed levels tend to carry the most weight.
Works on any symbol and timeframe; the Trend Day readout is built for intraday. This is a tool for reading structure, not a signal service — nothing replaces risk management.
Maps market structure automatically: every trend is detected, classified, and turned into support/resistance levels that know their own state. Built around the polytrends method of reading structure through trends and progression. This is my own independent, open-source interpretation of the framework, coded from scratch based on publicly available material. For educational purposes only — not financial advice.
TRENDS AND CONTAINMENT
Every pivot is compared against the previous pivot in the same direction. A swing that pushes past the prior trend is a valid continuation and draws in the trend colour. A swing that fails to exceed it — a lower high on the way up and or a lower low on the way down — is a containment trend, drawn in its own colour and style.
The current in-progress leg draws dashed, so you always see the swing being built. Pivot detection reacts to wick pullbacks, close-breaks of the prior candle, structural breaks, and same-bar reversals — not fixed-length lookbacks.
LEVELS WITH STATE
Each trend leaves a level at the candle body, committed only after the next opposite pivot confirms it. Every label shows the level's current state at a glance:
G — gained
SG — support gained
L — lost
RL — resistance lost
State updates bar by bar as price closes through or reclaims a level. An optional break/test offset (in ticks or percent) means a level only counts as gained, lost, or tested once price clears it by your buffer.
PAIRED STRUCTURE
Levels come from trends and draws in colour-matched pairs from a 12-colour set, each pair originating from the same piece of structure.
Tested levels draw in a different line style from untested ones and can be hidden entirely; when hidden, you choose whether each pair still shows its tested partner so pairs stay intact. At high relevance settings, clustered tested levels within a tick distance thin down to the strongest one.
POLYBOUNDS
Experimental.
A corner readout that reduces the chart to the two prices that matter:
▲ hold above — the key gained level below price. Bulls are in control while price holds above it.
▼ hold below — the key lost level above price. Bears are in control while price holds below it.
Each line is coloured to match its pair on the chart, and the box only quotes levels that are actually drawn. A Trend Day row (1H and below) reads whether the session is shaping up bullish, bearish, or rangebound based on where price sits against the bounds.
SETTINGS
Levels above/below counts. A relevance dial controlling how deep into history levels are pulled from (50 bars to full history). Independent colours, styles, and widths for trends, containment trends, and levels. Configurable label background and twelve pair colours. A right-offset so all level rays align cleanly ahead of price.
HOW TO READ IT
The market is always in progression — always attempting either a new high or a new low. Every swing this indicator draws is one attempt in that sequence, and every level is the footprint it leaves behind.
Progression rule: in an uptrend, price should not lose the previous swing low if it intends to go higher — losing it shifts probability toward the opposite objective. Mirror logic in a downtrend. Watch the level states: a support flipping from SG to L is that shift happening in real time.
Containment is the early warning. A containment trend (lower high in an uptrend, higher low in a downtrend) means the progression is failing before any level has broken. Trend weakness is the warning; level failure is the confirmation.
Levels mark accepted value. They're built from candle bodies, not wicks — the goal is to see where the market accepted or rejected value, which is why the break/test offset exists to filter wick noise.
Untested levels react first. Fresh levels are the highest-priority reaction zones; tested levels remain valid structure and become targets when price is nearer to them. The pair colours show you which structure each level came from.
Timeframes nest. Higher-timeframe levels are destinations; lower-timeframe levels are the navigation between them. Significant trends typically start from higher-timeframe pivots — the biggest swings on your chart usually trace back to them. RTH-formed levels tend to carry the most weight.
Works on any symbol and timeframe; the Trend Day readout is built for intraday. This is a tool for reading structure, not a signal service — nothing replaces risk management.
リリースノート
Chart View update & titleリリースノート
Optimisation tweaksリリースノート
PolyBounds update, no longer a cosmetic and backtestedリリースノート
POLYTRENDS — MAJOR UPDATETRENDS
• New containment-free trend view: with "Enable Containment Trends" toggled OFF, the trend now draws as a clean alternating zigzag connecting only regular (valid) swings. Containment swings are fully absorbed — no gaps, no high-to-high lines — and the zigzag runs body-to-body so it sits on the exact same prices as your levels and highlights.
• In-progress (dashed) leg with containment off now only appears once price has actually made a new swing high or low. Containment-sized moves no longer preview a leg that may never form.
• Containment ON is unchanged — the full structure view with separate containment styling, exactly as before.
LEVELS & PAIRS
• Pair Trend Highlights (new): every displayed pair draws a translucent band along its connector swing, body level to body level, in that pair's own color. Toggle it in the Pair Colors section ("Highlight Pair Trends"); each band follows its "Pair N Color" setting.
• Level Origin Markers (new): a small pill sits on each level at the pivot that created it, matching the level's color. Markers and bands share the same opacity so they read as one element. Toggle in Levels.
• With containment trends off, containment levels are hidden and each valid level pairs with the nearest preceding valid level of the opposite type — pairs and bands always follow a real leg.
• Level Source (new): Body (recommended, original behavior) or Wick — the identical engine and states (SG/G/L/RL), with levels at the wick extremes instead, for comparison. Wick mode is not recommended for trading.
TESTED LEVELS — REBUILT
• Tested levels now draw ALONGSIDE your pair levels as standalone rays — they no longer replace or compete with the pairs.
• Own display counts: "Tested Levels Above" / "Tested Levels Below".
• Enforced spacing: no two tested levels within the separation distance. When several cluster together, only the most significant one (largest connector swing) is shown — nearest to price first.
• "Show Containment Tested Levels" (new): decides whether tested levels born from containment swings join the selection. One rule, any mode — works the same whether containment trends are shown or not.
• "Show Tested Pair Levels" now applies to pairs only: it shows/hides the tested companion inside a displayed pair.
RELEVANCE SIMPLIFIED
• The old 0–5 scale had duplicate tiers that displayed the same levels. It is now 1–3: 1 = Near (last 50 bars), 2 = Middle (last 600 bars), 3 = Distant (full history).
ACCURACY FIXES
• Higher-timeframe mode no longer uses lookahead data. Swing detection now runs on the just-closed HTF candle, so what you see on historical bars is exactly what you would have seen live. HTF pivots and levels appear one HTF bar later than before — that is the fix working, not a delay bug.
• Fixed a drawing bug that capped level-ray history at 300 bars regardless of the relevance setting.
リリースノート
POLYTRENDS — UPDATE: PAIRS REBUILT + STRUCTURE VIEW PERFECTEDPAIRING REDEFINED
• A pair now means one thing: a swing high level + the swing low level that follows it — the level that high produced on its way down. Every level belongs to exactly one pair. Highs resolve forward to their next low; lows resolve back to their high.
• This removes the old overlap where a level could sit in two neighboring pairs, which caused doubled highlights on a single move and stacked levels at swing points.
• Both members of a pair always share one color (keyed to the high member), and the pair's highlight band runs along that pair's own connector swing, body level to body level.
MISSING LEVELS FIXED
• Fixed a long-standing selection bug where pairs sharing a level with a neighboring pair could be silently suppressed — levels at obvious swings would not plot no matter how high Levels Above/Below was set. Both members of every displayed pair now always plot; a shared level is simply never drawn twice.
TESTED LEVELS JOIN THEIR PAIRS
• A displayed tested level now plots as part of its pair: pair color, dotted tested style (state still shown in the label), with its pair partner and connecting band drawn alongside.
• Selection is unchanged: nearest to price first, your Tested Levels Above/Below counts, minimum separation, and most-significant-wins when tested levels cluster.
CONTAINMENT OFF — ONE COHERENT STRUCTURE VIEW
• With containment trends off, the chart now shows one consistent containment-free structure: the trend draws as a clean alternating zigzag through true swing extremes (wick to wick), and levels, pairs, bands, and tested selection all derive from that same zigzag's nodes.
• A swing that was absorbed — containment, or a valid extreme replaced by a bigger one — has no level, no pair, no band. A level can never appear without a connector swing touching it, and one leg can never carry two highlight bands.
• Absorbed tested levels can still be surfaced with "Show Containment Tested Levels".
• The zigzag never skips a leg: same-candle legs draw when a pivot makes a genuine new extreme, and nonsense connections (low to lower low) are impossible.
• The in-progress (dashed) leg only appears once the developing move has actually made a new swing high or low.
LEVEL HIGHLIGHTS (NEW)
• Optional thin translucent band along each displayed level ray, in the level's color — the level line itself still draws underneath. Shares one opacity with the pair bands and origin markers so all highlights read in harmony. Toggle: "Highlight Levels" in the Levels section.
STABILITY
• Fixed a runtime error ("requested historical offset is beyond the historical buffer's limit") that could appear when drawings anchored to old pivots — most visibly in replay mode. The history buffer is now reserved explicitly and all drawing anchors are safely capped.
NOTES
• A freshly formed swing high plots without its pair partner until the following low is confirmed by the next pivot — the indicator's anti-repaint design, not a missing level.
• If levels seem missing above or below price, check Relevance: it bounds how far back levels are sourced (1 = last 50 bars, 2 = last 600, 3 = full history).
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。