Adaptive S/R
Two layers of levels: slow structural ones that stay until price closes through them, and fast ones that mark a short-term break — with the structural layer filtering the fast one.
What it computes
Two sets of pivots with different lookbacks. The slow set, fifteen bars by default, becomes the macro levels: each confirmed swing high draws a resistance line, each swing low a support line, and the line stays until price closes through it. The fast set, five bars, becomes a single micro level above and below — drawn as a dotted trace — and a break is marked when price closes through one. A break is only marked when there is room to the next macro level, measured in ATR.
What it assumes
That a short-term break matters more when it has somewhere to go. A micro level taken out a few ticks below a macro resistance is unlikely to lead anywhere; the same break with two ATR of clear space above it is a different situation. That is the whole idea of the filter. What it does not claim: a break is not a prediction. It marks that a level was taken out, and leaves the rest to you.
Where it falls short
- Both layers appear late. A macro level is confirmed fifteen bars after the high, a micro level five. That delay cannot be removed — without it there is no way to know a high was a high.
- A break on a closing basis is a choice. Price can wick far through a level and close back inside, and the script will not call that a break. On some instruments that is right, on others it will feel slow.
- In a range the micro layer fires often and means little. The room filter removes some of it, but not all — a wide range leaves plenty of space between macro levels.
- Only four levels per side are kept. Older ones are dropped, so a level from weeks back will not be there. Raise the limit if you work with those, at the cost of a busier chart.
Backtest
There is none. The script marks structure and breaks; it gives no entry, stop or target, so there is nothing to measure. A rule built on it could be measured, and that would be a separate tool published with its results.
Settings
| Setting | What it does |
|---|---|
| Macro pivot lookback | How many bars must be lower on each side for a structural level. This is also the delay. |
| Max active levels per side | Older levels are dropped at this limit. |
| Micro pivot lookback | The same for the fast layer. |
| Require room to the next macro level | The filter. On by default. |
| Minimum room | How much space must be clear, measured in ATR. Lower it for more triggers, raise it for fewer. |
| Alerts | Micro breaks in both directions, and macro level breaks. |
Changelog
v2.0
The macro levels are now actually connected to the triggers. The listing described a macro filter combined with micro breakout triggers, but in the code the triggers referenced no macro level at all — the levels were drawn and reported in the panel while having no effect on a single signal. A trigger now requires room to the next macro level. Expect fewer signals; that is the point. "BUY" and "SELL" became "Break up" and "Break down", because what the script detects is a level being taken out, not a trade. Alerts were added — there were none, so the signals could not be used in an alert at all. Macro levels that price had already passed by the time the pivot confirmed are no longer created, a macro break is marked instead of the line silently vanishing, and the level labels sit at the right end of the line instead of drifting through the middle of the price action.
v1.0
First release.
How to get it
Open source and free on TradingView. Add it to your chart from the link below — no account needed here.
Open on TradingView