OPEN-SOURCE SCRIPT
FVG IFVG SMT Sweep Engine by Ticker Trading

Fair value gaps, their inversions, and SMT divergence against a correlated symbol, built to one specification instead of to the conventions that circulate in open Pine scripts. Where the two disagree, this follows the specification, and every disagreement is listed below.
FAIR VALUE GAPS
A gap is the three-candle pattern: candle 1 and candle 3 fail to overlap, candle 2 spans the space between. The zone runs from candle 3's high to candle 1's low on a bearish gap, and the reverse on a bullish one. The boundary that matters later is candle 1's low, or its high on a bullish gap.
You define mitigation: a wick into the zone, a touch of the midline (consequent encroachment), or a close past the far edge. Mitigated gaps then fade, delete, or stay put. Bullish and bearish gaps live in separate buckets, so "keep the last 10" means ten of each, whatever order they printed in. Gaps can also be pulled from a higher timeframe onto a lower-timeframe chart, and mitigation is still judged on the chart's own closes.
INVERTED FVG
When price closes through a gap's boundary the gap flips polarity. A bearish gap becomes support; a bullish gap becomes resistance. A close, never a wick. That is the only structural filter here, and it is why a chart in a strong rally turns green: every bearish gap gets closed through and recolours. An IFVG dies when price closes back through it, or wicks back through, your choice.
SMT DIVERGENCE
This is where the script diverges most from what is already published. Most SMT scripts run ta.pivothigh() on both symbols and need the two pivots to confirm on the same bar. When they land a bar apart, which is often, nothing prints and nothing tells you a comparison was skipped.
This one asks whether each symbol took out its own reference level. Bar timing never has to line up. Four level sources are available and can run together:
prev: the previous candle's high or low. Highest frequency by a wide margin, and the first source to switch off if the chart gets busy.
rec: the extreme of the last N closed bars.
piv: the last confirmed swing pivot. The structural read, and behind by the right-bar count by construction.
sess: the session high or low, on a clock you pick.
Four filters sit on top.
Penetration and miss distance. The sweeper has to clear its level by a set number of ticks, and the partner has to fall short of its own by a set number. The second one does the real work. If the partner missed by half a tick, both instruments did the same thing, and calling that a divergence is a lie. Public scripts test the partner with a bare inequality.
Two-candle filter. When the sweep lands on the bar immediately after the bar that set the level, one candle of disagreement is not yet a narrative, so the divergence is marked pending. A later bar has to trade back to the sweep bar's extreme or the setup dies. A three-plus candle gap confirms on the spot. Pending divergences draw dotted and go solid the moment they confirm, so you can watch one build.
Both-swept neutralisation. If the partner takes out its own level too, inside a window you set, the divergence was never real and the marker is removed.
Stale-partner guard. request.security carries the last known value forward when the partner has no bar at a given timestamp. A carried-forward high can never exceed its own level, so the partner reads as "did not sweep" and a divergence gets invented out of a data hole. This compares the partner's bar time against the chart bar's and skips the bar when they disagree.
REPAINTING
Detection on bar close is the default, and nothing repaints. Reference levels advance on closed bars only, and each bar is tested against the level as it stood before that bar ran. History therefore shows what you would have seen live. Live intrabar detection is there if you want it, and it marks a sweep the moment a wick takes the level. Those markers can appear and vanish as bars reverse.
SETUP
Point the comparison input at the correlated partner and never at the chart symbol. MNQ against MES, NQ against ES, US100 against US500. Use a real-time feed. A delayed partner is stale on the newest bars, and every divergence there is fiction.
Five alerts: bullish FVG, bearish FVG, IFVG inversion, bullish SMT, bearish SMT.
Open source. The reasoning behind each rule is in the header comments.
FAIR VALUE GAPS
A gap is the three-candle pattern: candle 1 and candle 3 fail to overlap, candle 2 spans the space between. The zone runs from candle 3's high to candle 1's low on a bearish gap, and the reverse on a bullish one. The boundary that matters later is candle 1's low, or its high on a bullish gap.
You define mitigation: a wick into the zone, a touch of the midline (consequent encroachment), or a close past the far edge. Mitigated gaps then fade, delete, or stay put. Bullish and bearish gaps live in separate buckets, so "keep the last 10" means ten of each, whatever order they printed in. Gaps can also be pulled from a higher timeframe onto a lower-timeframe chart, and mitigation is still judged on the chart's own closes.
INVERTED FVG
When price closes through a gap's boundary the gap flips polarity. A bearish gap becomes support; a bullish gap becomes resistance. A close, never a wick. That is the only structural filter here, and it is why a chart in a strong rally turns green: every bearish gap gets closed through and recolours. An IFVG dies when price closes back through it, or wicks back through, your choice.
SMT DIVERGENCE
This is where the script diverges most from what is already published. Most SMT scripts run ta.pivothigh() on both symbols and need the two pivots to confirm on the same bar. When they land a bar apart, which is often, nothing prints and nothing tells you a comparison was skipped.
This one asks whether each symbol took out its own reference level. Bar timing never has to line up. Four level sources are available and can run together:
prev: the previous candle's high or low. Highest frequency by a wide margin, and the first source to switch off if the chart gets busy.
rec: the extreme of the last N closed bars.
piv: the last confirmed swing pivot. The structural read, and behind by the right-bar count by construction.
sess: the session high or low, on a clock you pick.
Four filters sit on top.
Penetration and miss distance. The sweeper has to clear its level by a set number of ticks, and the partner has to fall short of its own by a set number. The second one does the real work. If the partner missed by half a tick, both instruments did the same thing, and calling that a divergence is a lie. Public scripts test the partner with a bare inequality.
Two-candle filter. When the sweep lands on the bar immediately after the bar that set the level, one candle of disagreement is not yet a narrative, so the divergence is marked pending. A later bar has to trade back to the sweep bar's extreme or the setup dies. A three-plus candle gap confirms on the spot. Pending divergences draw dotted and go solid the moment they confirm, so you can watch one build.
Both-swept neutralisation. If the partner takes out its own level too, inside a window you set, the divergence was never real and the marker is removed.
Stale-partner guard. request.security carries the last known value forward when the partner has no bar at a given timestamp. A carried-forward high can never exceed its own level, so the partner reads as "did not sweep" and a divergence gets invented out of a data hole. This compares the partner's bar time against the chart bar's and skips the bar when they disagree.
REPAINTING
Detection on bar close is the default, and nothing repaints. Reference levels advance on closed bars only, and each bar is tested against the level as it stood before that bar ran. History therefore shows what you would have seen live. Live intrabar detection is there if you want it, and it marks a sweep the moment a wick takes the level. Those markers can appear and vanish as bars reverse.
SETUP
Point the comparison input at the correlated partner and never at the chart symbol. MNQ against MES, NQ against ES, US100 against US500. Use a real-time feed. A delayed partner is stale on the newest bars, and every divergence there is fiction.
Five alerts: bullish FVG, bearish FVG, IFVG inversion, bullish SMT, bearish SMT.
Open source. The reasoning behind each rule is in the header comments.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.