OPEN-SOURCE SCRIPT

OSF

2 235
OSF — Fractal Sweep / CISD Model
Overview

OSF is an overlay indicator that tracks a four-candle higher-timeframe (HTF) sequence and reports its progress on a lower-timeframe (LTF) chart. It draws a compact HTF candle preview to the right of price, marks the point where an HTF candle sweeps the prior candle's extreme and closes back inside it, locates the LTF order-block open that price must reclaim (CISD), and then follows the setup through two further HTF candles to record whether it stayed intact or was invalidated.

Everything the script draws comes from one place: the relationship between consecutive HTF candles and the LTF bars that build them. Nothing is smoothed, averaged, or derived from a conventional oscillator.

What the model is

The script names four consecutive HTF candles:

C1 — the reference candle whose high and low become the levels to be swept.
C2 — the sweep candle. A bullish C2 trades below C1's low and closes back above it. A bearish C2 trades above C1's high and closes back below it. The C2 extreme (its low for bullish, its high for bearish) becomes the invalidation level for the whole setup.
C3 — the confirmation window. This is where price is expected to hold above (bullish) or below (bearish) the C2 extreme, and where the CISD reclaim is normally expected.
C4 — the outcome window. If price has still not breached the C2 extreme by the end of C4, the setup is recorded as "C4 intact."

A breach of the C2 extreme at any point kills the setup. The script distinguishes a breach that happens during C3 from one that happens during C4, because they are different failure modes, and labels the C2 marker XC2 accordingly (red before C4, orange after).

CISD

CISD (Change In State of Delivery) is calculated on the chart timeframe, not on the HTF. When the chart makes a new period low that also runs below the prior period's low, the script walks back up to ten bars to find the relevant swing open — the open of the last up-candle before the down-sequence that produced the low, adjusted upward if a later down-candle opens higher. That open price is the CISD level. The bearish case is the mirror image.

Two states are shown:

Early CISD — price closes back through the level before the HTF model has confirmed. Drawn as its own line and label so you can see the reclaim as it happens. Optional, and controlled separately from the alert for it.
Confirmed CISD — the same reclaim, but attached to a live C2 setup. Confirmed CISD is what "reveals" a setup: by default the C2 label, sweep line, and T-Spot zones are only drawn once CISD confirms, so the chart is not cluttered with unconfirmed sweeps.

If CISD only ever confirms after the model has already moved into C4, and C4 is then invalidated, the entire setup — including that CISD confirmation — is removed retroactively rather than left on the chart as a signal that never mattered.

Drawings
HTF candle preview — up to ten synthetic HTF candles rendered to the right of the last chart bar, with configurable body, border, and wick colors, an offset control, and a live-updating current candle.
HTF open line, period boundary lines, live high/low lines — optional reference lines tied to the HTF period.
Candle equilibrium — the 50% level of each HTF candle, plus the reference dash used by the T-Spot zone.
T-Spot box — the zone between the current HTF candle open and the previous HTF candle's equilibrium, drawn for C3 and again for C4. This is the area the model treats as the working range for the phase.
Candle 1 sweep lines — optional lines from the swept C1 extreme forward to confirmation, available separately on the HTF preview and on the chart timeframe, with a count limit and an s label.
Deviation projections — optional standard-deviation style extensions of the CISD-to-C2-extreme range, using either wicks or bodies as endpoints. Multipliers are entered as a comma-separated list (for example -1,-2,-3); invalid entries are ignored.

Line style, width, color, extension length, and label offset are exposed for every drawing type.

Timeframe pairing

The model needs an LTF/HTF pair. Preset pairs are 3m-15m, 1m-15m, 3m-30m, 5m-1H, 15m-4H, 1H-1D, 4H-1W, and 1D-1W. Custom lets you set both sides yourself. Auto selects the pair from the chart timeframe: 30s through 3m charts use 3m-15m, 5m uses 5m-1H, 15m uses 15m-4H, and anything else falls back to a monthly HTF.

The chart timeframe must be at or below the LTF side of the pair. When it is not, the dashboard shows a red warning row naming the timeframe you should switch to, and the HTF preview is suppressed. Model calculations still run, but the display is not meaningful in that state.

Note that HTF values are requested with lookahead enabled so the developing HTF candle can be drawn in real time. This is intentional for the preview, but it means historical HTF candle bodies on the chart reflect completed data — treat historical and realtime rendering as different, and do not read the preview as a backtest.

Dashboard

The table has three modes:

Live — the active setup only: direction, phase, CISD state, reclaim strength, rejection wick, age in bars.
Historical — adds the observed tally accumulated over the chart's loaded history: C4-intact rate, CISD confirmation rate, C4-intact rate split by whether CISD confirmed, and the two failure rates.
Full — adds sample counts, definitions, and interpretation notes.

Two measurements are worth defining explicitly:

Reclaim strength — where C2 closed inside C1's range, as a percentage of C1's range. A bullish C2 that swept the low and closed near C1's high scores high.
Rejection wick — the length of C2's rejection wick as a percentage of C2's own range.
About the reference figures

The dashboard can display a set of fixed reference percentages alongside the live tally. Those reference numbers are hard-coded constants taken from an external observational study of NQ/ES futures over 2019–2025 that counted per-event outcomes only. They are not calculated by this script, not derived from your chart, not a backtest, and not a P&L result — no position sizing, costs, slippage, or exit rules are involved anywhere in them. They are included purely as a static point of comparison, and they can be switched off entirely with the Study Benchmarks input.

The "Observed" column is calculated live by the script from whatever history your chart has loaded, so it will differ between symbols, timeframes, and account plans, and it will be small and noisy on short histories. Sample sizes (n=) are shown so you can judge that for yourself. Neither column predicts future outcomes.

Settings
General Settings — alerts master switch, separate Early CISD alert switch, history depth (number of retained setups; 0 keeps all), directional bias filter (Neutral / Bullish / Bearish), fractal pair, Early CISD display, custom LTF/HTF.
HTF Candles — candle count, hide toggle, offset, body/border/wick colors, HTF open line, period boundary lines, live high/low lines.
Model Style — label visibility and size, Early CISD styling, bullish and bearish CISD styling, candle equilibrium, T-Spot box colors.
Candle 1 Sweeps — HTF and LTF display toggles, count cap, sweep colors, extension, labels and label offset, style and width.
Line Extensions — bar-count extensions and label offsets for CISD and projection lines.
Deviations — enable, multiplier list, wick or body method, styling.
Dashboard — show/hide, mode, size, screen position, text and background colors, reference-figure toggle, live-setup toggle.
Alerts

Enable Alerts?, then create an alert on this indicator using "Any alert() function call." Events fire once per bar:

Bullish C2 formed
Bearish C2 formed
Bullish / Bearish Early CISD confirmed (requires Early CISD Alerts? as well)

Early CISD Alerts? controls only the alert events. Early CISD drawings are controlled by the separate Early CISD input.

How to use it
Set the fractal pair, or leave it on Auto, and make sure your chart timeframe is at or below the LTF side. The dashboard warns you if it is not.
Wait for a C2 to form — an HTF candle that sweeps the prior candle's extreme and closes back inside it.
Watch for the CISD reclaim on your chart timeframe. Confirmed CISD is what reveals the setup and what the model treats as the state change.
The C2 extreme is the invalidation reference. C3 is the window in which the setup should hold; C4 is where the outcome is recorded.
Use the T-Spot zone and the HTF equilibrium as context for where inside the phase price is working, and the deviation projections if you want measured extensions off the CISD range.
Use the bias filter to suppress counter-trend setups when you have a directional view.
Limitations and notes
This is an analysis and visualization tool. It generates no entries, exits, stops, targets, or position sizing, and it is not a strategy.
Drawing objects are capped by TradingView at 500 boxes, lines, and labels. High History, HTF Candles, Count, and deviation-multiplier settings all consume from those caps, and older drawings will be dropped when the cap is reached.
HTF data is requested with lookahead enabled to render the developing HTF candle. Realtime and historical rendering therefore differ; the preview is a display convenience, not a signal source.
The observed statistics depend entirely on how much history your chart has loaded and will change as you scroll, switch symbols, or change timeframes.
Repainting behavior on the current bar is inherent to any model that evaluates a developing candle. Levels and phase states are settled on bar close.
Nothing here is financial advice, and no result shown — observed or reference — is a prediction or a guarantee of future performance. Trading involves risk of loss.

إخلاء المسؤولية

لا يُقصد بالمعلومات والمنشورات أن تكون، أو تشكل، أي نصيحة مالية أو استثمارية أو تجارية أو أنواع أخرى من النصائح أو التوصيات المقدمة أو المعتمدة من TradingView. اقرأ المزيد في شروط الاستخدام.