OPEN-SOURCE SCRIPT
מעודכן Sweep IFVG (M1D)

Sweep IFVG
Marks one sequence and refuses to mark anything else.
Liquidity is taken, a fair value gap opens away from it, and that gap then fails and inverts.
Each stage has to happen in order and inside a window you set, or the zone is never drawn.
Most gap indicators draw every imbalance on the chart and let you sort out which ones matter. This one starts from the liquidity event and works forward, so a gap that opened without a raid in front of it is not a candidate and never appears. What survives to the chart is a small number of zones with a reason behind each one.
The sweep
A swing is the three-candle structure; one candle each side of the middle one, the middle holding the high or the low. That is the default, and it can be widened when you want only larger structure tracked. A sweep is that level being wicked through and rejected on the same candle: price trades beyond the swing extreme and the candle closes back inside it. A raided high is a buyside sweep, a raided low is a sellside sweep.
Each sweep is marked with a small arrow set clear of the bar — above a swept high, below a swept low — and the level that was taken is drawn as a solid line back to the candle that formed it, so the origin of the raid stays visible rather than being implied.
Sweeps are capped at a number you choose. Past it, the oldest arrow and its level line are removed together, so a sweep never half-disappears.
The candidate gap
A sweep stays live for a set number of bars afterwards. Only inside that window can a fair value gap be adopted as its displacement, which is what stops an unrelated gap forty bars later being attributed to a raid it had nothing to do with.
The displacement itself is read over three candles and has to clear a minimum size in ticks to count. It must also run the same way as the reaction the sweep implies: a raided low can only qualify a bullish leg, a raided high only a bearish one. Two things qualify — a fair value gap, and a suspension block — and the section below covers how they differ.
A qualifying gap is drawn as a dashed box named BISI or SIBI. That is a candidate — a gap on watch, nothing more.
Volume imbalance and suspension blocks
A fair value gap is measured wick to wick, and on a fast leg that understates the region. Where the candle bodies also gap but the wicks still bridge the space, there is a volume imbalance sitting on the seam, and it is part of the same imbalance rather than a separate object. The zone absorbs it: the edge extends from the wick out to the body it should have reached. Each gap has two seams, one either side of the displacement candle, and each is tested on its own.
A suspension block is what happens when both joins gap at once. Three candles run the same way and each one opens beyond the previous one's close, so the bodies never trade back through the leg at any point in it. The zone is then the whole suspended span, from the first candle's close to the last candle's open, and it is named SB+ or SB- rather than BISI or SIBI.
It qualifies on its own terms and does not need a fair value gap to be present. A leg can be stacked tightly enough that every wick overlaps the one before it — no wick gap anywhere — while the bodies still never trade back. That is the case a wick-measured gap cannot see at all. Where a wick gap is present as well, the block's span is drawn instead, and it always contains the gap it replaces: the first candle's close sits at or below that gap's high, and the last candle's open at or above its low.
A block goes on to fail and invert on exactly the same terms as any other candidate. The resolved edges — absorbed or suspended — are what the midpoint line, the overlap rule and the failure test are all measured against.
One exclusion is built in. A body gap across a session or weekend break is a calendar artefact rather than displacement, so a join spanning more than one bar's worth of time is rejected. Without it a daily session break would manufacture a block every day. The rule applies to blocks, which is where that would happen.
Absorption and block detection each have their own switch. With both off, every zone is the plain wick-to-wick gap.
The inversion
A candidate has a limited number of bars to fail. Failure means a candle body closing clean through the gap, not a wick into it: a wick is a probe, and probes are not delivery.
When that close happens the box turns solid, changes colour, and is renamed IFVG+ or IFVG-. The names describe how the gap was built and which way it now trades — a bullish gap that gets closed through becomes a bearish inversion. Both directions share one confirmed colour, because at that point the useful distinction is confirmed against candidate, and direction is already stated in the name.
A candidate that never fails inside its window is deleted rather than left on the chart. Nothing that did not complete the sequence stays drawn.
Consequent encroachment
Each zone can carry its midpoint — the consequent encroachment of that gap, which is a different object from the equilibrium of a range. It is off by default and has its own colour, width and line style.
Zone names sit beside the box, on its centre line, just past the right edge. The midpoint line stops at that edge and the text starts there, so neither ever crosses the other, and a name stays readable when the zone it belongs to is only a few pixels tall.
Keeping the chart readable
Four limits, all yours to set. Candidates are capped per side and confirmed inversions are capped per side, oldest dropped first. A new zone can optionally be refused when it overlaps one already on the chart, which is what stops a run of gaps stacking into a single unreadable block on a fast leg.
The fourth is distance. A zone left hanging far from the candles forces the price scale to keep reaching for it, so the candles end up squashed into part of the pane and the whole thing rescales every time you touch the chart. Confirmed zones past a set distance are dropped, measured from the nearer edge of the zone to the current close and expressed in chart-timeframe ATR so it carries across instruments and timeframes. A zone price is trading inside reads as near zero and can never be dropped from under the candles.
Candidates are never dropped this way — one has to stay in play to be able to invert at all — and they expire on their own grace window regardless.
Colours, border width, label text, label size and every name string are settings, including the words BISI, SIBI, SB+, SB-, IFVG+ and IFVG- themselves.
Alerts
Four. Buyside sweep, sellside sweep, bullish IFVG confirmed, bearish IFVG confirmed. The two sweep alerts fire on the raid itself; the two inversion alerts fire on the close that completes the failure.
Method & repainting
Everything is read from the chart timeframe. There are no higher-timeframe requests anywhere in the script, so there is no lookahead to get wrong and no future data to leak.
Every detection is gated to a confirmed bar close. A sweep, a gap and an inversion are all judged on closed candles, so nothing appears mid-bar and then withdraws.
One characteristic is worth stating plainly, because it is inherent to pivots rather than a fault: a swing is only confirmed once the bars to its right have printed. On the three-candle default that is one bar, and a sweep can only be measured against a swing that has been confirmed. Widening the swing setting widens that delay by the same amount. It is lag, not repainting — the marks do not move once drawn.
Zones and midpoint lines extend rightward to the current bar while they are live. That is the boxes tracking the present, not their history changing.
What it will not do
It places no entries, exits, stops or targets, and it does not size a position. It draws no trend, no bias and no target projection.
It does not read structure beyond the pivots it uses to find swings, and it does not label market phases. Whether a completed inversion is worth trading is a judgement about context this script does not have — session, higher-timeframe draw, and what the day has already done.
A sweep alone draws nothing but its arrow and its level. Displacement alone, with no raid in front of it, draws nothing at all. Only the finished sequence produces a zone, so an empty chart in a range is the tool working, not failing.
Settings
Swing lookback, sweep validity window, sweep markers and their size, the swept-level line and its width, and the cap on sweeps shown; minimum gap size, volume imbalance absorption, suspension block detection, inversion grace window, the per-side caps on candidates and confirmed inversions, the overlap rule and the distance gate with its ATR multiple; candidate and confirmed colours, sweep colour and zone border width; the midpoint line with its colour, width and style; and zone labels with their six name strings, size and text colour.
Disclaimer
This is a decision-support tool for discretionary ICT trading. It is not financial advice, and no market's past behaviour is indicative of future results. It draws where a level failed, a candidate imbalance and leaves the decision to you.
Marks one sequence and refuses to mark anything else.
Liquidity is taken, a fair value gap opens away from it, and that gap then fails and inverts.
Each stage has to happen in order and inside a window you set, or the zone is never drawn.
Most gap indicators draw every imbalance on the chart and let you sort out which ones matter. This one starts from the liquidity event and works forward, so a gap that opened without a raid in front of it is not a candidate and never appears. What survives to the chart is a small number of zones with a reason behind each one.
The sweep
A swing is the three-candle structure; one candle each side of the middle one, the middle holding the high or the low. That is the default, and it can be widened when you want only larger structure tracked. A sweep is that level being wicked through and rejected on the same candle: price trades beyond the swing extreme and the candle closes back inside it. A raided high is a buyside sweep, a raided low is a sellside sweep.
Each sweep is marked with a small arrow set clear of the bar — above a swept high, below a swept low — and the level that was taken is drawn as a solid line back to the candle that formed it, so the origin of the raid stays visible rather than being implied.
Sweeps are capped at a number you choose. Past it, the oldest arrow and its level line are removed together, so a sweep never half-disappears.
The candidate gap
A sweep stays live for a set number of bars afterwards. Only inside that window can a fair value gap be adopted as its displacement, which is what stops an unrelated gap forty bars later being attributed to a raid it had nothing to do with.
The displacement itself is read over three candles and has to clear a minimum size in ticks to count. It must also run the same way as the reaction the sweep implies: a raided low can only qualify a bullish leg, a raided high only a bearish one. Two things qualify — a fair value gap, and a suspension block — and the section below covers how they differ.
A qualifying gap is drawn as a dashed box named BISI or SIBI. That is a candidate — a gap on watch, nothing more.
Volume imbalance and suspension blocks
A fair value gap is measured wick to wick, and on a fast leg that understates the region. Where the candle bodies also gap but the wicks still bridge the space, there is a volume imbalance sitting on the seam, and it is part of the same imbalance rather than a separate object. The zone absorbs it: the edge extends from the wick out to the body it should have reached. Each gap has two seams, one either side of the displacement candle, and each is tested on its own.
A suspension block is what happens when both joins gap at once. Three candles run the same way and each one opens beyond the previous one's close, so the bodies never trade back through the leg at any point in it. The zone is then the whole suspended span, from the first candle's close to the last candle's open, and it is named SB+ or SB- rather than BISI or SIBI.
It qualifies on its own terms and does not need a fair value gap to be present. A leg can be stacked tightly enough that every wick overlaps the one before it — no wick gap anywhere — while the bodies still never trade back. That is the case a wick-measured gap cannot see at all. Where a wick gap is present as well, the block's span is drawn instead, and it always contains the gap it replaces: the first candle's close sits at or below that gap's high, and the last candle's open at or above its low.
A block goes on to fail and invert on exactly the same terms as any other candidate. The resolved edges — absorbed or suspended — are what the midpoint line, the overlap rule and the failure test are all measured against.
One exclusion is built in. A body gap across a session or weekend break is a calendar artefact rather than displacement, so a join spanning more than one bar's worth of time is rejected. Without it a daily session break would manufacture a block every day. The rule applies to blocks, which is where that would happen.
Absorption and block detection each have their own switch. With both off, every zone is the plain wick-to-wick gap.
The inversion
A candidate has a limited number of bars to fail. Failure means a candle body closing clean through the gap, not a wick into it: a wick is a probe, and probes are not delivery.
When that close happens the box turns solid, changes colour, and is renamed IFVG+ or IFVG-. The names describe how the gap was built and which way it now trades — a bullish gap that gets closed through becomes a bearish inversion. Both directions share one confirmed colour, because at that point the useful distinction is confirmed against candidate, and direction is already stated in the name.
A candidate that never fails inside its window is deleted rather than left on the chart. Nothing that did not complete the sequence stays drawn.
Consequent encroachment
Each zone can carry its midpoint — the consequent encroachment of that gap, which is a different object from the equilibrium of a range. It is off by default and has its own colour, width and line style.
Zone names sit beside the box, on its centre line, just past the right edge. The midpoint line stops at that edge and the text starts there, so neither ever crosses the other, and a name stays readable when the zone it belongs to is only a few pixels tall.
Keeping the chart readable
Four limits, all yours to set. Candidates are capped per side and confirmed inversions are capped per side, oldest dropped first. A new zone can optionally be refused when it overlaps one already on the chart, which is what stops a run of gaps stacking into a single unreadable block on a fast leg.
The fourth is distance. A zone left hanging far from the candles forces the price scale to keep reaching for it, so the candles end up squashed into part of the pane and the whole thing rescales every time you touch the chart. Confirmed zones past a set distance are dropped, measured from the nearer edge of the zone to the current close and expressed in chart-timeframe ATR so it carries across instruments and timeframes. A zone price is trading inside reads as near zero and can never be dropped from under the candles.
Candidates are never dropped this way — one has to stay in play to be able to invert at all — and they expire on their own grace window regardless.
Colours, border width, label text, label size and every name string are settings, including the words BISI, SIBI, SB+, SB-, IFVG+ and IFVG- themselves.
Alerts
Four. Buyside sweep, sellside sweep, bullish IFVG confirmed, bearish IFVG confirmed. The two sweep alerts fire on the raid itself; the two inversion alerts fire on the close that completes the failure.
Method & repainting
Everything is read from the chart timeframe. There are no higher-timeframe requests anywhere in the script, so there is no lookahead to get wrong and no future data to leak.
Every detection is gated to a confirmed bar close. A sweep, a gap and an inversion are all judged on closed candles, so nothing appears mid-bar and then withdraws.
One characteristic is worth stating plainly, because it is inherent to pivots rather than a fault: a swing is only confirmed once the bars to its right have printed. On the three-candle default that is one bar, and a sweep can only be measured against a swing that has been confirmed. Widening the swing setting widens that delay by the same amount. It is lag, not repainting — the marks do not move once drawn.
Zones and midpoint lines extend rightward to the current bar while they are live. That is the boxes tracking the present, not their history changing.
What it will not do
It places no entries, exits, stops or targets, and it does not size a position. It draws no trend, no bias and no target projection.
It does not read structure beyond the pivots it uses to find swings, and it does not label market phases. Whether a completed inversion is worth trading is a judgement about context this script does not have — session, higher-timeframe draw, and what the day has already done.
A sweep alone draws nothing but its arrow and its level. Displacement alone, with no raid in front of it, draws nothing at all. Only the finished sequence produces a zone, so an empty chart in a range is the tool working, not failing.
Settings
Swing lookback, sweep validity window, sweep markers and their size, the swept-level line and its width, and the cap on sweeps shown; minimum gap size, volume imbalance absorption, suspension block detection, inversion grace window, the per-side caps on candidates and confirmed inversions, the overlap rule and the distance gate with its ATR multiple; candidate and confirmed colours, sweep colour and zone border width; the midpoint line with its colour, width and style; and zone labels with their six name strings, size and text colour.
Disclaimer
This is a decision-support tool for discretionary ICT trading. It is not financial advice, and no market's past behaviour is indicative of future results. It draws where a level failed, a candidate imbalance and leaves the decision to you.
הערות שחרור
Fixed a crash that could stop the script mid-session. A sweep line starts at the swing that was raided, which can sit thousands of chart bars back. Placing that anchor on the chart walks back through bar history, and the buffer Pine sizes for it is set from what past bars happened to need, so the first live bar that needed one bar more stopped the whole script with "requested historical offset is beyond the historical buffer's limit". The buffer is now set explicitly, and an anchor older than the chart can reach draws from the oldest reachable bar instead of failing. Nothing changes in what is detected or how it is drawn.
A sweep must take the extreme of a leg, not a turn inside it. The three-candle swing is still the shape, but a swing now only counts as liquidity when it is the highest high (lowest low) of the bars leading into it - new setting, Swing Must Be the Extreme of, default 20 bars. Every three-candle pullback inside a run was a swing before, and the next wick through it was a sweep; stops do not rest behind those. Set it to 0 for the old behaviour.
Defaults set to the cleaner load. Swing lookback 3, the swing must be the extreme of 50 bars, sweep validity window 50, minimum gap 30 ticks, two confirmed IFVGs per side, the CE line on, and the far-zone drop and overlap skip both off. These are the settings the script was being run with anyway - existing charts keep whatever they have set.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.