Support & Resistance in Pine Script
Horizontal zones where price has reversed before and is expected to react again: support below, where demand stepped in, and resistance above, where supply did.
Definition
Support and resistance are horizontal price zones where a market has reversed before. Support is a zone below price where demand stopped a decline; resistance is a zone above price where supply stopped a rally. They belong to the horizontal-levels family, the oldest branch of technical analysis. Every other levels tool, from pivots to retracements, is a way of finding candidates for them. The classic level is drawn by hand from prior swing points; the library's tools supply objective versions from the previous day, from a formula and from prices you type.
The zones work because markets have memory. Traders who went long at a low remember it and defend it; traders who went short at a high, or were stopped there, go short there again; and those who missed the first reversal wait for a second chance at the same price. Resting orders gather at the level, which is why price slows there. When a level finally breaks, the traders on the wrong side exit into any return to it, and the level changes role: broken support becomes resistance and broken resistance becomes support.
There is no author and no standard setting, only conventions. A level is a zone, not a line, and its width scales with the timeframe and the market's volatility, often about a quarter to a half of an ATR. Levels from higher timeframes outrank levels from lower ones. The number of tests matters, but in two directions: a level that has held over months on widely spaced tests is well established, while a level being hit repeatedly within a few bars is being worn down and is likely to break.
On the chart expect price to slow, wick and often reverse at the first return to a level, and to behave differently on each visit. The first retest of a broken level from the other side is the classic role-reversal entry. A close through a level on volume with follow-through is a break; a wick through it with a close back inside is a sweep of the stops beyond it, which often marks the reversal. Levels do not disappear when broken; they change sides and stay on the chart until price has traded far away.
Reading the chart
Finding levels is a matter of marking where price turned, then keeping only the zones that still matter.
- Start on a higher timeframe than the one you trade. Daily levels for a 15-minute chart, weekly levels for a daily chart; the higher-timeframe zones frame everything below them.
- Mark the obvious reversal points: swing highs and lows where price turned sharply, the edges of consolidations, and the levels at which gaps opened or were filled.
- Turn each line into a zone. Include the wicks and the bodies of the reversal bars, and widen the zone in proportion to the market's volatility rather than drawing to the tick.
- Look for repeat visits. A level that turned price two or three times over a long period is confirmed; a level touched once is a candidate until price returns to it.
- Note broken levels and expect role reversal. Old resistance that price closed above is now support, and its first retest from above is the cleanest test of the new role.
- Add objective references. The previous day's high, low and close, the daily pivots and a round number that coincides with a drawn zone make it stronger, and the alert tool tells you when a typed price is reached.
The maths
Support and resistance have no formula of their own, but a zone can be defined around a swing point in units of volatility, and the library's implementations supply objective levels.
The previous day levels script draws yesterday's high, low and close and marks a long on a close above the high and a short on a close below the low; the pivot script draws the classic seven levels from the same three prices and marks crosses of the central pivot.
The price level alerts script draws up to three prices you type, with 0 switching a level off, and marks a long when the close crosses above any of them and a short when it crosses below; with no level set it uses yesterday's high and low, so the tool works before you type a number.
None of the scripts draw levels by hand. The zone width in the formula above is a convention for reading drawn levels; the implementations draw exact prices and leave the buffer to you.
Levels from a higher timeframe need a higher-timeframe request or a hand-typed price; both stay fixed on the lower chart until the higher-timeframe bar completes.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Level price | the swing point, or yesterday's high and low | Typing a price gives an exact line and an alert on the cross; the previous day and pivot tools supply the price automatically each session. |
| Zone width | 0.25 to 0.5 ATR | A wider zone catches more reactions and gives more room for stops; a narrower one gives tighter entries but more misses on sweeps. |
| Timeframe of the level | one step above the trading chart | Higher-timeframe levels are fewer and stronger; lower-timeframe levels are many and break easily, so keep only the ones that line up with something larger. |
| Break rule | close beyond the level | A close-based rule, which all three scripts use, ignores wicks and trades fewer, cleaner breaks; a touch-based rule catches sweeps but gives many false breaks. |
In practice
- As entries in a range: the range rule goes long on the retest of support with a stop beyond the zone and resistance as the target, short on the retest of resistance the same way, and stops when a close breaks either edge.
- As role-reversal entries: after a close through resistance, the rule waits for the first retest from above; a hold there is the entry, with the zone as the stop reference and the next level as the target.
- As alert lines: type the prices of the levels you care about and let the script mark the cross, so you watch the reaction rather than the screen.
- As stop placement: stops go beyond the zone, not on the line, because sweeps of the tick just past the level are common and the reversal often starts after them.
- As a session frame: the previous day's high, low and close and the daily pivots give an objective set of levels every morning, and the drawn levels that coincide with them come first.
- As targets: the next level in the direction of the trade is the natural target, and a trade with no level between entry and target has a clear path.
Where it goes wrong
- Drawing lines instead of zones. Price rarely stops on a tick; widen the level to include the reversal bars and place stops beyond the zone.
- Marking every wick. A chart with thirty lines has no levels; keep the reversals that are obvious from across the room and the objective daily references.
- Trading the first touch after a break. Stops fire and the move often reverses; wait for a close and a retest, or trade the failure of the break.
- Ignoring the timeframe. A 5-minute level means little against a daily level; note which timeframe each zone comes from and let the larger one win.
Compared with
Pivot Points. Pivots are computed every session from yesterday's prices by a formula and are identical for everyone; drawn support and resistance come from actual reversals and can be months old. Pivots are objective candidates, drawn levels are the confirmed memory.
Fibonacci Retracement. Retracement levels are fractions of a swing and can land where price never reversed; support and resistance are where it did. A retracement that lands on a prior reversal is a stronger zone than either alone.
Moving Average. A moving average is dynamic support or resistance that follows price every bar; a horizontal level is fixed to a past reversal. Trend traders lean on the average, range traders on the horizontal zones, and both watch where they meet.
Anchored VWAP. An anchored VWAP marks where the average money sits since an event, even where price never turned; horizontal support and resistance mark where price actually turned, whatever the volume was. The two are strongest in confluence, when the moving line meets a fixed zone.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
How many touches make a level valid?
Two clear reversals over a reasonable span make a level, and a third confirms it. But spacing matters more than the count: touches months apart show a level the market keeps respecting, while five touches in ten bars show a level being worn down by repeated tests and likely to break soon.
Why does broken support become resistance?
Because the traders who went long at the level are now under water. When price returns to it from below they exit at break-even, and traders who shorted the break add to their positions there. That combined supply is the new resistance. The mirror happens when resistance breaks and the shorts cover on the retest.
How wide should a zone be?
Wide enough to include the wicks and bodies of the reversal bars, which in practice is about a quarter to a half of the market's average true range on the timeframe of the level. Narrower zones miss reactions and get swept; wider ones lose precision. Scale it with the timeframe: a daily level is wider than a 5-minute one.
Which of the library's tools should I use for levels?
The previous day levels script for the freshest references, the pivot script for a formula set that many traders share, and the price level alerts script for levels you have drawn yourself: type up to three prices and it marks and alerts on each cross. With no price typed it falls back to yesterday's high and low.
How do I know a level has broken?
Ask for a close beyond it, preferably on above-average volume, and then for a retest from the other side that holds. A wick through the level with a close back inside is a sweep, not a break, and often precedes the reversal. The scripts all use closes for their marks for the same reason.
Do levels work on all timeframes?
Yes, but they rank. A weekly level outranks a daily one, which outranks an intraday one, and a lower-timeframe level that lines up with a higher one is the strongest of all. The levels of the timeframe above the execution timeframe carry the weight, and the smaller ones set entries and stops within them.