Pine Script v6 · TradingView · Trader's guide

Adaptive Mean + ATR Bands

A mean-reversion and reclaim engine that measures one thing: how far price has travelled from its own adaptive mean, priced in daily ATRs.

Build AM ATR v4.21-CL Basis 5DMA intraday · 20DMA daily+ Scale Daily ATR(20) Status Live, not backtested
01

Objective

New here? Start with the plain-English guide

This document is the design essay — why the tool works the way it does. For what you see and what to do, read the AM ATR User Guide (v4.23-CL). Its “Where everything is on the chart” section maps every idea below to the exact line, label or table row it appears as.

Overall

Price spends most of its life oscillating around a mean it drags behind it. This indicator defines that mean, measures the distance to it in units of daily range, and marks the two moments that distance becomes tradeable: when it has stretched far enough to snap back, and when it has closed back through the mean after a real pullback.

Short horizon

Fade the stretch

Price pushes past ±2 ATR from the basis and then closes back inside. The trade is the return — first target the ±1 band, then the basis itself.

Long term · swing / investor

Buy the reclaim

Price pulls away from the mean for days, then a daily close takes it back. That reclaim, once confirmed, opens a position held across sessions and managed down a three-step ladder.

Same engine, two speeds. The short-term trade fades extension. The long-term trade buys its resolution. They use the same basis and the same ATR scale, which is why one chart can carry both without contradiction.
02

The one number

Everything resolves to extension — the gap between price and the basis, divided by the daily ATR. It answers a single question: how many normal days of travel is price away from its mean right now?

+4 ATRExtreme — rarely holds to the close
+3 ATRExtended — chasing pays for someone else
+2 ATRStretched — the fade level
+1 ATRMoving with purpose
BASISThe adaptive mean
−1 ATRMoving with purpose
−2 ATRStretched — the fade level
−3 ATRExtended
−4 ATRExtreme
The ±N ATR labels on your chart mark these tiers and nothing else. They are not entries, not targets, and not tied to any trade. They print whether a position exists or not. Read them as a ruler, not a signal.
Only two band pairs are actually drawn. The scale above is the tier engine — it knows all four levels, and the State row and the tags both use them. The plotted lines are two selectable multiples, 1.0 and 2.0 by default. Four sets of lines buried price, so the rest of the ladder is measured but not painted.
03

Day trade or swing — which rules apply?

Two engines, opposite entries — one shared ruler

The two setups enter at opposite ends of the same measurement. Everything is priced in ext = (close − basis) / daily ATR. The fade enters roughly 2 ATR away from the mean; the reclaim enters at the mean. They cannot share entry criteria, and they do not.

They are also separate state machines — fadeDir and playDir — each with its own stop, targets and exits. Both can be open at once, which is why they carry different id series (F3 and #266).

What they do share is that neither has a day mode or a swing mode. The only time-based rule anywhere is entry-day protection on the reclaim: on day one, a confirmed close back through the basis kills it outright; from day two only the ladder, the stop or a daily close can end it.

FadeReclaim
Fires whenPrice was beyond ±2 ATR and has closed back insideA daily close flips sides of the basis, then holds next session
Entry sits~2 ATR from the mean — far outAt the mean — ext ≈ 0
You are bettingThe stretch is exhausted and price returnsThe return already happened and now continues
Direction of travelToward the basisAway from the basis

There is no VWAP fade

Extension is measured from the basis only. The session VWAP has its own extension reading and its own ±1 / ±2 alerts, but no trade is ever triggered from it — those crossings fire notifications and nothing else. If you want to fade a stretch from VWAP rather than from the mean, that setup does not exist in this indicator.

The trader still chooses which setup to take. Their characters differ beyond the entry:

Fade — short horizonReclaim — swing
Trigger Extension re-enters from beyond ±2 ATR Daily close reclaims the basis, then confirms next session
Label △ fade / ▽ fade ▲ LONG / ▼ SHORT
Holding Not enforced. Usually resolves same-session, but nothing in the code closes it — it runs until stop or basis, however long that takes. Days to weeks. playAge counts the sessions.
Targets T1 the ±1 band, T2 the basis. Both printed on the label. The 30 / 50 / 20 ladder in section 08.
Stop The extreme of the stretch, capped at 2 ATR. The bowl low, capped at 2 ATR.
Exits Stop, T1 (half at the 1 ATR band), T2 (remainder at the basis). All three print and alert. Stop, then the 30 / 50 / 20 ladder, plus the entry-day void.
Managed by the tool Yes, as of v4.19. Before that it was a label and nothing more. Yes. Ladder, void, stop and exits all print and alert.

Neither trade is time-bounded. Read this before calling either one a day trade.

Nothing in the code closes anything at the bell. There is no session flatten, no maximum age, and no reference to the day boundary in the fade engine at all. A fade ends exactly two ways — its stop, or the basis.

So "short horizon" describes how the fade usually resolves, not a rule the tool enforces. If price stalls between the stop and the mean, that fade is still open tomorrow, and next week. If you intend to trade either setup flat by the close, the flatten is yours to execute — and the indicator will keep printing labels and firing alerts for a position you no longer hold.

04

Where VWAP fits

Direct answer

The session VWAP and all eight anchored VWAPs are context and alerts only. Not one of them is an input to any entry or exit decision — there is no VWAP fade and no VWAP reclaim. Every trade rule in this document runs off the basis, the daily ATR, the bowl low and the prior session's extremes. Turning every VWAP off changes nothing about which trades fire.

They still earn their place — they just do it as reference levels you read, not as conditions the engine tests.

How to use them without confusing yourself. Take the trade off the basis rules. Use the VWAPs to decide whether it is worth taking — a reclaim long with the 2-Day, WTD and MTD stacked beneath it has room; the same signal pinned under all three is fighting every timeframe at once.
05

Timeframes

The signal is always daily. A session throughout this document means one trading day, never your chart interval. Your chart interval only decides how precisely the entry gets filled.

It is not fractal. The detector only ever asks the daily question. A 2-minute chart gives you daily reclaims filled with 2-minute precision — not 2-minute reclaims of 2-minute structure. If that is what you want, it needs a selectable signal timeframe, which the tool does not have.
06

Key components required

07

Everything on the chart

Every line, label and readout the indicator draws, what it gives you, and why it is there. Anything not listed here is not drawn by this script.

Layer 1 — the mean and its bands

Basis

Is: the adaptive mean — a true 5-day span intraday (days × measured bars/day), a 20-period MA on daily and above.
Gives: the reference every other number is measured from.
Why: a fixed bar count means something different on every timeframe. A day-span mean is the same real line on a 2m and a 30m, so signals do not change when you change chart.

Band pair A and B

Is: two selectable ATR multiples above and below the basis — 1.0 and 2.0 by default.
Gives: the visual price of the extension number.
Why: only two pairs are drawn, not four. Four sets of lines buried price; the tier engine still knows all four levels even though only two are plotted.

Band fill

Is: the tinted zone between the pairs.
Gives: at-a-glance depth without reading a number.
Why: context should sit behind price, not compete with it — hence the transparency control.

Armed-session tint

Is: faint green or red background over a session with a live play.
Gives: instant answer to "am I in something right now?"
Why: the entry label scrolls off; the tint does not.

Dotted grey line

Is: an armed break-confirm level — the prior session's high or low.
Gives: the exact price that turns a rejected reclaim into a trade.
Why: it replaced a text tag. One event, one mark: the level either breaks or expires quietly.

Layer 2 — moving averages

Trail / filter MA

Is: one state-coloured line, sized in minutes (510 by default) so it is the same real line on every intraday frame.
Gives: tranche 2 exits, and the MA-state filter that gates fades.
Why: it used to be two near-identical lines. Colour encodes state: price above and rising, below and rising, below and falling, above and falling.

MA30 ×3

Is: three MAs whose lengths are stated in 30-minute bars (7 / 17 / 33) and rescaled to your chart.
Gives: the same three real lines on a 5m as on a 30m.
Why: a 17-period MA means something different on every timeframe; a 510-minute MA does not.

Daily MAs

Is: 5 / 10 / 20 / 50 / 200 day averages, computed as rolling chart bars — not pulled from the daily timeframe.
Gives: the levels everyone else is watching, on your execution chart.
Why: a security-call daily MA steps once a day and repaints on the open. A rolling bar count updates continuously and never repaints.

MA cloud

Is: shading between price and a chosen MA.
Gives: whether price is working with or against that average.
Why: a filled region reads faster than two lines and a mental subtraction.

Layer 3 — the VWAP family (context only — never an entry condition)

Session VWAP + bands

Is: today's volume-weighted average with its own ATR bands. Intraday only, at or below 65 chart minutes.
Gives: the intraday companion to basis extension — the VWAP ext table row.
Why: for timing a fade entry inside the session. Hand-rolled on the same accumulator as every anchored line so the two cannot disagree about when a session starts.

2-Day

Is: a rolling window across yesterday and today, re-anchored on real session starts.
Gives: short-term fair value once the session VWAP has drifted.
Why: anchoring on session starts rather than "48 hours ago" is what makes it weekend- and holiday-safe.

WTD

Is: anchored at the week open.
Gives: the level a swing position is judged against.
Why: a reclaim long that cannot hold the week's average price is not working, whatever the entry label says.

MTD

Is: anchored at the month open.
Gives: the monthly accumulation level.
Why: where institutional cost basis for the month sits.

YTD

Is: anchored at the year open.
Gives: positional context for an investor timeframe.
Why: blank if the chart cannot load back to January 1 — it will not substitute the first visible bar and call it year-to-date.

YTD High

Is: VWAP measured from the highest high of the year. The anchor moves when a new high prints.
Gives: the average price paid by everyone who bought the top.
Why: that is the concept, not a repaint bug — the line means "VWAP since the high", and the high is not final until the year is.

YTD Low

Is: the mirror, re-anchoring on each new low.
Gives: the cost basis of buyers at the bottom.
Why: a common support reference on a recovering name.

Earnings, and prior earnings

Is: two alternating accumulators — one anchored at the last report, one at the report before it.
Gives: where this quarter's holders actually sit, and last quarter's.
Why: two are needed because a single anchored series resets on each report and can only ever show the most recent one.

Right-edge name tags

Is: the price of each line, at the right edge, in that line's own colour.
Gives: which line is which without hunting the legend.
Why: with several anchors on, colliding tags stagger apart rather than stack; the printed number is always the true value even where the label is nudged.

Layer 4 — trade labels (these, and only these, are trades)

#7 ▲ LONG / ▼ SHORT

Is: a confirmed swing entry, carrying its stop, its T1 band and the R that target pays.
Gives: everything needed to place the order.
Why: the number is the trade id — every later label for that trade repeats it.

◔ 30% · ◑ 50%

Is: tranche 1 and tranche 2 scale-outs, each with realised R.
Gives: the running record of what the trade has already paid.
Why: R is printed at the moment of the exit, not reconstructed later.

● EXIT

Is: the remainder closing on an opposite daily close through the basis.
Gives: the end of the swing trade.
Why: it states the true size it closes — 20%, 70% or 100% depending on which tranches paid.

✗ STOPPED

Is: a confirmed close beyond the stop.
Gives: the loss, in R.
Why: new in v4.19. Before that the stop was printed but never acted on.

✗ VOID

Is: entry-day invalidation — a close back through the basis before T1.
Gives: an early exit at the mean rather than at the stop.
Why: the premise was that the reclaim holds. It did not, and that is knowable before the stop is reached.

F3 △ FADE and its exits

Is: a fade entry with stop, T1 and T2, plus ◐ T1, ● T2 and ✗ STOP labels.
Gives: a fully managed mean-reversion trade — entry, stop and both targets tracked.
Why: F-numbers keep fades separate from swing trades, so two open positions never share a tag.

Grey ✗ tags

Is: a setup the filters rejected — too shallow, wrong slope, one-day flip, failed at the open, blocked by regime.
Gives: a record of what the filters cost you.
Why: off by default. Turn them on when you want to judge whether a filter is earning its place.

Layer 5 — information tags (never trades)

±N ATR band tags

Is: a mark the first time each ATR tier is reached in a session.
Gives: the bar at which the move became stretched.
Why: capped at one per tier per side per session and debounced by the same hysteresis the State row uses — price resting on a band used to print a tag on every wobble.

max N ATR

Is: a marker at the bar that made the session's furthest excursion, printed after the close.
Gives: an honest record of how much range each day actually paid.
Why: useful for judging whether your targets match what the symbol really delivers.

Layer 6 — the readout table

RowWhat it tells you
BasisWhich mean is active and how many chart bars it spans. Its tooltip shows measured bars/day and the session length that was detected.
D ATR(20)Daily ATR in price and as a percent of price — the scale everything else is quoted in.
5DMA extLive extension in ATRs. This ticks intrabar.
StateNORMAL / STRETCHED / EXTENDED / EXTREME, debounced and confirmed on close so it does not flicker.
VWAP extDistance from the session VWAP in ATRs. Intraday only.
DTR / ATRHow much of a normal day's range today has already used. Past 1.00 entry quality degrades — it warns, it does not block.
Day max extThe furthest price has got from the basis so far today.
P&R playLive trade state — direction, which tranches have paid, and open R. Reads PENDING confirm while a reclaim is armed but not yet confirmed.
Every label has a tooltip. Hover any of them for the levels, the anchor date, and the reasoning behind that specific mark. The on-chart legend at bottom-left decodes the symbols without leaving the chart.
08

Rules — entering

Path A — the reclaim

  1. Persistence

    Price has closed on the wrong side of the basis for at least 2 consecutive days. One-day flips are rejected.

  2. Depth

    While it was over there, the excursion reached at least 0.5 ATR past the basis. That deepest point is the bowl — and the bowl low is the stop.

  3. The cross

    A daily close takes price back across the basis, with the basis itself flat or sloping the right way. No buying the stern of a boat still sinking.

  4. Confirmation

    The signal arms silently and waits. It becomes a position only when the first completed chart bar of the next session holds the correct side of the basis. A session that gaps and fails at the open never prints an entry.

Path B — the break-confirm

  1. A reclaim was rejected

    The cross happened but a filter killed it — too shallow, wrong slope, a one-day flip, or it failed at the open.

  2. A level arms instead

    The prior session's high (longs) or low (shorts) becomes a tripwire, drawn as a dotted grey line.

  3. Structure proves the turn

    A confirmed close through that level within 3 sessions opens the trade anyway — the basis still has to be non-opposing at the trigger bar. Otherwise the level expires quietly.

Path C — the fade

  1. Stretch

    Extension pushed beyond ±2 ATR from the basis.

  2. Re-entry

    It closes back inside ±2. That bar is the trigger.

  3. Filters

    The MA state must agree (rounding the right way, or a timeframe break), and no fade is allowed against an armed reclaim play in the opposite direction.

09

Rules — exiting

For a reclaim or break-confirm trade: one entry, three scale-outs, and one condition that ends it before any of them.

30%Tranche 1

Off at the ±1 ATR band. Promotes to the ±2 band when the trade was born already beyond 1 ATR, so it does not book a target it has passed.

50%Tranche 2

Off on a confirmed close through the trail MA — and only once that trail has itself turned against the trade. A poke through a still-rising trail does not pay.

20%Remainder

The rest closes when a daily close crosses back through the basis against you. The market closing against the position is always the exit.

StopAny day

A confirmed close beyond the stop closes the trade, whatever size is left. Live from v4.19 — before that the stop was printed but never acted on.

VoidEntry day only

On day one, a confirmed close back through the basis beyond the tolerance kills the trade outright, before any tranche has paid. From day two it is a swing and the void no longer applies.

Void and stop are not the same thing. The stop is a price being wrong. The void is the premise being wrong — the reclaim you bought did not hold through its own first session — and it fires at the basis, usually well before the stop. It only exists on day one because after that the trade is a swing, and a swing that dips back through its mean has not been invalidated.
Every label of a trade carries its number. A swing entry prints #7, and so do that trade's ◔ 30%, ◑ 50%, void, stop and exit labels. Fades use their own series — F3 — so the two never collide. Same tag, same trade.

The fade — short horizon

50%T1

Off at the ±1 ATR band — the first place a stretched move typically pauses, and near enough to actually pay.

50%T2

Remainder at the basis. The mean is the entire thesis; reaching it closes the idea. There is no third target and no trail — a fade is not held for trend.

StopThesis dead

A confirmed close back through the extreme of the stretch. The fade says the move is exhausted; a new extreme says it is not.

10

Where every stop and target comes from

No level here is an arbitrary multiple. Each one is the price at which a specific claim stops being true — which is also why each one is different for the two trades.

LevelWhere it sitsWhy there
Swing stopThe bowl extreme — deepest point of the pullbackThe trade says that low held and buyers reclaimed the mean. Price back below it says they did not. It is the last price at which the setup was still intact.
Swing T1The next whole ATR band beyond entryOne ATR of travel is a normal day's move. Taking 30% there books a real gain on the leg you were actually paid for, without calling the top.
Swing T2A confirmed close through the trail, once the trail has turnedNot a price — a condition. It asks whether the trend that carried you is still carrying you. Requiring the trail to have turned stops a single poke from paying.
Swing runnerOpposite daily close through the basisThe mean is the thesis. The market closing on the far side of it, on the timeframe that generated the signal, ends the idea.
VoidThe basis, day one only, before T1Premise failure, not price failure. A reclaim that cannot hold through its first session was never confirmed in substance.
Fade stopThe extreme of the stretch beyond ±2 ATRThe fade claims the move is exhausted. A new extreme past that point is the market saying it is not. Mirror image of the bowl.
Fade T1The ±1 ATR bandWhere a stretched move typically first pauses — close enough to reach inside the session, far enough to pay for the risk.
Fade T2The basis"Reversion" means reaching the mean. Arriving there is the trade completing, not a trailing decision.
Both stopsCapped at Max stop distance, default 2 ATRStructural stops vary wildly in width. The cap bounds risk per trade so position sizing stays comparable across setups.
The pattern: every stop is the extreme that the setup said would hold, and every target is either a band the move is likely to reach or the mean the whole idea is built on. Nothing is a round number and nothing is optimised.
11

Risk and position sizing

The indicator does not size anything

It reports risk in points and results in R. It does not know your account, does not cap risk per trade, and will never refuse a trade because it is too large. Sizing is entirely yours.

The discipline that matters most here: the stop is a structural level, not a fixed ATR multiple. The bowl low can sit 0.6 ATR below entry on one setup and 1.8 ATR below on the next. Sizing a fixed number of shares across both is how this tool hurts people.

Max stop distance puts a ceiling on that spread. Set to 2 ATR by default, it leaves a tight structural stop alone and pulls in anything wider, so no single trade can quietly ask for four times the risk of the last one. It is a risk cap, not a better stop — if the structure genuinely needed the room, the trade is now stopping earlier than the setup implies.

StepWhat to do
1 · RiskRead stop off the entry label. Risk per share = entry − stop (longs).
2 · BudgetDecide the dollar loss you accept on this trade. A fixed percent of account is the usual discipline.
3 · SizeShares = risk budget ÷ risk per share. A wider bowl means a smaller position, always.
4 · SanityCheck the R on the label. If T1 pays less than about 1R, the setup is not worth the risk it is asking for.
5 · RangeCheck DTR / ATR in the table. Past 1.00 the day has already spent its range — size down or skip.
The ladder blends your R. Taking 30% at T1, 50% at T2 and 20% at the exit means realized R is a weighted average, not the number on any single label. A trade that shows +2.7R at the final exit did not return 2.7R on the whole position.
12

Settings that actually matter

Most inputs are cosmetic. Five change which trades exist. Move these one at a time and watch the trade count.

SettingDefaultWhat moving it does
Reclaim depth0.5 ATRHow deep the pullback must be. Raise for fewer, better setups; lower for more, shallower ones. Do not set it to 0 — the depth test then passes with no pullback at all, and the stop can go undefined.
Min days on side2Persistence before a reclaim can arm. Raise to kill flip-flops in chop; drop to 1 to catch faster turns and accept the noise.
Void tolerance0.10 ATRHow far a day-one close must go back through the basis to kill the trade. Raise to survive a messy open; lower to cut failures faster.
Break-confirmon, 3 sessionsThe second entry path. Turn it off and you only take clean reclaims — materially fewer trades. Widen the window for more.
Trail span510 minSets tranche 2. Shorter takes the 50% sooner and more often; longer holds through more noise. Stated in minutes so it is the same real line on any intraday chart.
Max stop distance2.0 ATRHard ceiling on risk per trade. The structural stop is used as-is when it is closer than this; when the pullback was wider, the stop is pulled in to exactly this distance. Raise it to let structure breathe, lower it to standardise risk across setups.
Leave these alone unless you know why. Confirmed ATR (on) is what stops the bands repainting. Slope gate (on) is what stops you buying into a falling mean. Regime gate (on) is what stops you fading against your own open position.
13

Failure modes — when this is wrong

Kills the fade

A trending market

Price rides ±2 to ±4 ATR for days and every fade gets run over. The tell is the band tags: +2, +3, +4 printing in sequence with no return. The regime gate only protects you when a reclaim play is already armed — it will not save an unrelated fade.

Kills the reclaim

A tight range

Price crosses the basis every other day. The 2-day persistence filter catches the worst of it, but a two-day chop still qualifies and you get whipsawed with a shallow bowl and a tight stop.

Both

Earnings and gaps

There is no earnings blackout. A gap straight through the basis can arm, confirm and void inside one session — and a gap through your stop on day two or later is not protected by the void rule at all.

Both

Thin liquidity

Every level is a close. If the spread is wide or the symbol is illiquid, the R printed on the label is not the R you will get. The tool assumes you trade the print.

The edge is in what it refuses. Shallow reclaims, one-day flip-flops, reclaims into a mean still moving against you, fades in the wrong regime — all filtered out. Most of this indicator is a list of trades it declines to take. If you override the filters, you are trading something else.
14

Known gaps

Fixed in v4.18 and v4.19

Fixed

T1 now promotes past price

The first target is the next whole band beyond where price already sits, capped at 4. It can no longer be behind the entry, and the negative R at fill is gone.

Fixed

Risk per trade is capped

Every entry passes its stop through one check that replaces it if it is missing or on the wrong side of the fill, and pulls it in when it sits further than Max stop distance (default 2 ATR). One variable is now the stop everywhere — label, tooltip and webhook cannot disagree.

Fixed

Label text is legible

Text colour is computed from the background's luminance, so the yellow and orange tier tags get dark text.

Fixed

Trades are numbered

Entry, both tranches, the void and the exit all carry the same #N. Same number, same trade — and trade_no is in the webhook payload.

Fixed

The stop now exits

Until v4.19 the stop was printed and used as the R denominator but no code acted on it — a trade could run straight through its own stop and keep being managed. A confirmed close beyond it now closes the position.

Fixed

The fade is a managed trade

Stop at the extreme of the stretch, half off at the 1 ATR band, remainder at the basis — with labels and alerts for all three, and its own F-series id.

Fixed

Band tags fire once per tier

They fired on the raw crossing, so price resting on a band printed a tag on every wobble — four "+2 ATR" labels on one consolidation. Now debounced and capped at one per tier per side per session.

Fixed

The payload specifies both trades

Trade id, side, entry price and time, stop with the reason it was chosen, risk, and every target as an absolute price with its size.

Still open

Missing

No VWAP-based setup

Extension is measured from the basis only. The session VWAP has an extension reading and alerts but triggers no trade — a fade of a stretch from VWAP does not exist here.

Missing

Nothing is time-bounded

No session flatten, no maximum age, no day-boundary logic in the fade engine at all. A fade sitting between its stop and the basis is still open next week. Calling either setup a day trade is a description of intent, not of behaviour.

Scope

Not fractal

Daily signal only, whatever chart you run it on.

Scope

The range gauge warns, it does not block

Past 1.00 DTR/ATR the table turns red, but nothing stops an entry.

Scope

No backtest stands behind it

Every rule here is reasoned, none is measured. The forward test is the test.

Read this before trading it

This is a measurement and signalling tool, not a strategy with verified expectancy. It marks conditions; it does not size, manage risk, or account for slippage, commissions or gaps. Every rule in this document is reasoned from how the code behaves — none of it has been measured against results.

↑ Contents