FM-BY-VickyA

This is a Pine Script v6 indicator for TradingView. It draws the “Le Modèle” C1 / C2 / C3 / C4 structure on the chart, with HTF (higher timeframe) candle previews, SMT and PSP checks, and alerts. It is built on the open-source cantolab fractal script you uploaded.
The file has four parts: inputs, constants and types, helper functions, and the per-bar logic. A plot section at the end draws the output.
1. Inputs (lines 4–120)
Settings are grouped into panels:
General / Model: alerts master switch, Early CISD toggle, and the model pair (Auto, 1m-15m, 3m-30m, 5m-1H, 15m-4H, 1H-1D, 4H-1W, 1D-1W, 1D-1M, 1W-3M, or Custom). Auto picks the HTF/LTF pair from the chart timeframe.
HTF Candles: how many HTF candles to show, the hide toggle, the offset, the candle-time label and its timezone (Exchange, UTC, UTC+1 … UTC-5), and colors for body, wick, border and HTF open.
Visuals: C1 sweep line, Early CISD, Bullish/Bearish CISD lines, candle equilibrium, and the T-Spot (sweet-spot) box.
Deviations: optional projections at -1, -2, -3 from the C2 wick or body.
PSP / SMT: PSP toggle, SMT toggle and style, two SMT pairs (defaults NQ vs ES and GC vs SI), and filters Require PSP / Require SMT.
C2 Alerts: C2 close alert on/off, C2 timeframe filter (Any, 15m, 30m, 1H, 4H), Require PSP, Require SMT, and Wait for LTF CISD.
Dashboard: a small table showing the current setup status, with position and colors.
2. Types and state (lines 121–245)
HtfCandle: one HTF candle. It stores OHLC, bar indexes, drawing objects (body box, wicks, equilibrium line, sweep line), the open time t, and the SMT/PSP direction data for both correlated instruments.
PeriodState: the previous two HTF candles’ highs, lows and bar indexes, and the previous-bar C2 trigger flags.
C2Setup: one active trade model. It holds the C2 extreme, C3 and C4 start bars, the CISD level and whether it has confirmed, PSP and SMT flags, and an alertPending flag for wait-for-CISD alerts.
SetupRecord / EarlyCisdRecord: history of finished setups and of Early CISD levels, used for drawing and cleanup.
Global var arrays: the HTF candle list, the vertical time lines, and the L/H lines.
3. Functions (lines 245–885)
Labels and timing: tfLabel, tfMins, autoHTF, ltfCode. These turn timeframes into labels and map the chart timeframe to its HTF/LTF pair.
Timezone: f_tz() returns the exchange timezone or the UTC offset you picked. The candle-time label uses it.
SMT: f_div checks whether one instrument takes out the C1 low/high and the other does not. f_smtNames returns the counterpart name on NQ/ES or GC/SI charts, or all diverging pairs elsewhere. f_chartRoot reads the chart’s root symbol (NQ, ES, GC or SI), so MNQ and MES work too.
Tags: f_tags builds the alert suffix. It adds +PSP, +SMT <name> and +CISD only when those actually formed.
HTF candle methods:
update extends the developing candle with each new bar.
syncCorr stores the correlated instruments’ OHLC on the candle.
draw draws the candle, wicks, time label and equilibrium.
Early CISD: drawEarlyCisd and its prune and consume helpers track the early reclaim levels.
Setup lifecycle (C2Setup methods):
reveal draws the setup once CISD confirms, backdated to when C3 started.
advanceToC4 and extendAndCheck move the setup from C2 to C3 to C4 as price moves.
checkC4Invalid discards a setup whose C4 fails, including a CISD that only confirmed in C4.
checkCisdConfirm marks CISD confirmed when price closes through the CISD level.
finish and registerRecord close the setup and store it.
Projections: createStdDevProjections and parseFloats build the optional deviation levels.
PSP: markPsp labels PSP on the HTF preview candles, and only inside a triggered model.
4. Per-bar logic (lines 883–1108)
Bullish and bearish fixed levels. When price makes a new low (or high) and the candle pattern matches, the script stores the level to watch: the open of the opposing candle, or the best open/close in the sweep. These become the bullish and bearish CISD levels.
Reclaim and Early CISD. When close reclaims a level after a period sweep, the script records the reclaim and draws an Early CISD line, if Early CISD is on.
HTF candle update. On each new HTF period, a new HtfCandle is added at the front and the previous two candles are saved in PeriodState. The first candle’s time comes from time(autoTf), which is the exact HTF bar open. Otherwise the current candle is updated.
PSP and SMT at C2 close. On the HTF period change, the script reads the two previous candles, C1 and C2. PSP is set when the two instruments close in opposite directions. SMT is set when only one instrument sweeps its C1 extreme.
Filters. Require PSP and Require SMT decide whether a C2 counts as a valid setup.
Setup creation and update. Valid C2 triggers call processC2, which creates or updates the setup. Then extendAndCheck, checkC4Invalid and checkCisdConfirm run on each bar.
Alerts.
Wait for LTF CISD off: when a valid C2 closes, one alert fires: Bullish/Bearish C2 formed on <ticker> (<tf>), with PSP and SMT tags if they formed. No CISD tag, because CISD hasn’t happened yet.
Wait for LTF CISD on: the setup is armed on the bar it is created. When its CISD confirms, one alert fires with the same wording and the +CISD tag, plus PSP and SMT if present. Each setup alerts once.
The file has four parts: inputs, constants and types, helper functions, and the per-bar logic. A plot section at the end draws the output.
1. Inputs (lines 4–120)
Settings are grouped into panels:
General / Model: alerts master switch, Early CISD toggle, and the model pair (Auto, 1m-15m, 3m-30m, 5m-1H, 15m-4H, 1H-1D, 4H-1W, 1D-1W, 1D-1M, 1W-3M, or Custom). Auto picks the HTF/LTF pair from the chart timeframe.
HTF Candles: how many HTF candles to show, the hide toggle, the offset, the candle-time label and its timezone (Exchange, UTC, UTC+1 … UTC-5), and colors for body, wick, border and HTF open.
Visuals: C1 sweep line, Early CISD, Bullish/Bearish CISD lines, candle equilibrium, and the T-Spot (sweet-spot) box.
Deviations: optional projections at -1, -2, -3 from the C2 wick or body.
PSP / SMT: PSP toggle, SMT toggle and style, two SMT pairs (defaults NQ vs ES and GC vs SI), and filters Require PSP / Require SMT.
C2 Alerts: C2 close alert on/off, C2 timeframe filter (Any, 15m, 30m, 1H, 4H), Require PSP, Require SMT, and Wait for LTF CISD.
Dashboard: a small table showing the current setup status, with position and colors.
2. Types and state (lines 121–245)
HtfCandle: one HTF candle. It stores OHLC, bar indexes, drawing objects (body box, wicks, equilibrium line, sweep line), the open time t, and the SMT/PSP direction data for both correlated instruments.
PeriodState: the previous two HTF candles’ highs, lows and bar indexes, and the previous-bar C2 trigger flags.
C2Setup: one active trade model. It holds the C2 extreme, C3 and C4 start bars, the CISD level and whether it has confirmed, PSP and SMT flags, and an alertPending flag for wait-for-CISD alerts.
SetupRecord / EarlyCisdRecord: history of finished setups and of Early CISD levels, used for drawing and cleanup.
Global var arrays: the HTF candle list, the vertical time lines, and the L/H lines.
3. Functions (lines 245–885)
Labels and timing: tfLabel, tfMins, autoHTF, ltfCode. These turn timeframes into labels and map the chart timeframe to its HTF/LTF pair.
Timezone: f_tz() returns the exchange timezone or the UTC offset you picked. The candle-time label uses it.
SMT: f_div checks whether one instrument takes out the C1 low/high and the other does not. f_smtNames returns the counterpart name on NQ/ES or GC/SI charts, or all diverging pairs elsewhere. f_chartRoot reads the chart’s root symbol (NQ, ES, GC or SI), so MNQ and MES work too.
Tags: f_tags builds the alert suffix. It adds +PSP, +SMT <name> and +CISD only when those actually formed.
HTF candle methods:
update extends the developing candle with each new bar.
syncCorr stores the correlated instruments’ OHLC on the candle.
draw draws the candle, wicks, time label and equilibrium.
Early CISD: drawEarlyCisd and its prune and consume helpers track the early reclaim levels.
Setup lifecycle (C2Setup methods):
reveal draws the setup once CISD confirms, backdated to when C3 started.
advanceToC4 and extendAndCheck move the setup from C2 to C3 to C4 as price moves.
checkC4Invalid discards a setup whose C4 fails, including a CISD that only confirmed in C4.
checkCisdConfirm marks CISD confirmed when price closes through the CISD level.
finish and registerRecord close the setup and store it.
Projections: createStdDevProjections and parseFloats build the optional deviation levels.
PSP: markPsp labels PSP on the HTF preview candles, and only inside a triggered model.
4. Per-bar logic (lines 883–1108)
Bullish and bearish fixed levels. When price makes a new low (or high) and the candle pattern matches, the script stores the level to watch: the open of the opposing candle, or the best open/close in the sweep. These become the bullish and bearish CISD levels.
Reclaim and Early CISD. When close reclaims a level after a period sweep, the script records the reclaim and draws an Early CISD line, if Early CISD is on.
HTF candle update. On each new HTF period, a new HtfCandle is added at the front and the previous two candles are saved in PeriodState. The first candle’s time comes from time(autoTf), which is the exact HTF bar open. Otherwise the current candle is updated.
PSP and SMT at C2 close. On the HTF period change, the script reads the two previous candles, C1 and C2. PSP is set when the two instruments close in opposite directions. SMT is set when only one instrument sweeps its C1 extreme.
Filters. Require PSP and Require SMT decide whether a C2 counts as a valid setup.
Setup creation and update. Valid C2 triggers call processC2, which creates or updates the setup. Then extendAndCheck, checkC4Invalid and checkCisdConfirm run on each bar.
Alerts.
Wait for LTF CISD off: when a valid C2 closes, one alert fires: Bullish/Bearish C2 formed on <ticker> (<tf>), with PSP and SMT tags if they formed. No CISD tag, because CISD hasn’t happened yet.
Wait for LTF CISD on: the setup is armed on the bar it is created. When its CISD confirms, one alert fires with the same wording and the +CISD tag, plus PSP and SMT if present. Each setup alerts once.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.