OPEN-SOURCE SCRIPT
Atualizado

S&R + Trends | Polytrends Method (gracefultrading)

502
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.
Notas de Lançamento
Chart View update & title
Notas de Lançamento
Optimisation tweaks
Notas de Lançamento
PolyBounds update, no longer a cosmetic and backtested
Notas de Lançamento
POLYTRENDS — MAJOR UPDATE

TRENDS
• 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.

Aviso legal

As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.