PINE LIBRARY
Telah dikemas kini

CapitalCompassCore

350
Capital Compass Core

Capital Compass Core is the shared Pine Script framework for the Capital Compass ecosystem. It centralizes reusable calculations, state definitions, visual standards, market-context logic, risk logic, portfolio helpers, strategy utilities, panel functions, formatting tools, and alert infrastructure used across Capital Compass scripts.

The library is designed to keep Market Navigator, Tactical Navigator, Strategy Lab, Portfolio Compass, and future Capital Compass tools operating from the same definitions instead of maintaining duplicate implementations across multiple scripts.

Purpose

Capital Compass Core is infrastructure rather than a standalone trading indicator.

The library calculates and standardizes reusable logic. Consuming indicators and strategies remain responsible for user inputs, plots, fills, chart markers, alert conditions, strategy orders, and script-specific interpretation.

Core calculates and standardizes. The consuming script orchestrates and renders.

Core systems

Reusable functionality includes:

• EMA, SMA, RMA, WMA, VWMA, HMA, DEMA, TEMA, and VWAP
• Moving-average structure, compression, expansion, zones, crosses, and standardized MA hierarchy
• 20-SMA / 21-EMA Fast Trend Zone
• Ichimoku calculations
• Bollinger Bands
• ATR, relative volume, drawdown, price-shock, and volatility calculations
• SuperTrend and multi-SuperTrend agreement
• RSI/MFI/MACD momentum components and consolidated momentum states
• Market regime, risk, opportunity, and market-permission scoring
• Tactical market phases and transition states
• Market Navigator state aggregation
• Price structure, pivots, and regular divergence
• Asset-profile presets
• Portfolio allocation and deployment calculations
• Account-context helpers
• Position sizing, ATR stops, targets, trailing logic, reward/risk, R multiples, expectancy, and strategy-quality helpers
• Confirmed higher-timeframe data helpers
• Relative-strength calculations
• Alert-event routing and transition helpers
• JSON and text formatting
• Theme-aware panels, table cells, text, borders, fills, and semantic state backgrounds

State and color standard

Capital Compass uses a consistent semantic visual language:

• Green = bullish / favorable
• Red = bearish / unfavorable
• Orange = caution / transition / sideways / neutral / mixed
• Gray = inactive / unavailable / insufficient data
• Blue = informational / fast-trend reference
• Magenta = major structural reference

Moving-average identity colors are separate from directional state colors. This allows a moving average to retain a recognizable identity while optional Trend mode communicates bullish, bearish, or transitional conditions.

The standardized moving-average hierarchy includes:

8, 13, 20, 21, 34, 50, 55, 89, 100, and 200 periods.

Primary structural references:

• 20 / 21 = fast trend
• 50 / 55 = intermediate trend / caution zone
• 200 = major long-term structural reference

Capital Compass Core also provides theme-aware helpers derived from the active TradingView chart colors so consuming scripts can remain readable across light and dark chart themes.

Capital Compass ecosystem

Market Navigator
Long-term market condition, regime, risk, opportunity, portfolio context, and review.

Tactical Navigator
Tactical trend, momentum, transition, Fast Trend Zone, volatility, and market-phase analysis.

Strategy Lab
Research, hypothesis testing, backtesting support, position sizing, risk planning, and strategy evaluation.

Portfolio Compass
Portfolio allocation, deployment, account context, and long-term capital-management support.

Shared calculations should be imported from Capital Compass Core rather than independently duplicated inside each script.

Library usage

Import the library with:

[code]
import DrGetDown/CapitalCompassCore/1 as CC
[/code]

Examples of shared functionality include:

[code]
CC.ma(...)
CC.maColor(...)
CC.fastTrendZone(...)
CC.marketNavigatorState(...)
CC.tacticalPhase(...)
CC.momentumScore(...)
CC.stateColor(...)
CC.panelPos(...)
CC.strategyPlan(...)
[/code]

Published library versions are intentionally explicit. Consuming scripts should migrate only after a newer Core release has been compiled, tested, and validated.

Design principles

• Maintain one definition for shared calculations and state meanings.
• Separate market-state colors from moving-average identity colors.
• Keep reusable calculations in Core whenever technically practical.
• Keep script-specific interpretation and rendering in the consuming script.
• Avoid unnecessary duplicate or correlated calculations.
• Use confirmed higher-timeframe data where explicitly specified.
• Keep risk and position-sizing mathematics separate from actual strategy order placement.
• Preserve consistent panel placement, formatting, abbreviations, state meanings, and visual behavior across the ecosystem.
• Test significant shared changes before promoting them across dependent Capital Compass scripts.

Limitations

Capital Compass Core does not predict future prices and does not guarantee profitable trades or prevent losses.

Market regimes, momentum states, tactical phases, opportunity scores, risk scores, divergences, moving-average structures, and strategy statistics are analytical classifications based on supplied market data and configured assumptions. They should not be interpreted as guarantees of future performance.

Backtest statistics describe historical results and do not guarantee similar future results.

Portfolio, allocation, deployment, and position-sizing helpers provide mathematical and analytical context only. Actual decisions remain dependent on objectives, portfolio circumstances, risk tolerance, time horizon, liquidity needs, taxes, diversification, and independent research.

Version

Internal Core version: 1.0.0
TradingView library release: /1

Capital Compass
[ C.C. — C O R E ]

OBSERVE • DISCERN • PREPARE • ACT WISELY

Tuned to the signal. Anchored to the mission.
Nota Keluaran
v2

Added:
f_jsonEscape(value)
  Parameters:
    value (string)

Updated:
fastZoneCode(zoneStateValue)
  Fast Trend Zone code.
Positive = constructive location; negative = adverse location.
LOSS is more severe than persistent BELOW because it represents a fresh loss of the zone.
  Parameters:
    zoneStateValue (string)

tacticalPhaseCode(phaseValue)
  Tactical phase code.
Positive = constructive phase; zero = neutral base;
negative = caution / defensive deterioration.
  Parameters:
    phaseValue (string)

Updated:
tacticalMomentum(...)
Refined momentum state scoring for clearer constructive-to-adverse coding.

tacticalPhase(...)
Refined phase priority and classification logic for recovery, compression, expansion, pullback, weakening, and breakdown states.
Nota Keluaran
v3

Added:
jsonEscape(value)
  Parameters:
    value (string)

Removed:
f_jsonEscape(value)
Nota Keluaran
v4

Added:
timeframeLabel(tf)
  Human-friendly timeframe label shared by Capital Compass scripts.
Examples: 15 -> 15m, 60 -> 1H, 240 -> 4H, D -> 1D.
  Parameters:
    tf (simple string)

panelLabel3(pnlSize, compactText, normalText, wideText)
  Three-density panel label for Compact / Normal / Wide panels.
  Parameters:
    pnlSize (series PanelSize)
    compactText (string)
    normalText (string)
    wideText (string)

semanticBg(baseColor, transparency)
  Theme-adjusted semantic background from any Capital Compass color.
  Parameters:
    baseColor (color)
    transparency (int)

semanticText(baseColor, transparency)
  Readable text for theme-adjusted semantic panel backgrounds.
  Parameters:
    baseColor (color)
    transparency (int)

completedWeeklyMomentumPayload(oscillatorLen, macdFastLen, macdSlowLen, macdSigLen)
  Completed-week payload used by Market Navigator weekly context.
Intended to execute inside a weekly request.security() call.
  Parameters:
    oscillatorLen (simple int)
    macdFastLen (simple int)
    macdSlowLen (simple int)
    macdSigLen (simple int)

actionColor(action)
  Shared semantic color for Market Navigator review/event actions.
  Parameters:
    action (string)

shortAction(action)
  Mobile-first abbreviation for shared Capital Compass actions.
  Parameters:
    action (string)

eventCode(action)
  Stable machine event code for shared Capital Compass actions.
  Parameters:
    action (string)

shortMomentumPhase(phase)
  Compact momentum phase shared by notifications/panels.
  Parameters:
    phase (string)

structureColor(bull, bear, expanding, contracting, neutralColor)
  Semantic structure color shared by chart/panel consumers.
  Parameters:
    bull (bool)
    bear (bool)
    expanding (bool)
    contracting (bool)
    neutralColor (color)

alertMessage(alertFormat, readableMessage, jsonMessage)
  Selects a Capital Compass human-readable or JSON alert payload.
  Parameters:
    alertFormat (string)
    readableMessage (string)
    jsonMessage (string)

fmtInt(value)
  Parameters:
    value (int)

fmtSignedNum(value)
  Parameters:
    value (float)

fmtSignedPct(value)
  Parameters:
    value (float)

deltaColor(delta, higherIsBetter)
  Delta color where caller defines whether higher values are better.
  Parameters:
    delta (float)
    higherIsBetter (bool)

Penafian

Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.