You open a chart and start drawing lines. A horizontal at the obvious high, another at a low that looks important, a third because price seemed to turn there twice. Ten minutes later the chart is striped, and if a friend drew the same chart you would disagree on half the lines. The problem is not your eye. It is that "support and resistance" was never written down as a rule, so every line is a judgment call you cannot check later. This guide writes the rule down: what counts as a swing, how swings become a zone, how wide a zone is, and how many touches it needs. Then it shows the same rule done three ways, by hand, by PineScripter's chart agent while you watch, and by a Pine Script v6 indicator that draws it on every chart.
Short answer
Draw zones from confirmed swing points, not from candles that look important. A swing high is a bar whose high is not beaten by a set number of bars on each side (5 is a common choice). Group swings, highs and lows together, whose prices sit within half an ATR of each other, and draw each group as a box from its lowest to its highest swing, starting at its first swing and extending right. Label each box with how many swings built it. A zone with one swing is not a zone. The box describes where price turned in the past on the bars you loaded. It does not say price will turn there again.
Key facts
- A swing is only known after the bars on its right have closed. With 5 bars each side, a swing high is confirmed 5 bars after it prints.
- Swing highs and swing lows go into the same pool. A level where price turned down and later turned up is the classic flip zone, and it gets both touches.
- Zone width is measured in ATR, so the same rule works on BTCUSDT 1 minute and on a daily chart without retuning a price distance.
- Grouping by distance from the group's lowest swing keeps zones from chaining upward forever, which is what happens when each swing is compared only with its neighbour.
- The touch count is the number of confirmed swings inside the box. It is a count of past turns, not a strength rating and not a forecast.
- PineScripter's chart agent reads swings the same way (5 bars each side, swings within half an ATR(14) grouped, levels with one touch dropped) and draws zones as rectangles from the first touch, extended right.
- The Pine Script below redraws the zones on the last bar from confirmed swings only, so it never uses a bar that has not closed.
| Choice | Common setting | What changing it does |
|---|---|---|
| Bars on each side of a swing | 5 | Higher finds fewer, bigger swings and confirms them later |
| Zone width | 0.5 ATR | Wider merges more swings into fewer, thicker zones |
| Touches needed | 2 | Higher keeps only the levels price turned at repeatedly |
| How far back | All loaded bars, or a set window | Shorter keeps the chart about recent structure |
| Which price | Wicks (high and low) | Closes give tighter zones but miss the extremes |
Start from swings, not from candles that look important
Most hand-drawn levels start from a candle that caught the eye: a long wick, a big body, a gap. The trouble is that "caught the eye" changes with the zoom level and the mood. A swing point has a definition you can apply the same way every time. A swing high is a bar whose high is not exceeded by the bars on either side of it, and a swing low is the mirror image. The number of bars you require on each side is the only setting. Five is a common middle ground. Two finds every wobble. Twenty finds only the turns that mattered over a month of hourly bars.
The cost of the definition is time. You cannot know that today's high is a swing high until the next five bars have printed without beating it. Any tool that marks the swing on the bar it happened, on historical data, is quietly using bars it would not have had live. In Pine Script that is ta.pivothigh and ta.pivotlow with the same length on both sides, and both return their value on the confirming bar, not on the swing itself. The pivot high and low guide covers that delay in detail, and it is worth reading before you trust any zone tool, ours included.
Use the wick, not the close, for zones. Stops, limit orders and the moments where price was rejected all live at the extremes. A zone built from closes is tidier but it sits inside the area where price actually turned, and you will watch wicks poke through your clean box and wonder whether that counts.
A zone is a cluster, and its width is measured in ATR
Two swing highs at 75,208 and 75,304 on an hourly BTCUSDT chart are the same idea seen twice. Drawing two lines for them makes the chart busier without saying anything new. A zone groups them. The question is how close is close enough, and a fixed price distance is the wrong answer, because 100 dollars is nothing on a volatile day and a lot on a quiet one. Measure the distance in ATR instead. Half of a 14-bar ATR is a reasonable default: wide enough that equal highs merge, narrow enough that a level and the next one up stay separate.
There is a trap in how you group. If each new swing only has to be close to the previous one, a slow staircase of swings, each a little higher than the last, merges into one tall zone that spans a whole trend. The fix is to compare every swing with the lowest price already in the group. Sort the swings by price, start a group at the lowest, keep adding swings while they sit within one band of that starting price, and start a new group when one does not. Every zone is then at most one band tall, and two zones never overlap.
Put swing highs and swing lows in the same pool. A price where the market turned down in March and turned up in June is one level that played two roles, and it is exactly the kind of level people mean when they say a zone "flipped". Keeping the two sides apart would split it into two half-strength zones and hide the most interesting thing about it.
Count the touches, and know what the count means
Each zone carries a number: how many confirmed swings built it. One swing is a point, not a zone, so drop those. Two is the minimum for a level that price turned at more than once. Five or six on a few hundred bars is a level the chart kept coming back to. Write the number on the box, because a box without a count invites you to give it a weight it has not earned.
Be precise about what the count measures. It counts swings, and a swing needs the bars after it to fail to go further. A level that price sliced through ten times without turning has a count of zero, however many times it was crossed. A level touched three times inside the same short wobble gets three, which is arguably one event. None of that makes the count wrong. It makes it a description of past turns on the bars you loaded, and that is all it should be read as.
Then check it, because the count is where self-deception starts. Change the timeframe and see whether the zone still exists. Scroll back and see whether the touches are spread out or bunched in one week. Step through it bar by bar in replay and look at the moment each swing was confirmed, five bars after it printed, which is the moment the zone would actually have existed for you.
Ask the agent to draw it while you watch
On PineScripter's chart you can hand the whole job to the chart agent in one sentence: "Mark the swing highs and lows on BTCUSDT 4h and draw the levels they cluster into as zones, with the touch count on each." The agent first reads the chart. It gets the market, the timeframe, ATR, the swing points with 5 bars on each side, and the price levels those swings cluster into when they sit within half an ATR of each other, with how many touches each has and which were highs and which were lows. Levels with a single touch are dropped, and it is given the strongest few, most touches first.
Then it draws, and you see it happen. An AI cursor picks the rectangle tool in the drawing toolbar and clicks the two corners of each zone, from the first touch to the current bar, extended right, with a label that describes the level, such as "Zone, 4 touches". It does not invent prices: every corner comes from the swing levels it just computed. It does not write "buy here" or anything like it, and a label that reads as an instruction is replaced with a neutral one. If you do not like the result, the whole batch is undone with one click from the chat.
The useful part comes next. Say "now switch to the daily and draw the same zones", and it changes the timeframe, reads again and draws again, so you see which zones survive a higher timeframe and which were hourly noise. Ask it to remove the zones with only two touches. Ask it to recolour the ones above the last close. It edits its own drawings when you ask, and only touches yours if you tell it to. The agent works on PineScripter's chart, on crypto spot markets, not on your TradingView chart.
Turn the rule into an indicator that draws it on every chart
Once the rule is written down, it is a short script. The version below keeps every confirmed swing in two arrays, forgets swings older than a window you choose, and on the last bar sorts the swings by price and walks them from the bottom up, starting a new zone whenever the next swing is more than one band above the zone's lowest swing. Each zone with enough touches becomes a box from its earliest swing to the current bar, extended right, coloured by whether it sits above, below or around the last close, and labelled with its count.
//@version=6
indicator("Swing zones", overlay = true, max_boxes_count = 50)
swingLen = input.int(5, "Bars on each side of a swing", minval = 1)
bandAtr = input.float(0.5, "Zone width, in ATR", minval = 0.05, step = 0.05)
minTouch = input.int(2, "Swings needed to draw a zone", minval = 2)
memory = input.int(500, "Forget swings older than (bars)", minval = 50)
atr = ta.atr(14)
ph = ta.pivothigh(high, swingLen, swingLen)
pl = ta.pivotlow(low, swingLen, swingLen)
// Every confirmed swing, high or low, with the bar it happened on.
var array<float> swingPrice = array.new<float>()
var array<int> swingBar = array.new<int>()
if not na(ph)
swingPrice.push(ph)
swingBar.push(bar_index - swingLen)
if not na(pl)
swingPrice.push(pl)
swingBar.push(bar_index - swingLen)
while swingBar.size() > 0 and bar_index - swingBar.first() > memory
swingBar.shift()
swingPrice.shift()
var array<box> zones = array.new<box>()
if barstate.islast
for z in zones
z.delete()
zones.clear()
n = swingPrice.size()
if n > 0
// Walk the swings from the lowest price up. A zone keeps taking swings
// while they sit within one band of the zone's lowest swing.
idx = swingPrice.sort_indices(order.ascending)
band = bandAtr * atr
i = 0
while i < n
bottom = swingPrice.get(idx.get(i))
top = bottom
left = swingBar.get(idx.get(i))
j = i
while j + 1 < n and swingPrice.get(idx.get(j + 1)) - bottom <= band
j += 1
top := swingPrice.get(idx.get(j))
left := math.min(left, swingBar.get(idx.get(j)))
touches = j - i + 1
if touches >= minTouch and zones.size() < 40
tint = bottom > close ? color.red : top < close ? color.teal : color.gray
zones.push(box.new(left, top, bar_index, bottom, border_color = color.new(tint, 40), bgcolor = color.new(tint, 85), extend = extend.right, text = str.tostring(touches, "#") + " touches", text_size = size.small, text_color = color.new(tint, 20), text_halign = text.align_left))
i := j + 1Two choices in it are worth knowing. The zones are rebuilt on the last bar only, from swings that were already confirmed, so they describe the current state of the chart and never depend on a bar that has not closed. And the box starts at the zone's first swing, not at the bar where the zone first had two touches, which matches how the chart agent and most people draw zones. If you want to know when a zone first existed, that is the bar where its second swing was confirmed, five bars after the swing itself, and it is a one-line change to record it. The script stops at 40 zones so a long chart cannot crowd the screen, and the drawing objects guide covers what happens as a script nears TradingView's drawing limits.
Common mistakes, and how the rule avoids them
Drawing from the current bar backwards is the most common one. You look at where price is now, then hunt for history that agrees with a level nearby. The swing rule removes the hunt: the zones exist before you decide which one you care about. The second is letting zones grow. A box that is two ATR tall is not a level, it is a range, and the from-the-lowest-swing grouping keeps every zone to one band. The third is forgetting that old swings were made by a market that may not exist any more. Limit the memory, or at least look at the date of the first touch before you lean on a zone.
The last mistake is treating the touch count as a promise. A zone that held five times has a history of five turns. That history is worth knowing, and it is also exactly what a break of the zone looks like right before it happens. Read zones as a map of where price has reacted, check them on another timeframe and in replay, and keep any decision about what to do with that map outside the drawing.
Frequently asked questions
How many touches make a support or resistance zone?
At least two confirmed swings inside the zone. One swing is a single turn, not a level. More touches mean price turned there more often on the bars you loaded, which is a description of the past, not a measure of how likely it is to turn there again.
How wide should a support and resistance zone be?
Measure it in ATR rather than in price. Half of a 14-bar ATR is a sensible default: swings closer than that are grouped into one zone. Wider merges more swings into fewer zones, narrower splits them.
Should zones use wicks or closes?
Wicks, for most purposes. Swing highs and lows are defined on the high and the low, and that is where price was actually rejected. Zones built from closes are tighter but sit inside the area where price turned.
Can an AI draw support and resistance on my chart?
PineScripter's chart agent can draw them on PineScripter's chart, on crypto spot markets. It computes the swings and the levels they cluster into, then draws each zone with the rectangle tool while you watch its cursor, labels it with its touch count, and can undo the batch in one click. It does not draw on your TradingView chart, and it does not say what to trade.
Does the zone indicator repaint?
The zones are rebuilt on the last bar from confirmed swings only, so a zone never depends on a bar that has not closed. A new swing can add a new zone or join an existing one once it is confirmed, five bars after it prints, which is the honest delay of any swing-based level.
The practical takeaway
Write the zone down before you draw it. A swing is a high or low that the bars on both sides did not beat, known only after they closed. A zone is a group of swings within half an ATR of its lowest one, drawn from its first swing and extended right. Its number is how many swings built it, on the bars you loaded. Once the rule is that explicit, you can draw it by hand, have the agent draw it while you watch, or run it as a script, and all three will agree, which is the whole point of having a rule.
The chart agent, the drawing toolbar and the editor that turns the rule into a script all live in one chat in PineScripter. Ask the agent to mark the zones, check them on another timeframe and in replay, then ask for the indicator that draws them on every chart.
Sources
- Pine Script v6 reference: ta.pivothigh
- Pine Script v6 reference: ta.atr
- Pine Script v6 reference: box.new
- Pine Script v6 reference: array.sort_indices
Related reading: why swing points arrive late, ATR in Pine Script, boxes, lines and the drawing limit, liquidity sweeps of swing pools, bar replay.
Disclaimer: PineScripter is a coding tool for Pine Script development. It does not provide financial advice and does not guarantee trading profits. Always backtest strategies thoroughly and understand the risks before live trading.