OPEN-SOURCE SCRIPT

Bitcoin Almanac [WillyAlgoTrader]

8 503
₿ Bitcoin Almanac is an overlay indicator that maps the entire Bitcoin macro landscape on one chart: a fixed-length cycle time model (bull/bear phases projected from a single anchor date), two hyperbolic curves fitted through historical cycle lows and cycle highs in log-price space, Fibonacci grids stretched between every macro pivot, halving markers, accumulation and distribution zones, and a hypothetical price path for the next bull leg — all summarized in a live dashboard with projected turn dates, curve prices, and historical correction depths.

The core insight: Bitcoin's completed cycles show a remarkably stable time rhythm (roughly 1064 days up, 364 days down) and a decelerating growth pattern that a hyperbola in log10(price) captures with surprisingly small error. Neither observation is a law of nature — but when the time model and the price curves are combined on one chart, they produce concrete, falsifiable reference points: a projected top date with a curve price, a projected bottom date with a curve price, and buy/sell zones derived from both. The indicator makes the whole framework explicit, configurable, and honest about its assumptions.

Everything is driven by dates and user-defined pivots — not by real-time price action — so nothing repaints: the lines you see today are the lines you saw yesterday.


🧩 WHY THESE COMPONENTS WORK TOGETHER

A cycle-date model alone answers WHEN but not AT WHAT PRICE. A curve through historical lows answers WHERE support migrates but not WHEN price will meet it. Fibonacci retracements answer WHERE pullbacks tend to end, but only if you know which macro leg to anchor them to. Used separately, each tool leaves you guessing at the missing dimension.

Bitcoin Almanac chains them into one pipeline:

Cycle time model (anchor + phase lengths) → projected turn dates → hyperbolic lows/highs curves → curve price AT each projected date → Fibonacci grids between macro pivots → 0.786–0.836 accumulation zones bounded by cycle end dates → ±% distribution zones around each high → replayed bull-path projection between the two curve endpoints → dashboard synthesis

The time model supplies the X-coordinate of every future event. The two hyperbolas supply the Y-coordinate: the lows curve is evaluated exactly at the projected bottom date, the highs curve exactly at the projected top date — the "◎ cycle × curve" labels mark these intersections with date and price. The Fibonacci grids are then anchored to the same pivots the curves are built from, so the 0.786–0.836 buy zone of the current leg stretches in time precisely to the model's next cycle-bottom date. Finally, the projection module takes the two curve × date intersections as endpoints and fills the path between them by replaying the shape of the previous bull phase in log space.

No single component can do this: the intersection of an independent time model with an independent price model is what turns two vague trajectories into specific, checkable coordinates.


🔍 WHAT MAKES IT ORIGINAL

1️⃣ Fixed-rhythm cycle engine — pure time math, zero price input.

The phase of any bar is computed directly from calendar time:

daysSince = (barTime − anchor) / 86 400 000
phasePos = daysSince mod (bullDays + bearDays)
isBull = phasePos < bullDays

Defaults: anchor = 07 Nov 2022, bullDays = 1064, bearDays = 364 (each ≈ the average of the three completed BTC cycles). A true mathematical modulo (always ≥ 0) phases bars BEFORE the anchor correctly, so past cycles line up too. With defaults this reproduces the well-known projected dates: top ≈ 06 Oct 2025, bottom ≈ 05 Oct 2026. An alternative anchor (21 Nov 2022 — the actual lowest trade of the cycle) is documented right in the input tooltip and shifts the bottom to 19 Oct 2026.

Why this matters: because the phase depends only on time, the bull/bear background, turn lines and flip alerts are deterministic and cannot repaint — the model's claims are fully falsifiable in advance.

2️⃣ Hyperbolic curve through cycle lows — exact geometry or least-squares fit, with the error printed on the chart.

The lows model is log10(price) = a + b / (c − t), where t is days from the first pivot. The hyperbola has a vertical asymptote in the past and a horizontal asymptote in the future — it encodes decelerating growth, which a straight log-regression line cannot.

— With exactly 3 enabled lows (default: Aug 2015 ≈ $169, Dec 2018 ≈ $3 122, Nov 2022 ≈ $15 476) the three parameters are solved exactly — the curve passes through the pivots by construction. This is geometry, not statistics, and the label says so: "exact through 3 lows".
— With 4+ enabled lows (three optional early-history slots: 2011, 2013, 2015 are provided) the indicator switches to a least-squares fit: a coarse log-spaced search over 250 candidate asymptote positions, followed by a 200-step linear refinement around the best candidate. The curve label then reports the number of points and the RMSE in log10 units — the fit quality is never hidden.

A fit is accepted only if b > 0 and the asymptote c lies before the earliest pivot — degenerate solutions are rejected and the curve simply doesn't draw.

3️⃣ Second independent hyperbola through cycle highs.

The same model is fitted to cycle tops (defaults: Nov 2013 ≈ $1 238, Dec 2017 ≈ $19 700, Nov 2021 ≈ $69 000, Oct 2025 ≈ $126 200 — four points, so LS fit with visible RMSE). A fifth, disabled slot exists only if you want to force the fit through your own future target; you never need it for the projection, because the future top is marked automatically at the crossing of the highs curve with the projected top date.

Why two curves: lows and highs decelerate at different rates. Fitting them independently (instead of offsetting one curve) lets the model express a narrowing channel without assuming its shape.

4️⃣ "Cycle × curve" intersection labels — the model's testable predictions.

At the projected bottom date the lows curve is evaluated: ◎ label with date ≈ price. At the projected top date the highs curve is evaluated: ◎ label with date ≈ price. These two points are the indicator's headline output — a date AND a price for each future turn, derived from two independent models. Both curves extend beyond their intersection as dashed lines (lows: default 10 years, highs: 5 years) to show the long-term trajectory.

5️⃣ Macro Fibonacci grids with a time-bounded 0.786–0.836 accumulation zone.

All enabled lows and highs are merged chronologically; every leg between two pivots of opposite type receives a grid (low→high = bull grid, high→low = bear grid; same-type neighbours are skipped). Levels are fully user-defined (default: 0, 0.236, 0.382, 0.5, 0.618, 0.786, 0.836, 0.886, 1; values > 1 add extensions).

Two non-standard options:
Log-scale interpolation: level price = 10^(log10(pA) + f × (log10(pB) − log10(pA))) — matches a fib tool drawn on a log chart. Off by default (arithmetic levels for a linear chart).
Reverse mode (default ON): ratio 0 sits at the END of the leg, so on a bull leg 0.618 is the classic retracement below the high.

The 0.786–0.836 zone of each bull leg is highlighted as a "BUY ZONE" box — and here is the original part: the box stretches in time from the leg start to the end date of the cycle the leg belongs to (the next projected cycle bottom). Depth from the fib model, deadline from the time model — the zone is a rectangle in (price × time), not just a price band.

6️⃣ Distribution zones tied to the cycle skeleton.

Every enabled high gets a "SELL ZONE" box spanning high ± sellPct (default 5% → from high × 0.95 to high × 1.05). The time span runs from the LATER of (a) the latest enabled low before that high or (b) the model's cycle bottom immediately preceding it — so a projected 2029 high starts its zone at the projected Oct-2026 bottom, not at a 2022 pivot. If no enabled high exists in the upcoming cycle, a projected sell zone is created automatically at the highs-curve × projected-date crossing (duplicate-guarded within half a cycle).

7️⃣ Bull-path projection — fractal replay of the previous bull, rescaled in log space.

The path for the NEXT bull phase (with defaults: 05 Oct 2026 → 03 Sep 2029) is drawn between two model-derived endpoints: start = lows curve at the projected bottom, end = highs curve at the following projected top. Two shapes:

Replay last bull (default): the log-price trajectory of the previous bull phase is recorded bar by bar (confirmed bars only, thinned to ≤ 400 samples for memory safety on intraday timeframes), then linearly rescaled: y(progress) = yStart + (ref(progress) − ref(0)) × (yEnd − yStart) / (ref(1) − ref(0)). The result keeps the timing character of the last cycle — early acceleration, mid-cycle chop, late blow-off — mapped onto the new endpoints.
Log-linear: a straight line on a log chart between the endpoints. The replay mode automatically falls back to log-linear if the reference phase covers less than 90% of the bull duration.

The path is explicitly labeled "◇ PROJECTED PATH (hypothetical)" — it is a scenario generator, not a forecast.

8️⃣ Corrections table — every macro drawdown since 2014, including the unfinished one.

The dashboard lists every completed high → following-low leg between enabled pivots since 2014 as a % drop (e.g. 2017–2018: −84%). If the latest pivot is a high with no low after it, the current correction is projected: measured from that high to the lows-curve price at the next model bottom, and marked "(proj.)" in accent color. You always see how the ongoing decline compares with history.

9️⃣ Full-transparency dashboard with a phase gauge and next-leg scenario PNL.

Four toggleable sections: Cycle (phase, day X / Y, ██████░░░░ progress gauge), Projection (top and bottom dates with days-left counters and curve prices, plus the hypothetical PNL of the next bull leg: (topCurve / bottomCurve − 1) × 100% and the × multiple), Corrections (see 8️⃣), Ranges (nearest upcoming buy range = the 0.786–0.836 zone prices; nearest sell range = the ±% zone around the next projected high). The footer states the calibration chart (INDEX:BTCUSD · W · linear scale, with a live ✓ when you're on it), a timeframe warning, and the sample-size caveat "⚠ Sample size: 3 cycles" — the model's biggest limitation is printed on the chart itself.

🔟 Efficient, tick-stable rendering.

All drawings (500+ polyline points, fib grids, boxes, dashboard) are anchored to bar-open times and first-bar curve fits — nothing changes within a bar. A redraw gate rebuilds them once per new bar instead of on every real-time tick, and both curve fits run exactly once on the first bar. The chart stays responsive even with all modules enabled.


📐 HOW IT WORKS — CALCULATION FLOW

Step 1 — Parse pivots: on the first bar, all enabled lows and highs are converted to (days-from-first-pivot, log10(price)) pairs.

Step 2 — Fit the curves: each set is fitted to log10(price) = a + b/(c − t) — exact solve for 3 points, two-stage least-squares search for 4+. Fit validity is checked (b > 0, asymptote before the data).

Step 3 — Phase every bar: calendar-time modulo against the anchor determines bull/bear phase, day-in-phase, and the timestamps of the current, next bottom and next top.

Step 4 — Evaluate intersections: the lows curve at the projected bottom date and the highs curve at the projected top date become the model's price targets.

Step 5 — Record the reference bull: during the anchor cycle's bull phase, confirmed closes are stored as (progress, log10 price) — the shape later replayed by the projection.

Step 6 — Draw (once per bar): turn lines and labels for N past and M future cycles, both hyperbolas with dashed extensions, fib grids per alternating pivot leg, buy/sell zone boxes, halving lines (2012 / 2016 / 2020 / 2024 solid, Apr 2028 dashed "(est.)"), the projected path, the dashboard and the watermark.

Step 7 — Alert: on confirmed bars, phase flips and the pre-turn countdown fire alert() calls in text or JSON format.


📖 HOW TO USE

🎯 Quick start:
1. Open the INDEX:BTCUSD chart, Weekly timeframe, regular (linear) price scale — the model is calibrated there, and the dashboard shows a ✓ when the symbol and timeframe match (the scale must be checked manually — Pine cannot detect it).
2. Add the indicator. The green/red background immediately shows the model's current phase; the dashboard shows the day count and progress gauge.
3. Find the two ◎ labels — the projected bottom (orange, lows curve) and the projected top (red, highs curve). These are the model's date + price coordinates for the next turns.
4. Check the yellow boxes: BUY ZONE (0.786–0.836 of the current bull leg, extended to the cycle end date) and SELL ZONE (±5% around each high).
5. Create ONE alert with condition "Any alert() function call" to receive flips and the pre-turn countdown.

👁️ Reading the chart:
— 🟢 Green background = model bull phase; 🔴 red = bear phase
— Solid green verticals = cycle bottoms; dashed red verticals = cycle tops; future turns are labeled ★ PROJECTED and drawn brighter
— 🟠 Orange curve = hyperbola through cycle lows (solid to the projected bottom, then dashed extension)
— 🔴 Red curve = hyperbola through cycle highs (solid to the projected top, then dashed extension)
— Small circles = the exact pivots each curve is built from
— ◎ labels = cycle × curve intersections with date, ≈ price, and fit info (point count + RMSE, or "exact through 3")
— Fib grids between macro pivots: solid edges (0 / 1), dashed 0.5, dotted intermediate levels, price + ratio labels on the right
— 🟡 Yellow boxes = BUY ZONE (0.786–0.836, time-bounded by the cycle end) and SELL ZONE (±% around highs; "(proj.)" = auto-generated at the projected top)
— ⛏ Grey verticals = halvings; the 2028 line is dashed and marked "(est.)"
— 🔵 Blue dashed path = hypothetical next-bull trajectory with its ◇ end label

📊 Dashboard fields:
Phase / Phase day / Progress: current model phase, day within it, and a 10-segment gauge
Proj. top / Proj. bottom: projected turn dates, days remaining, and the curve price at each date
Next leg PNL: hypothetical bottom→top move of the next bull leg in % and as a × multiple — a scenario, not a forecast
Corrections: every completed macro drawdown since 2014 (high → following low, %), plus the unfinished one projected to the curve bottom and marked (proj.)
Next buy range / Next sell range: the price boundaries of the nearest upcoming accumulation and distribution zones
— Footer: recommended chart check, timeframe warning, sample-size caveat, version

🔧 Tuning guide:
Curve doesn't draw: fewer than 3 pivots enabled, or the fit was rejected as degenerate — enable at least 3 lows (or highs) with sensible dates/prices.
You disagree with a pivot price: every pivot is an editable date + price input — correct it and both the curve and the fib grids rebuild instantly.
Want dates matching the actual price low: switch the anchor to 21 Nov 2022 (documented in the tooltip); the projected bottom moves to 19 Oct 2026.
Fib levels look wrong on a log chart: enable "Log-scale levels" (keep it OFF on the recommended linear chart).
Chart feels crowded: disable individual modules (grids, zones, halvings, projection) or dashboard sections — every block has its own switch.
Curious about 2030+: enable "Show 2nd projected cycle" for one more bottom/top pair (~Sep 2030 / ~Aug 2033) — off by default because those dates carry double model uncertainty.

💡 Trading ideas:
Accumulation planning: scale into the 0.786–0.836 BUY ZONE while the model is in its bear phase; the zone's right edge tells you the model's deadline.
Distribution planning: scale out inside the ±5% SELL ZONE as the projected top date approaches; the pre-alert (default 30 days) gives you a heads-up.
Scenario testing: move pivots, change phase lengths, or force High #5 to your own target and watch how the whole framework (curves, zones, PNL) responds — the model is a sandbox, not an oracle.


⚙️ KEY SETTINGS

⚙️ Cycle Model:
Anchor — cycle bottom (default 07 Nov 2022): date all phases are projected from; alternative 21 Nov 2022 documented in the tooltip
Bull phase length (default 1064 days) / Bear phase length (default 364 days): ≈ averages of the 3 completed cycles
Cycles to draw back (default 3) / forward (default 1): how many turn lines and labels are drawn
Show 2nd projected cycle (default off): one extra bottom/top pair with doubled uncertainty

🎨 Visual Settings:
Theme (Auto / Dark / Light): Auto detects from the chart background; all text colors adapt
Phase background, Cycle turn lines, Turn labels, Watermark: independent toggles with color inputs

📊 Dashboard:
— Position (4 corners), font size (Small–Huge; dividers render one step smaller), and per-section switches: Cycle / Projection / Corrections / Ranges

📈 Hyperbola — Lows:
— 3 main cycle lows (2015 / 2018 / 2022, on by default) + 3 optional early-history lows (2011 / 2013 / 2015) — each is a checkbox + date + price
Dashed extension (default 10 years), curve color, anchor-point markers

📉 Hyperbola — Highs:
— 4 cycle highs (2013 / 2017 / 2021 / 2025, on by default) + a spare projected slot (off), extension (default 5 years), curve color

🔢 Fibonacci Grids:
Bull grids (default on) / Bear grids (default off) with separate colors
Levels (default "0, 0.236, 0.382, 0.5, 0.618, 0.786, 0.836, 0.886, 1"; values > 1 = extensions)
Highlight 0.786–0.836 zone (default on), Log-scale levels (default off), Reverse (default on), level labels

Halvings: lines + labels toggles, color

🟡 Sell Zones: toggle, color, Zone size % from high (default 5%)

🔮 Price Projection: toggle, Path shape (Replay last bull / Log-linear), color

🔔 Alerts: master switch, Webhook JSON Format (default off), Pre-alert days (default 30)


🔔 ALERTS

— 🟢 CYCLE FLIP → BULL — model bottom date reached; payload: ticker, timeframe, price, next projected top date
— 🔴 CYCLE FLIP → BEAR — model top date reached; payload: ticker, timeframe, price, next projected bottom date
— ⏳ CYCLE TURN APPROACHING — fires once, N days (default 30) before the next projected turn; payload: turn type (TOP/BOTTOM), days left, date

All alerts fire on confirmed bars only (once per bar close) and support both human-readable text and JSON webhook payloads for bot integration. Create a single alert with condition "Any alert() function call".


⚠️ IMPORTANT NOTES

— 🚫 No repainting. The cycle phase is pure calendar-time math against a fixed anchor; the curves are fitted once from user-defined historical pivots; the reference bull shape is recorded from confirmed bars only; all alerts use bar-close frequency. Nothing in the model reads unconfirmed real-time data, so no line, zone or label moves after the fact.
— 📐 Sample size: 3 completed cycles. Every statistical claim in this model rests on three observations. The hyperbolic fits are geometry/regression over 3–6 points. Treat all projected dates and prices as reference scenarios with wide error bars — the dashboard says "Rhythm ≠ law" for a reason.
— 📏 Calibrated chart: INDEX:BTCUSD, Weekly, regular (linear) price scale. Exchange charts start later and distort early-history fits. Keep the fib "Log-scale levels" input OFF on a linear chart. The dashboard's ✓ confirms symbol and timeframe; the scale must be checked manually.
— ⚖️ Scope: this is a macro-cycle framework for Bitcoin. It produces no intraday entry signals, no stop placement, and no position sizing. The projected path is explicitly hypothetical.
— 🛠️ This is a cycle-analysis and scenario-visualization tool, not an automated trading bot. It provides projected turn dates, curve-based price references, and accumulation/distribution zones — trade decisions remain yours.
— 🌐 The script runs on any symbol and timeframe, but the model is designed for Bitcoin on Daily/Weekly charts — a dashboard warning appears on intraday timeframes.

Bitcoin Almanac · v1.5.2

כתב ויתור

המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.