Weierstrass + Fractal Cycles

Title: Weierstrass Fractal Cycles —
Regime-Aware Oscillator with Divergence, Trend Gate & Trade Plan
Short description
A mathematically grounded fractal oscillator built on the Weierstrass function (a·b regime), with auto-tuned frequency, confirmed zero-crosses, regular/hidden divergence, trend gating, and a full state-machine trade plan with ATR SL/TP and webhook-ready alerts.
📖 Full Description
🧠 What it is
Most oscillators are recombinations of price averages. This one is different — it's built directly from the Weierstrass function, the classic example of a continuous but nowhere-differentiable curve:
W(x) = Σ aⁿ · cos(bⁿ · π · x)
The behavior of that sum is governed almost entirely by the product a·b, which gives this indicator something rare: a mathematically meaningful regime classification.
a·b Regime Meaning
> 1 🔵 FRACTAL Rough, self-similar, chaotic — the Weierstrass property
≈ 1 🟠 CRITICAL Boundary case, transition zone
< 1 ⚪ SMOOTH Low-dimensional, mean-reverting behavior
The oscillator you see plotted is that sum, normalized and optionally smoothed. Its shape changes with regime — not just its level.
⚙️ How it works
1. Auto Timeframe Detection
On low timeframes (≤15m) the script shortens pivot lengths, reduces terms, and boosts scale. On higher TFs it lengthens them. You don't have to re-tune per chart — but you can disable this and go fully manual.
2. Auto-Tune b (optional)
When enabled, every N bars the script searches b ∈ [bMin, bMax] and picks the value that maximizes a variance-ratio "roughness" score. A ★ appears in the info table when a tuned value is active. A performance guard caps tuning to the first perfGuardMax bars so it never slows your chart down.
3. Anchoring
Bar Index — rolling anchor, always fresh
Swing Pivot — re-anchors to the latest pivot, with a phase-continuity correction so the oscillator never jumps
Fixed Start — anchor to a specific timestamp
4. Confirmed Zero-Crosses
Instead of firing on the first bar past zero, the script requires eff_confirm consecutive bars on the new side. This eliminates most whipsaws while staying responsive.
5. Trend Gate
Signals can be filtered by EMA, SMA, or Supertrend direction. Counter-trend alerts can be allowed separately from counter-trend entries.
6. Divergence Detection
Regular and hidden divergence is detected on price pivots vs. oscillator pivots, with a configurable range cap and optional drawn lines.
7. Trade Plan (state machine)
Optional long/short state machine with:
ATR-based SL/TP
Optional divergence requirement for entry
Opposite-signal rejection
Entry/SL/TP lines drawn on the price chart via force_overlay
JSON or plain-text webhook payloads for automation
8. Info Table
Live readout of: regime, a·b, effective b, scale, oscillator value, trend state, Supertrend direction, last divergence, current plan state, open P&L in ATR multiples, and performance-guard status — all with tooltips.
🎨 How to read the panel
Oscillator line — cyan when rising, yellow when falling
Background tint — regime color (blue = fractal, orange = critical, gray = smooth)
▲ / ▼ arrows — confirmed zero-crosses (bright = trend-aligned, dim = counter-trend)
DIV / hDIV labels — regular and hidden divergence
Circles — Supertrend direction mirrored onto the oscillator panel (a compact visual gate)
Info table — top-right by default; fully configurable position, layout, and size
🛠 Suggested starting configurations
Style TF autoTF a b trendType confirm
Scalp 5–15m ✅ 0.5 auto Supertrend 1
Intraday 1H–4H ✅ 0.5 3.0 EMA 34 2
Swing 1D ✅ 0.5 3.0 EMA 50 2
Position 1W ✅ 0.6 2.5 Supertrend 3
Turn on Auto-Tune b if you want the script to adapt b to the instrument's own texture. Turn it off for reproducibility.
🔔 Alerts available
Zero-cross (bull/bear, trend-gated)
Regime change (FRACTAL / CRITICAL / SMOOTH)
Regular divergence (bull/bear)
Hidden divergence (bull/bear)
Trade plan ENTRY and EXIT (with full JSON payload for webhooks)
All alerts fire once_per_bar_close — designed for reliable bot consumption, not intrabar noise.
⚠️ Notes & limitations
This is not a repainting-free guarantee for divergence drawings — divergence is confirmed only after eff_divLook bars (standard pivot behavior).
Auto-tune is disabled after perfGuardMax bars by design, to keep long charts snappy.
The Weierstrass sum is deterministic given (a, b, x) — it is not predictive in itself. It's a texture measure, not a forecast. Use it as a filter and context tool, not a standalone entry system.
The trade plan is a reference implementation — always forward-test and size positions independently.
The maximum useful n_terms in the UI is capped at 12 internally for performance, even though the input allows 50.
🧪 Philosophy
This indicator treats the market as a signal texture problem rather than a prediction problem. The regime tells you what kind of market you're in; the oscillator tells you where in that texture you are; the trend gate tells you whether to trust the signal direction. Everything else — divergence, plan, alerts — is scaffolding around those three questions.
Trade the regime. Respect the trend. Let the noise stay noise.
📌 Credits
Original concept and implementation by © gogaz. Published under Mozilla Public License 2.0. Built on Pine Script® v6.
Feedback, forks, and instrumentation ideas are welcome — especially if you find a cleaner objective for the auto-tune score or a better phase-continuity correction for pivot anchoring.
Not financial advice. Past behavior of a mathematical function is not a guarantee of future behavior of a financial instrument. Use at your own risk.
Regime-Aware Oscillator with Divergence, Trend Gate & Trade Plan
Short description
A mathematically grounded fractal oscillator built on the Weierstrass function (a·b regime), with auto-tuned frequency, confirmed zero-crosses, regular/hidden divergence, trend gating, and a full state-machine trade plan with ATR SL/TP and webhook-ready alerts.
📖 Full Description
🧠 What it is
Most oscillators are recombinations of price averages. This one is different — it's built directly from the Weierstrass function, the classic example of a continuous but nowhere-differentiable curve:
W(x) = Σ aⁿ · cos(bⁿ · π · x)
The behavior of that sum is governed almost entirely by the product a·b, which gives this indicator something rare: a mathematically meaningful regime classification.
a·b Regime Meaning
> 1 🔵 FRACTAL Rough, self-similar, chaotic — the Weierstrass property
≈ 1 🟠 CRITICAL Boundary case, transition zone
< 1 ⚪ SMOOTH Low-dimensional, mean-reverting behavior
The oscillator you see plotted is that sum, normalized and optionally smoothed. Its shape changes with regime — not just its level.
⚙️ How it works
1. Auto Timeframe Detection
On low timeframes (≤15m) the script shortens pivot lengths, reduces terms, and boosts scale. On higher TFs it lengthens them. You don't have to re-tune per chart — but you can disable this and go fully manual.
2. Auto-Tune b (optional)
When enabled, every N bars the script searches b ∈ [bMin, bMax] and picks the value that maximizes a variance-ratio "roughness" score. A ★ appears in the info table when a tuned value is active. A performance guard caps tuning to the first perfGuardMax bars so it never slows your chart down.
3. Anchoring
Bar Index — rolling anchor, always fresh
Swing Pivot — re-anchors to the latest pivot, with a phase-continuity correction so the oscillator never jumps
Fixed Start — anchor to a specific timestamp
4. Confirmed Zero-Crosses
Instead of firing on the first bar past zero, the script requires eff_confirm consecutive bars on the new side. This eliminates most whipsaws while staying responsive.
5. Trend Gate
Signals can be filtered by EMA, SMA, or Supertrend direction. Counter-trend alerts can be allowed separately from counter-trend entries.
6. Divergence Detection
Regular and hidden divergence is detected on price pivots vs. oscillator pivots, with a configurable range cap and optional drawn lines.
7. Trade Plan (state machine)
Optional long/short state machine with:
ATR-based SL/TP
Optional divergence requirement for entry
Opposite-signal rejection
Entry/SL/TP lines drawn on the price chart via force_overlay
JSON or plain-text webhook payloads for automation
8. Info Table
Live readout of: regime, a·b, effective b, scale, oscillator value, trend state, Supertrend direction, last divergence, current plan state, open P&L in ATR multiples, and performance-guard status — all with tooltips.
🎨 How to read the panel
Oscillator line — cyan when rising, yellow when falling
Background tint — regime color (blue = fractal, orange = critical, gray = smooth)
▲ / ▼ arrows — confirmed zero-crosses (bright = trend-aligned, dim = counter-trend)
DIV / hDIV labels — regular and hidden divergence
Circles — Supertrend direction mirrored onto the oscillator panel (a compact visual gate)
Info table — top-right by default; fully configurable position, layout, and size
🛠 Suggested starting configurations
Style TF autoTF a b trendType confirm
Scalp 5–15m ✅ 0.5 auto Supertrend 1
Intraday 1H–4H ✅ 0.5 3.0 EMA 34 2
Swing 1D ✅ 0.5 3.0 EMA 50 2
Position 1W ✅ 0.6 2.5 Supertrend 3
Turn on Auto-Tune b if you want the script to adapt b to the instrument's own texture. Turn it off for reproducibility.
🔔 Alerts available
Zero-cross (bull/bear, trend-gated)
Regime change (FRACTAL / CRITICAL / SMOOTH)
Regular divergence (bull/bear)
Hidden divergence (bull/bear)
Trade plan ENTRY and EXIT (with full JSON payload for webhooks)
All alerts fire once_per_bar_close — designed for reliable bot consumption, not intrabar noise.
⚠️ Notes & limitations
This is not a repainting-free guarantee for divergence drawings — divergence is confirmed only after eff_divLook bars (standard pivot behavior).
Auto-tune is disabled after perfGuardMax bars by design, to keep long charts snappy.
The Weierstrass sum is deterministic given (a, b, x) — it is not predictive in itself. It's a texture measure, not a forecast. Use it as a filter and context tool, not a standalone entry system.
The trade plan is a reference implementation — always forward-test and size positions independently.
The maximum useful n_terms in the UI is capped at 12 internally for performance, even though the input allows 50.
🧪 Philosophy
This indicator treats the market as a signal texture problem rather than a prediction problem. The regime tells you what kind of market you're in; the oscillator tells you where in that texture you are; the trend gate tells you whether to trust the signal direction. Everything else — divergence, plan, alerts — is scaffolding around those three questions.
Trade the regime. Respect the trend. Let the noise stay noise.
📌 Credits
Original concept and implementation by © gogaz. Published under Mozilla Public License 2.0. Built on Pine Script® v6.
Feedback, forks, and instrumentation ideas are welcome — especially if you find a cleaner objective for the auto-tune score or a better phase-continuity correction for pivot anchoring.
Not financial advice. Past behavior of a mathematical function is not a guarantee of future behavior of a financial instrument. Use at your own risk.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.
Pernyataan Penyangkalan
Informasi dan publikasi ini tidak dimaksudkan, dan bukan merupakan, saran atau rekomendasi keuangan, investasi, trading, atau jenis lainnya yang diberikan atau didukung oleh TradingView. Baca selengkapnya di Ketentuan Penggunaan.