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.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.