PROTECTED SOURCE SCRIPT

Fair Value Trend Model [SiDec]

158
ABSTRACT

This pine script introduces the Fair Value Trend Model, an on-chart indicator for TradingView that constructs a continuously updating "fair-value" estimate of an asset's price via a logarithmic regression on historical data. Specifically, this model has been applied to Bitcoin (BTC) to fully grasp its fair value in the cryptocurrency market. Symmetric channel bands, defined by fixed percentage offsets around this central fair-value curve, provide a visual band within which normal price fluctuations may occur. Additionally, a short-term projection extends both the fair-value trend and its channel bands forward by a user-specified number of bars.

INTRODUCTION

Technical analysts frequently seek to identify an underlying equilibrium or "fair value" about which prices oscillate. Traditional approaches-moving averages, linear regressions in price-time space, or midlines-capture linear trends but often misrepresent the exponential or power-law growth patterns observable in many financial markets. The Fair Value Trend Model addresses this by performing an ordinary least squares (OLS) regression in log-space, fitting ln(Price) against ln(Days since inception). In practice, the primary application has been to Bitcoin, aiming to fully capture Bitcoin's underlying value dynamics.

The result is a curved trend line in regular (price-time) coordinates, reflecting Bitcoin's long-term compounding characteristics. Surrounding this fair-value curve, symmetric bands at user-specified percentage deviations serve as dynamic support and resistance levels. A simple linear projection extends both the central fair-value and its bands into the immediate future, providing traders with a heuristic for short-term trend continuation.

This exposition details:
  1. Data transformation: converting bar timestamps into days since first bar, then applying natural logarithms to both time and price.
  2. Regression mechanics: incremental (or rolling-window) accumulation of sums to compute the log-space fit parameters.
  3. Fair-value reconstruction: exponentiation of the regression output to yield a price-space estimate.
  4. Channel-band definition: establishing ±X% offsets around the fair-value curve and rendering them visually.
  5. Forecasting methodology: projecting both the fair-value trend and channel bands by extrapolating the most recent incremental change in price-space.
  6. Interpretation: how traders can leverage this model for trend identification, mean-reversion setups, and breakout analysis, particularly in Bitcoin trading.

Analysing the macro cycle on Bitcoin's monthly timeframe illustrates how the fair-value curve aligns with multi-year structural turning points.快照
DATA TRANSFORMATION AND NOTATION

1. Timestamp Baseline (t0)

Let t0 = timestamp of the very first bar on the chart (in milliseconds). Each subsequent bar has a timestamp ti, where ti ≥ t0.

2. Days Since Inception (d(t))

Define the “days since first bar” as

  d(t) = max(1, (t − t0) / 86400000.0)

Here, 86400000.0 represents the number of milliseconds in one day (1,000 ms × 60 seconds × 60 minutes × 24 hours). The lower bound of 1 ensures that we never compute ln(0).

3. Logarithmic Coordinates:

Given the bar’s closing price P(t), define:

  xi = ln( d(ti) )
  yi = ln( P(ti) )

Thus, each data point is transformed to (xi, yi) in log‐space.

REGRESSION FORMULATION

We assume a log‐linear relationship:

  yi = a + b·xi + εi

where εi is the residual error at bar i. Ordinary least squares (OLS) fitting minimizes the sum of squared residuals over N data points. Define the following accumulated sums:

  Sx = Σ [xi] for i = 1 to N
  Sy = Σ [yi] for i = 1 to N
  Sxy = Σ [xi·yi] for i = 1 to N
  Sx2 = Σ [xi^2] for i = 1 to N
  N = number of data points

The OLS estimates for b (slope) and a (intercept) are:

  b = ( N·Sxy − Sx·Sy ) / ( N·Sx2 − (Sx)^2 )
  a = ( Sy − b·Sx ) / N

All‐Time Versus Rolling‐Window Mode:

All-Time Mode:
  • Each new bar increments N by 1.
  • Update Sx ← Sx + xN, Sy ← Sy + yN, Sxy ← Sxy + xN·yN, Sx2 ← Sx2 + xN^2.
  • Recompute a and b using the formulas above on the entire dataset.

Rolling-Window Mode:
  • Fix a window length W. Maintain two arrays holding the most recent W values of {xi} and {yi}.
  • On each new bar N:

  1. Append (xN, yN) to the arrays; add xN, yN, xN·yN, xN^2 to the sums Sx, Sy, Sxy, Sx2.
  2. If the arrays’ length exceeds W, remove the oldest point (xN−W, yN−W) and subtract its contributions from the sums.
  3. Update N_roll = min(N, W).
  4. Compute b and a using N_roll, Sx, Sy, Sxy, Sx2 as above.

This incremental approach requires only O(1) operations per bar instead of recomputing sums from scratch, making it computationally efficient for long time series.

FAIR‐VALUE RECONSTRUCTION

Once coefficients (a, b) are obtained, the regressed log‐price at time t is:

  ŷ(t) = a + b·ln( d(t) )

Mapping back to price space yields the “fair‐value”:

  F(t) = exp( ŷ(t) )
     = exp( a + b·ln( d(t) ) )
     = exp(a) · [ d(t) ]^b

In other words, F(t) is a power‐law function of “days since inception,” with exponent b and scale factor C = exp(a). Special cases:
  • If b = 1, F(t) = C · d(t), which is an exponential function in original time.
  • If b > 1, the fair‐value grows super‐linearly (accelerating compounding).
  • If 0 < b < 1, it grows sub‐linearly.
  • If b < 0, the fair‐value declines over time.

CHANNEL‐BAND DEFINITION

To visualise a “normal” range around the fair‐value curve F(t), we define two channel bands at fixed percentage offsets:

1. Upper Channel Band

  U(t) = F(t) · (1 + α_upper)

where α_upper = (Channel Band Upper %) / 100.

2. Lower Channel Band

  L(t) = F(t) · (1 − α_lower)

where α_lower = (Channel Band Lower %) / 100.

For example, default values of 50% imply α_upper = α_lower = 0.50, so:

  U(t) = 1.50 · F(t)
  L(t) = 0.50 · F(t)

When “Show FV Channel Bands” is enabled, both U(t) and L(t) are plotted in a neutral grey, and a semi‐transparent fill is drawn between them to emphasise the channel region.

SHORT‐TERM FORECAST PROJECTION

To extend both the fair‐value and its channel bands M bars into the future, the model uses a simple constant‐increment extrapolation in price space. The procedure is:

1. Compute Recent Increments

Let

  F_prev = F( t_{N−1} )
  F_curr = F( t_N )

Then define the per‐bar change in fair‐value:

  ΔF = F_curr − F_prev

Similarly, for channel bands:

  U_prev = U( t_{N−1} ), U_curr = U( t_N ), ΔU = U_curr − U_prev
  L_prev = L( t_{N−1} ), L_curr = L( t_N ), ΔL = L_curr − L_prev

2. Forecasted Values After M Bars

Assuming the same per‐bar increments continue:

  F_future = F_curr + M · ΔF
  U_future = U_curr + M · ΔU
  L_future = L_curr + M · ΔL

These forecasted values produce dashed lines on the chart:
  • A dashed segment from (bar_N, F_curr) to (bar_{N+M}, F_future).
  • Dashed segments from (bar_N, U_curr) to (bar_{N+M}, U_future), and from (bar_N, L_curr) to (bar_{N+M}, L_future).

Forecasted channel bands are rendered in a subdued grey to distinguish them from the current solid bands. Because this method does not re‐estimate regression coefficients for future t > t_N, it serves as a quick visual heuristic of trend continuation rather than a precise statistical forecast.

MATHEMATICAL SUMMARY

Summarising all key formulas:

1. Days Since Inception

  d(t_i) = max( 1, ( t_i − t0 ) / 86400000.0 )
  x_i = ln( d(t_i) )
  y_i = ln( P(t_i) )

2. Regression Summations (for i = 1..N)

  Sx = Σ [ x_i ]
  Sy = Σ [ y_i ]
  Sxy = Σ [ x_i · y_i ]
  Sx2 = Σ [ x_i^2 ]
  N = number of data points (or N_roll if using rolling‐window)

3. OLS Estimator

  b = ( N · Sxy − Sx · Sy ) / ( N · Sx2 − (Sx)^2 )
  a = ( Sy − b · Sx ) / N

4. Fair‐Value Computation

  ŷ(t) = a + b · ln( d(t) )
  F(t) = exp( ŷ(t) ) = exp(a) · [ d(t) ]^b

5. Channel Bands

  U(t) = F(t) · (1 + α_upper)
  L(t) = F(t) · (1 − α_lower)

with α_upper = (Channel Band Upper %) / 100, α_lower = (Channel Band Lower %) / 100.

6. Forecast Projection

  ΔF = F_curr − F_prev
  F_future = F_curr + M · ΔF

  ΔU = U_curr − U_prev
  U_future = U_curr + M · ΔU

  ΔL = L_curr − L_prev
  L_future = L_curr + M · ΔL

IMPLEMENTATION CONSIDERATIONS

1. Time Precision
  • Timestamps are recorded in milliseconds. Dividing by 86400000.0 yields days with fractional precision.
  • For the very first bar, d(t) = 1 ensures x = ln(1) = 0, avoiding an undefined logarithm.

2. Incremental Versus Sliding Summation
  • All‐Time Mode: Uses persistent scalar variables (Sx, Sy, Sxy, Sx2, N). On each new bar, add the latest x and y contributions to the sums.
  • Rolling‐Window Mode: Employs fixed‐length arrays for {x_i} and {y_i}. On each bar, append (x_N, y_N) and update sums; if array length exceeds W, remove the oldest element and subtract its contribution from the sums. This maintains exact sums over the most recent W data points without recomputing from scratch.

3. Numerical Robustness
  • If the denominator N·Sx2 − (Sx)^2 equals zero (e.g., all x_i identical, as when only one day has passed), then set b = 0 and a = Sy / N. This produces a constant fair‐value F(t) = exp(a).
  • Enforcing d(t) ≥ 1 avoids attempts to compute ln(0).

4. Plotting Strategy
  • The fair‐value line F(t) is plotted on each new bar. Its color depends on whether the current price P(t) is above or below F(t): a “bullish” color (e.g., green) when P(t) ≥ F(t), and a “bearish” color (e.g., red) when P(t) < F(t).
  • The channel bands U(t) and L(t) are plotted in a neutral grey when enabled; otherwise they are set to “not available” (no plot).
  • A semi‐transparent fill is drawn between U(t) and L(t). Because the fill function is executed at global scope, it is automatically suppressed if either U(t) or L(t) is not plotted (na).

5. Forecast Line Management
  • Each projection line (for F, U, and L) is created via a persistent line object. On successive bars, the code updates the endpoints of the same line rather than creating a new one each time, preserving chart clarity.
  • If forecasting is disabled, any existing projection lines are deleted to avoid cluttering the chart.

INTERPRETATION AND APPLICATIONS

1. Trend Identification
  • The fair‐value curve F(t) represents the best‐fit long‐term trend under the assumption that ln(Price) scales linearly with ln(Days since inception). By capturing power‐law or exponential patterns, it can more accurately reflect underlying compounding behavior than simple linear regressions.
  • When actual price P(t) lies above U(t), it may be considered “overextended” relative to its long‐term trend; when price falls below L(t), it may be deemed “oversold.” These conditions can signal potential mean‐reversion or breakout opportunities.

2. Mean‐Reversion and Breakout Signals
  • If price re‐enters the channel after touching or slightly breaching L(t), some traders interpret this as a mean‐reversion bounce and consider initiating a long position.
  • Conversely, a sustained move above U(t) can indicate strong upward momentum and a possible bullish breakout. Traders often seek confirmation (e.g., price remaining above U(t) for multiple bars, rising volume, or corroborating momentum indicators) before acting.

3. Rolling Versus All‐Time Usage
  • All‐Time Mode: Captures the entire dataset since inception, focusing on structural, long‐term trends. It is less sensitive to short‐term noise or volatility spikes.
  • Rolling‐Window Mode: Restricts the regression to the most recent W bars, making the fair‐value curve more responsive to changing market regimes, sudden volatility expansions, or fundamental shifts. Traders who wish to align the model with local behaviour often choose W so that it approximates a market cycle length (e.g., 100–200 bars on a daily chart).

4. Channel Percentage Selection
  • A wider band (e.g., ±50 %) accommodates larger price swings, reducing the frequency of breaches but potentially delaying actionable signals.
  • A narrower band (e.g., ±10 %) yields more frequent “overbought/oversold” alerts but may produce more false signals during normal volatility. It is advisable to calibrate the channel width to the asset’s historical volatility regime.

5. Forecast Cautions
  • The short‐term projection assumes that the last single‐bar increment ΔF remains constant for M bars. In reality, trend acceleration or deceleration can occur, rendering the linear forecast inaccurate.
  • As such, the forecast serves as a visual guide rather than a statistically rigorous prediction. It is best used in conjunction with other momentum, volume, or volatility indicators to confirm trend continuation or reversal.

LIMITATIONS AND CONSIDERATIONS

1. Power‐Law Assumption
  • By fitting ln(P) against ln(d), the model posits that P(t) ≈ C · [d(t)]^b. Real markets may deviate from a pure power‐law, especially around significant news events or structural regime changes. Temporary misalignment can occur.

2. Fixed Channel Width
  • Markets exhibit heteroskedasticity: volatility can expand or contract unpredictably. A static ±X % band does not adapt to changing volatility. During high‐volatility periods, a fixed ±50 % may prove too narrow and be breached frequently; in unusually calm periods, it may be excessively broad, masking meaningful variations.

3. Endpoint Sensitivity
  • Regression‐based indicators often display greater curvature near the most recent data, especially under rolling‐window mode. This can create sudden “jumps” in F(t) when new bars arrive, potentially confusing users who expect smoother behaviour.

4. Forecast Simplification
  • The projection does not re‐estimate regression slope b for future times. It only extends the most recent single‐bar change. Consequently, it should be regarded as an indicative extension rather than a precise forecast.

PRACTICAL IMPLEMENTATION ON TRADINGVIEW

1 Adding the Indicator
  • In TradingView’s “Indicators” dialog, search for Fair Value Trend Model or visit my profile, under "scripts" add it to your chart.
  • Add it to any chart (e.g., BTCUSD, AAPL, EURUSD) to see real‐time computation.

2. Configuring Inputs
  • Show Forecast Line: Toggle on or off the dashed projection of the fair‐value.
  • Forecast Bars: Choose M, the number of bars to extend into the future (default is often 30).
  • Forecast Line Colour: Select a high‐contrast colour (e.g., yellow).
  • Bullish FV Colour / Bearish FV Colour: Define the colour of the fair‐value line when price is above (e.g., green) or below it (e.g., red).
  • Show FV Channel Bands: Enable to display the grey channel bands around the fair‐value.
  • Channel Band Upper % / Channel Band Lower %: Set α_upper and α_lower as desired (defaults of 50 % create a ±50 % envelope).
  • Use Rolling Window?: Choose whether to restrict the regression to recent data.
  • Window Bars: If rolling mode is enabled, designate W, the number of bars to include.

3. Visual Output
  • The central curve F(t) appears on the price chart, coloured green when P(t) ≥ F(t) and red when P(t) < F(t).
  • If channel bands are enabled, the chart shows two grey lines U(t) and L(t) and a subtle shading between them.
  • If forecasting is active, dashed extensions of F(t), U(t), and L(t) appear, projecting forward by M bars in neutral hues.

CONCLUSION

The Fair Value Trend Model furnishes traders with a mathematically principled estimate of an asset’s equilibrium price curve by fitting a log‐linear regression to historical data. Its channel bands delineate a normal corridor of fluctuation based on fixed percentage offsets, while an optional short‐term projection offers a visual approximation of trend continuation.

By operating in log‐space, the model effectively captures exponential or power‐law growth patterns that linear methods overlook. Rolling‐window capability enables responsiveness to regime shifts, whereas all‐time mode highlights broader structural trends. Nonetheless, users should remain mindful of the model’s assumptions—particularly the power‐law form and fixed band percentages—and employ the forecast projection as a supplemental guide rather than a standalone predictor.

When combined with complementary indicators (e.g., volatility measures, momentum oscillators, volume analysis) and robust risk management, the Fair Value Trend Model can enhance market timing, mean‐reversion identification, and breakout detection across diverse trading environments.

REFERENCES
  1. Draper, N. R., & Smith, H. (1998). Applied Regression Analysis (3rd ed.). Wiley.
  2. Tsay, R. S. (2014). Introductory Time Series with R (2nd ed.). Springer.
  3. Hull, J. C. (2017). Options, Futures, and Other Derivatives (10th ed.). Pearson.

These references provide background on regression, time-series analysis, and financial modeling.

免責聲明

這些資訊和出版物並不意味著也不構成TradingView提供或認可的金融、投資、交易或其他類型的意見或建議。請在使用條款閱讀更多資訊。