1. Quarterly Theory ICT 04 SSMT 4Quarter Divergence Strategy Description
The indicator watches two related symbols at once: your chart symbol and a second "Symbol". It pairs up their swing highs and swing lows, and when — in a later quarter of the chosen time cycle (90 Minute by default) — only ONE of the two takes out its swing while the other fails to, it prints a bearish or bullish "SSMT" label (for example "Q2 to Q3") on both charts and can fire an alert.
1.1 Indicator Concept
The indicator is built on one idea taught in ICT: two markets that normally move together (BTC and ETH, Gold and Silver, NQ and ES...) should break their highs and lows together. When one of them breaks a high or a low and the other one refuses to follow, this disagreement — called an SMT divergence (Smart Money Technique) — is read as a sign that the break was a grab for liquidity rather than real strength. This version adds a time filter from Quarterly Theory: a divergence only counts when it shows up in a different quarter than the one where the swing was formed.
- Quarterly Theory: every cycle is cut into 4 quarters. A year, a month, a week, a day or a 90-minute block can each be split into Q1 → Q4. The author's own names for the four quarters are written inside the code (but never displayed): Q1 = Accumulation, Q2 = Manipulation, Q3 = Distribution, Q4 = Continuation or Reversal. You choose which cycle to use: Yearly, Monthly, Weekly, Daily, 90 Minute (default) or Micro. All clocks follow New York time.
- Two symbols, one comparison. The chart symbol (called X in this document) is compared with the symbol typed in the "Symbol" setting (called Y). They must be related markets, otherwise a "divergence" is just noise.
- Swing pairs. A swing high on X and a swing high on Y that formed within 2 candles of each other are glued together into one "pair" (the same is done for swing lows). The pair remembers both prices and the quarter it was recorded in.
- The divergence. After a pair exists, if one symbol trades above its swing high while the other symbol does not (or one trades below its swing low while the other does not), the two markets disagree → bearish SSMT at highs, bullish SSMT at lows. If BOTH break, they agree and nothing is signaled.
- The quarter gate. The signal is only printed if the swing pair was recorded in a different quarter than the quarter of the candle just before the sweep. That is why the label reads Q2 to Q3: "pair recorded in Q2, divergence seen in Q3".
The underlying belief: price often runs the old high or low of the previous phase of a cycle to collect liquidity, and the correlated market that does not confirm the run exposes it as a trap. The quarter gate keeps only the divergences that happen across phases of the cycle (for example manipulation → distribution) and drops those that happen inside the same phase.
1.2 Indicator Features
-
Display:
- Bearish SSMT label: dark red text SSMT + a line break + Q2 to Q3 sitting above the candle's high, with a dark red ▼ triangle just above the high. The text is placed 1.15 × ATR(200) above the high and the triangle 1.05 × ATR(200) above it.
- Bullish SSMT label: dark green text Q2 to Q3 + a line break + SSMT hanging below the candle's low, with a dark green ▲ triangle just under the low (same 1.15 / 1.05 × ATR(200) distances, downward).
- Two copies of every signal: one on the main price chart (symbol X) and one in the indicator pane (symbol Y). Both are printed on the same candle — the candle that took the swing out.
- Symbol Y candles in the pane: the indicator is a separate pane (not drawn over the price) and it plots the full candlesticks of symbol Y there — teal green when close ≥ open, red when close < open — so you can look at X above and Y below.
- Optional dotted lines (OFF by default): "Show Bullish SMT Line" / "Show Bearish SMT Line" draw a dotted horizontal line from the old swing candle to the candle that took it out, at the old swing price — one on each chart. Dark green for bullish, dark red for bearish.
- Optional cycle boxes and labels (OFF by default): "Show Cycle" paints a thin strip above the running high of every quarter, "Show Cycle Label" prints Q1…Q4 on it. Quarter colors: Q1 light blue, Q2 orange, Q3 teal, Q4 red, gray for anything that is not a quarter (the "Week 13" of the Monthly cycle). This is only a visual aid; it does not feed the signal.
- Alerts: two alerts, Bullish SMT Divergence and Bearish SMT Divergence, each with its own On / Off switch. The message looks like Bearish SMT Divergence in BTCUSDT & ETHUSDT (the chart ticker and the part of the "Symbol" after the colon). They are sent through the TradingFinder AlertSender library, not through alertcondition() — the code has no alertcondition() call at all. You can also set the alert name, the repeat frequency (All / Once Per Bar / Per Bar Close) and the time zone shown in the message.
1.3 How to Use the Indicator
- First, choose a truly related partner in "Symbol". The default is XAGUSD (Silver), which fits a Gold chart. For BTCUSDT you would pick ETHUSDT; for NQ you would pick ES. If the two never disagree in real life, the indicator will rarely fire; if they are unrelated, it will fire on noise. The two symbols should also trade the same hours.
- Match the cycle to the chart timeframe. One 90-minute quarter holds 6 candles on M15 but 18 on M5; a Micro quarter (about 22 minutes) holds only 1–2 candles on M15, so Micro is meant for M1–M5. Quarters must hold several candles to give the swings room to form.
- Read a bearish SSMT as a warning near highs. Both markets made a high together, then in the next quarter one pushed above it and the other could not. That is the classic "the high was a trap" picture: look for shorts, but confirm with your own structure, entry zone and session timing — the label is a warning, not a ready entry.
- Read a bullish SSMT as a warning near lows. The mirror image: one market undercut the old low, the other refused → look for longs with your own confirmation.
- Check both charts to see who failed. The label is printed on X and on Y at the same time and does not say which of the two failed to take its swing. Look at the two charts: the one that did not reach its old high (or low) is the weaker one.
- Read "Q2 to Q3" as a phase change. It tells you the swing pair was recorded in one quarter and the sweep happened in the next. In Quarterly Theory language, a divergence at the Q2 (manipulation) → Q3 (distribution) hand-over is the textbook case. That is a trading interpretation, not something the code checks.
- Expect the signal to come late, on the candle's close. A swing needs 3 candles after it to be confirmed, and the divergence test only runs on closed candles. The label therefore appears on the candle that took the swing out, after it closed — never at the swing itself.
- Do not expect a signal every quarter. No signal when both symbols break (they agree), when neither breaks, when the divergence comes too late (more than ~32 candles after the swing), or when it happens inside the same quarter.
- Tune sensitivity with the pivot settings. A bigger "Pivot Period" gives fewer, larger swings; a bigger "Pivot Sync Threshold" accepts pairs whose swings are further apart in time; a bigger "Validity Pivot Length" keeps pairs alive longer.
1.4 How the Indicator Works
Inputs & their role
- Quarterly_Cycles_Type (shown as "Quarterly Cycles Type", dropdown: Yearly / Monthly / Weekly / Daily / 90 Minute / Micro, default 90 Minute, group "Logical Setting"): which cycle is cut into 4 quarters. It decides the text stored with every swing pair and therefore the "Q2 to Q3" test. Example: on 90 Minute, 08:45 New York time is "NY AM Q2" (07:30–09:00); on Daily, the same moment is "Q3" (06:00–12:00); on Weekly it depends on the weekday. Change it and the same candle belongs to a different quarter, so the same divergence can pass or fail the quarter gate.
- SymY (shown as "Symbol", symbol picker, default XAGUSD): the second market, called Y. If you leave it as the wrong market (for example Silver on a BTC chart) the indicator still runs, but the "divergences" are meaningless. The part after the colon is also used in the alert message.
- Period (shown as "Pivot Period", integer, default 3): a swing high is a candle whose high is higher than the 3 candles on its left AND the 3 candles on its right (same logic for lows). It is confirmed only after those 3 right-side candles have closed. Example: at 3, a high at 07:45 on M15 is confirmed at 08:30; at 5 it would need 5 candles on each side, so swings are bigger and rarer and are confirmed later.
- MxPBack_b (shown as "Activate Max Pivot Back", tick box, default on) and MxPBack_i ("Max Pivot Back Length", integer, default 100): on every candle the indicator checks the stored pairs from the newest back. With the tick on it only checks the latest 100 pairs; with the tick off it checks all pairs ever recorded (slower on long charts, same results because old pairs expire anyway).
- Threshold (shown as "Pivot Sync Threshold", integer, default 2): how many candles apart the swing on X and the swing on Y may be and still count as "the same swing". Example: at 2, a BTC high on candle 1000 and an ETH high on candle 1001 form a pair (1 apart); an ETH high on candle 1004 does not (4 apart). It is counted in candles, not in minutes. Setting 0 demands both swings on exactly the same candle; setting a large number glues unrelated swings together.
- Validity (shown as "Validity Pivot Length", integer, default 30): how long a pair stays eligible, counted from the X swing candle: Validity + Threshold = 32 candles. About 3 of those candles are spent waiting for the swing to be confirmed, so a pair has roughly 29 candles left to produce a divergence. Past that it is ignored (it is not deleted, simply skipped).
- Show_Quarter ("Show Cycle", tick box, default off) and Show_Label ("Show Cycle Label", tick box, default off): the visual cycle strips and their Q labels. Display only; turning them on or off never changes a signal.
- Show_Line_Bull ("Show Bullish SMT Line", default off), Show_Label_Bull ("Show Bullish SMT Label", default on) and Color_Bull (color picker, default #006803 dark green) — the same three for the bearish side with Show_Line_Bear, Show_Label_Bear and Color_Bear (default #960303 dark red). The tick box and the color picker of each side sit on one row (inline). Turning "Show … Label" off hides both the text and the triangle of that side but does NOT turn the alert off.
- AlertName ("Alert Name", text, default SMT Alerts [TradingFinder]), Frequncy ("Message Frequency", dropdown All / Once Per Bar / Per Bar Close, default Once Per Bar), UTC ("Show Alert time by Time Zone", text, default UTC): text and repeat settings passed to the alert library. They never change when a signal happens.
- Alert_L ("Bullish SMT Divergence") and Alert_H ("Bearish SMT Divergence"), dropdowns On / Off, default On: switch each alert on or off. They do not hide the labels.
Hard-coded constants (NOT inputs)
- The clock is New York time (America/New_York) for every cycle type, and all session windows (Asian 18:00–00:00, London 00:00–06:00, NY AM 06:00–12:00, NY PM 12:00–18:00) are fixed in the code.
- Label distances: text at 1.15 × ATR(200) and triangle at 1.05 × ATR(200) from the candle's high / low, using the ATR of each symbol itself.
- Cycle strip height: ATR(500) / 2, only used by the optional cycle boxes.
- Y candle colors: #089981 up / #f23645 down. Quarter colors: see 1.2.
- Limits: max_bars_back = 5000, and 500 labels / 500 lines / 500 boxes at most (see the notes).
- The quarter-name shortener: labels only show Q1 to Q4 (or "non Q"). Session names such as "NY AM" and the Micro suffix "/2" are dropped in the label text.
Main logic blocks
🧭 Flow 0 — The big picture (every candle)
- On every candle the indicator does five things in order: ① decide which quarter this candle is in; ② read the candles and swings of both symbols; ③ pair up new swings of X and Y; ④ on a closed candle, test every live pair for a divergence; ⑤ if a divergence is found in a different quarter, draw the labels and send the alert. Then it plots Y's candles in the pane.
🕐 Flow 1 — Which quarter are we in? (every candle)
- A candle belongs to a quarter if its open time falls inside that quarter's window (New York time). The result is one text, Quarter, and it depends on the cycle you selected:
- Yearly: Q1 = Jan–Mar, Q2 = Apr–Jun, Q3 = Jul–Sep, Q4 = Oct–Dec.
- Monthly: a rolling count of full calendar weeks: 1st full week = Q1, 2nd = Q2, 3rd = Q3, 4th = Q4, and the week after Q4 starts again at Q1. Two exceptions: a week that starts in the last 3 days of a month is a "Partial Week" (no quarter, counter back to 0), and every 13th full week of the year is labelled "Week 13" (gray, no quarter). The week counter restarts every new year.
- Weekly: Monday = Q1, Tuesday = Q2, Wednesday = Q3, Thursday = Q4. Friday, Saturday and Sunday are all labelled "Friday" (no quarter).
- Daily: Q1 = 18:00–00:00 (Asian), Q2 = 00:00–06:00 (London), Q3 = 06:00–12:00 (NY AM), Q4 = 12:00–18:00 (NY PM).
- 90 Minute: each of the four sessions above is cut into four 90-minute quarters, and the text includes the session. Example (NY AM): Q1 06:00–07:30, Q2 07:30–09:00, Q3 09:00–10:30, Q4 10:30–12:00 → the candle at 08:45 is NY AM Q2, the candle at 09:00 is NY AM Q3.
- Micro: each 90-minute quarter is cut again into four quarters of about 22.5 minutes (22 or 23 minutes), named Qa/b where a is the small quarter and b is the 90-minute block inside the session. Example: NY AM Q1/2 = 07:30–07:52. In the label only the first number survives ("Q1").
- Why this matters: the raw text (for example "NY AM Q2") is what gets compared later. Two candles in different sessions but with the same Q number still count as different quarters, because the session name is part of the text.
📡 Flow 2 — Reading both symbols (every candle)
- Symbol X is the chart symbol, symbol Y is the "Symbol" input; both are read on the chart's own timeframe. For each one the indicator takes: open, high, low, close, the candle number, the candle time and the ATR(200). It also runs the swing finder (Flow 3) separately inside each symbol.
- Swing finder (pivot()): a swing high is confirmed when a candle's high is higher than the 3 candles on each side (Period = 3). At that moment it stores the swing's price, candle number and time. Until the next swing appears, these stored values stay the same — they are "the latest swing high / low" of that symbol. Same for swing lows.
- Concrete example: BTC prints a high of 68,000 on candle 1000 (07:45). Candles 1001–1003 all trade lower. At candle 1003 the swing is confirmed: latest BTC swing high = 68,000, number 1000.
🔗 Flow 3 — Pairing the swings of X and Y (every candle)
- Trigger: a new swing high is confirmed on X or on Y during this candle (the same for lows, running as a separate copy of the same logic).
- Sync test: take the latest swing high of the OTHER symbol and check that it happened no more than Threshold candles away from the swing that was just confirmed. In code terms: if X just confirmed, i_y − ph_Iy − PP <= Threshold; if only Y just confirmed, i_x − ph_Ix − PP <= Threshold.
- If the test passes → a pair is recorded: X's swing price / number / time, Y's swing price / number / time, a "permit" flag set to true, and the current candle's Quarter text. All of these go into parallel lists (arrays — numbered lists of values), one list per item, so item number N of every list belongs to the same pair.
- Concrete example: BTC swing high 68,000 on candle 1000 (07:45). ETH swing high 3,500 on candle 1001 (08:00). BTC is confirmed at candle 1003: ETH's latest swing is old → test fails, nothing recorded. ETH is confirmed at candle 1004 (08:45): BTC's latest swing is candle 1000 → 1004 − 1000 − 3 = 1 <= 2 → pass. A pair is recorded: BTC 68,000 / ETH 3,500, quarter NY AM Q2 (08:45 is inside 07:30–09:00).
- Two details: ① the pair is recorded when the later of the two swings is confirmed, so it is stamped with the quarter of that candle (up to 3 + 2 candles after the real swing), not of the swing candle itself. ② The same swing can be paired twice in a dense market (for example X swings on candles 10 and 12 and Y swings on candle 11).
🔍 Flow 4 — Watching the pairs for a divergence (closed candles only)
- Gate: this whole block runs only when barstate.isconfirmed is true, i.e. when the candle has closed (and on every historical candle). So the label can only appear at the close of the sweeping candle. It also needs at least 2 pairs in the list.
- Loop: from the newest pair backwards, at most Max Pivot Back Length (100) pairs. A pair is examined only if it is still active (permit = true) and its age is within the limit: current candle number − X swing candle number <= Validity + Threshold (32).
- BEARISH test (pair of swing highs): compare the current candle's high of each symbol with that symbol's stored swing high. Let A = "X's high is above X's old swing high" and B = "Y's high is above Y's old swing high".
- A and B are different (exactly one symbol took its high out): divergence. The pair's permit is set to false straight away (the pair is used up) → go to the quarter gate (Flow 5).
- A and B are both true (both took their highs out): the markets agree → the pair is retired silently, no signal.
- A and B are both false: nothing happened yet → the pair stays active and is checked again on the next closed candle.
- The comparison is a strict "higher than" on the current candle's high only: touching the old high exactly does not count.
- BULLISH test (pair of swing lows): exactly the mirror: compare the current candle's low with each stored swing low ("low is below the old swing low"). Exactly one symbol undercuts → divergence; both undercut → retired silently; neither → keep waiting.
- Concrete example (bearish): candle 1006 (09:15) closes with BTC high 68,120 and ETH high 3,490. BTC: 68,120 > 68,000 → A = true. ETH: 3,490 > 3,500? No → B = false. A ≠ B → divergence. Age: 1006 − 1000 = 6 <= 32 ✓. If ETH had printed 3,510 instead, A = B = true → both broke, pair retired, no signal.
🚪 Flow 5 — The quarter gate, the labels and the alert (only after a divergence)
- The test: the Quarter text stored in the pair must be different from the Quarter text of the previous candle (Quarter[1] — not the current candle). If it is the same, no label and no alert — but the pair has already been used up in Flow 4, so it will not be checked again.
- If it passes: the "Alert_h" (bearish) or "Alert_l" (bullish) flag turns true for this candle, and the labels are drawn (if the label switch of that side is on): the text, the triangle, and the optional dotted line — once on X (main chart) and once on Y (pane). The label text is Q? of the stored quarter + " to " + Q? of the previous candle's quarter.
- The alert: the library sends the message if that alert's switch (Alert_L / Alert_H) is "On". Both flags are false on every other candle.
- Concrete example (passes): pair stored in NY AM Q2. Sweep candle at 09:15; the previous candle (09:00) is NY AM Q3 → different → bearish label SSMT / Q2 to Q3 on both charts + alert.
- Concrete example (blocked): same pair, but the sweep comes at 09:00 sharp. The previous candle (08:45) is still NY AM Q2 → same → no label, no alert, and the pair is gone. The same divergence one candle later would have been signaled.
- If several pairs trigger on the same candle, the flag is still just "true" (one alert), but each pair draws its own labels, so they can sit on top of each other.
📦 Flow 6 — Cycle boxes (display only)
- When "Show Cycle" is on, each time a candle enters a new quarter a box is created above the chart, then stretched to the right on every candle of that quarter, its bottom following the running highest high of the quarter (top = that high + ATR(500)/2). "Show Cycle Label" adds the Q text in its middle. It reads the same quarter windows as Flow 1 but no signal depends on it.
Outputs & their role in trading
- Bearish / bullish SSMT labels (X on the chart, Y in the pane): "the two markets disagreed on this sweep, and the pair was recorded in a different quarter". Use them as a warning at highs / lows, then confirm with your own method.
- "Qx to Qy" text: tells which quarters the swing pair and the sweep belong to, so you can judge whether it is the phase change you trade (for example Q2 → Q3).
- Optional dotted lines: show exactly which old swing was taken, and how long ago it was formed.
- Symbol Y candles in the pane: let you see the partner market under your chart without opening a second chart.
- Alerts: the same two events pushed to your phone or webhook.
- Closed-candle logic, no repainting of signals. Pairs are recorded only after a swing is confirmed (3 candles late by default) and the divergence test runs only on closed candles, so a label that has appeared stays where it is. The price of that safety is lateness: the signal arrives after the sweeping candle closes.
- A divergence that fails the quarter gate is consumed silently. The pair's permit is switched off before the quarter check, so if the sweep comes in the same quarter as the one stored (or on the very first candle of the next quarter, where the previous candle still belongs to the old one), nothing is drawn and the pair cannot trigger later.
- The quarter stamp is the pairing candle's, not the swing's. A swing that formed just before a quarter boundary can be stamped with the next quarter if its partner is confirmed after the boundary.
- The sync test counts candles, not minutes. If X and Y have different trading hours or missing candles, the "2 candles apart" rule no longer means "2 time units apart". Use two symbols that trade together.
- The label does not say which symbol failed. Both symbols receive the same label. Compare the two charts yourself.
- Unused code: a function Phase() that maps Q1–Q4 to "Accumulation / Manipulation / Distribution / Continuation or Reversal" exists but is never called, so those names never appear on the chart.
- Cycle quirks to know about: ① Micro — the Asian session list stops at 21:22–21:45, so 21:45–00:00 New York has no Micro quarter at all; ② Weekly — Friday, Saturday and Sunday are all "Friday" (no quarter); ③ Monthly — it is a rolling 4-full-week counter, not a calendar-month split, and it contains the gray "Week 13" and "Partial Week" exceptions. In Weekly (Friday–Sunday) and in Monthly's "Week 13" the label text would read "non Q"; in Monthly's "Partial Week" and in the Micro gap the code assigns no quarter text at all, and how a swing pair stamped there behaves at the quarter gate was not tested. Prefer the other cycle types, or avoid relying on signals in those slots.
- Label budget: 500 labels, never deleted by the code. Each signal creates up to 4 labels (text + triangle on X, text + triangle on Y), and the cycle labels (if shown) use the same budget. Beyond 500, TradingView silently erases the oldest, so on a long chart only roughly the latest 120 signals remain visible.
- Lists grow forever. Retired or expired pairs are not removed from the arrays; the 100-pair limit only limits how many are examined each candle. With "Activate Max Pivot Back" off, every pair ever recorded is examined on every closed candle, which can slow a long chart.
- Chart overlay vs pane. The indicator itself lives in a separate pane (overlay = false); the X copies are forced onto the main price chart. Y's candles and Y's labels stay in the pane, on Y's own price scale.


