OPEN-SOURCE SCRIPT
更新済 Bitcoin vs M2 Global Liquidity (Lead 3M) - Table Ticker

═══════════════════════════════════════════════════════════════
Bitcoin vs M2 Global Liquidity - Regression Indicator
═══════════════════════════════════════════════════════════════
TECHNICAL SPECS
• Pine Script v6
• Overlay: false (separate pane)
• Data sources: 5 M2 series + 4 FX pairs (request.security)
• Calculation: Rolling OLS linear regression with configurable lead
• Output: Regression line + ±1σ/±2σ confidence bands + R² ticker
CORE FUNCTIONALITY
Aggregates M2 money supply from 5 central banks (CN, US, EU, JP, GB),
converts to USD, applies time-lead, runs rolling linear regression
vs Bitcoin price, plots predicted value with confidence intervals.
CONFIGURABLE PARAMETERS
Input Controls:
• Lead Period: 0-365 days (default: 90)
• Lookback Window: 50-2000 bars (default: 750)
• Bands: Toggle ±1σ and ±2σ visibility
• Colors: BTC, M2, regression line, confidence zones
• Ticker: Position, size, colors, transparency
Advanced Settings:
• Table display: R², lead, M2 total, country breakdown (%)
• Ticker customization: 9 position options, 6 text sizes
• Border: Width 0-10px, color, outline-only mode
DATA AGGREGATION
Sources (via request.security):
• ECONOMICS:CNM2, USM2, EUM2, JPM2, GBM2
• FX_IDC:CNYUSD, JPYUSD (others: FX:EURUSD, GBPUSD)
• Conversion: All M2 → USD → Sum / 1e12 (trillions)
REGRESSION ENGINE
• Arrays: m2Array, btcArray (dynamic sizing, auto-trim)
• Window: Rolling (lookbackPeriod bars)
• Lead: Time-shift via array indexing (i + leadPeriodDays)
• Calc: Manual OLS (covariance/variance), no built-in ta functions
• Outputs: slope, intercept, r2, stdResiduals
CONFIDENCE BANDS
±1σ and ±2σ calculated from standard deviation of residuals.
Fill zones between upper/lower bounds with configurable transparency.
ALERTS
5 pre-configured alertcondition():
• Divergence > 15%
• Price crosses ±1σ bands (up/down)
• Price crosses ±2σ bands (up/down)
TICKER TABLE
Dynamic table.new() with 9 rows:
• R² value (4 decimals)
• Lead period (days + months)
• M2 Global total (trillions USD)
• Country breakdown: CN, US, EU, JP, GB (absolute + %)
• Optional: Hide/show M2 details
VISUAL CUSTOMIZATION
All plot() elements support:
• Color picker inputs (group="Couleurs")
• Line width: 1-3px
• Transparency: 0-100% for zones
• Offset: M2 plot has +leadPeriodDays offset option
PERFORMANCE
• Max arrays size: lookbackPeriod + leadPeriodDays + 200
• Calculations: Only when array.size >= lookbackPeriod + leadPeriodDays
• Table update: barstate.islast (once per bar)
• Request.security: gaps_off mode
CODE STRUCTURE
1. Inputs (lines 7-54)
2. Data fetch (lines 56-76)
3. M2 aggregation (line 78)
4. Array management (lines 84-95)
5. Regression calc (lines 97-172)
6. Prediction + bands (lines 174-183)
7. Plots (lines 185-199)
8. Ticker table (lines 201-236)
9. Alerts (lines 238-246)
DEPENDENCIES
None. Pure Pine Script v6. No external libraries.
LIMITATIONS
• Daily timeframe recommended (1D)
• Requires 750+ bars history for optimal calculation
• M2 data availability: TradingView ECONOMICS feed
• Max lines: 500 (declared in indicator())
CUSTOMIZATION EXAMPLES
• Shorter lookback (200d): More reactive, lower R²
• Longer lookback (1500d): More stable, regime mixing
• No bands: Set showBands=false for clean view
• Different lead: Test 60d, 120d for sensitivity analysis
TECHNICAL NOTES
• Manual OLS implementation (no ta.linreg)
• Array-based lead application (not plot offset)
• M2 values stored in trillions (/ 1e12) for readability
• Residuals array cleared/rebuilt each calculation
OPEN SOURCE
Code fully visible. Modify, fork, analyze freely.
No hidden calculations. No proprietary data.
VERSION
1.0 | November 2025 | Pine Script v6
═══════════════════════════════════════════════════════════════
Bitcoin vs M2 Global Liquidity - Regression Indicator
═══════════════════════════════════════════════════════════════
TECHNICAL SPECS
• Pine Script v6
• Overlay: false (separate pane)
• Data sources: 5 M2 series + 4 FX pairs (request.security)
• Calculation: Rolling OLS linear regression with configurable lead
• Output: Regression line + ±1σ/±2σ confidence bands + R² ticker
CORE FUNCTIONALITY
Aggregates M2 money supply from 5 central banks (CN, US, EU, JP, GB),
converts to USD, applies time-lead, runs rolling linear regression
vs Bitcoin price, plots predicted value with confidence intervals.
CONFIGURABLE PARAMETERS
Input Controls:
• Lead Period: 0-365 days (default: 90)
• Lookback Window: 50-2000 bars (default: 750)
• Bands: Toggle ±1σ and ±2σ visibility
• Colors: BTC, M2, regression line, confidence zones
• Ticker: Position, size, colors, transparency
Advanced Settings:
• Table display: R², lead, M2 total, country breakdown (%)
• Ticker customization: 9 position options, 6 text sizes
• Border: Width 0-10px, color, outline-only mode
DATA AGGREGATION
Sources (via request.security):
• ECONOMICS:CNM2, USM2, EUM2, JPM2, GBM2
• FX_IDC:CNYUSD, JPYUSD (others: FX:EURUSD, GBPUSD)
• Conversion: All M2 → USD → Sum / 1e12 (trillions)
REGRESSION ENGINE
• Arrays: m2Array, btcArray (dynamic sizing, auto-trim)
• Window: Rolling (lookbackPeriod bars)
• Lead: Time-shift via array indexing (i + leadPeriodDays)
• Calc: Manual OLS (covariance/variance), no built-in ta functions
• Outputs: slope, intercept, r2, stdResiduals
CONFIDENCE BANDS
±1σ and ±2σ calculated from standard deviation of residuals.
Fill zones between upper/lower bounds with configurable transparency.
ALERTS
5 pre-configured alertcondition():
• Divergence > 15%
• Price crosses ±1σ bands (up/down)
• Price crosses ±2σ bands (up/down)
TICKER TABLE
Dynamic table.new() with 9 rows:
• R² value (4 decimals)
• Lead period (days + months)
• M2 Global total (trillions USD)
• Country breakdown: CN, US, EU, JP, GB (absolute + %)
• Optional: Hide/show M2 details
VISUAL CUSTOMIZATION
All plot() elements support:
• Color picker inputs (group="Couleurs")
• Line width: 1-3px
• Transparency: 0-100% for zones
• Offset: M2 plot has +leadPeriodDays offset option
PERFORMANCE
• Max arrays size: lookbackPeriod + leadPeriodDays + 200
• Calculations: Only when array.size >= lookbackPeriod + leadPeriodDays
• Table update: barstate.islast (once per bar)
• Request.security: gaps_off mode
CODE STRUCTURE
1. Inputs (lines 7-54)
2. Data fetch (lines 56-76)
3. M2 aggregation (line 78)
4. Array management (lines 84-95)
5. Regression calc (lines 97-172)
6. Prediction + bands (lines 174-183)
7. Plots (lines 185-199)
8. Ticker table (lines 201-236)
9. Alerts (lines 238-246)
DEPENDENCIES
None. Pure Pine Script v6. No external libraries.
LIMITATIONS
• Daily timeframe recommended (1D)
• Requires 750+ bars history for optimal calculation
• M2 data availability: TradingView ECONOMICS feed
• Max lines: 500 (declared in indicator())
CUSTOMIZATION EXAMPLES
• Shorter lookback (200d): More reactive, lower R²
• Longer lookback (1500d): More stable, regime mixing
• No bands: Set showBands=false for clean view
• Different lead: Test 60d, 120d for sensitivity analysis
TECHNICAL NOTES
• Manual OLS implementation (no ta.linreg)
• Array-based lead application (not plot offset)
• M2 values stored in trillions (/ 1e12) for readability
• Residuals array cleared/rebuilt each calculation
OPEN SOURCE
Code fully visible. Modify, fork, analyze freely.
No hidden calculations. No proprietary data.
VERSION
1.0 | November 2025 | Pine Script v6
═══════════════════════════════════════════════════════════════
リリースノート
default setting: 750 lookback Period --> 500オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。