Thursday, July 24, 2025

Bitcoin Power Law Line by JimSixOneEight (TradingView PineScript Indicator)

This is from https://x.com/JimSixOneEight/ (Jim618)...

**********

//@version=5

indicator("Bitcoin Power Law with 100-Day Extrapolation - @JimSixOneEight on Twitter ", overlay=true)


// Calculate days since Bitcoin genesis block (Jan 3, 2009)

days_since_genesis = (time - timestamp("UTC", 2009, 1, 3, 0, 0)) / (1000 * 60 * 60 * 24)


// Power law formula: P(t) = 2.88 * (t / 1000)^5.82

power_law = days_since_genesis > 1 ? 2.88 * math.pow(days_since_genesis / 1000, 5.82) : 0.0

plot(power_law, title="Power Law", color=color.blue, linewidth=2)


// Extrapolate 100 days into the future

days_future = days_since_genesis + 100

power_law_future = days_future > 1 ? 2.88 * math.pow(days_future / 1000, 5.82) : 0.0


// Determine bars to extend based on timeframe

// The goal is to represent 100 days regardless of the chart's timeframe.

// We need to calculate how many bars 100 days translates to for the current timeframe.

float bars_to_future_calc = 0.0


if timeframe.isdaily

    bars_to_future_calc := 100.0

else if timeframe.isweekly

    // 100 days / 7 days/week = approx 14.28 weeks

    bars_to_future_calc := 100.0 / 7.0

else if timeframe.ismonthly

    // 100 days / (approx 30.4375 days/month) = approx 3.28 months

    // We use 30.4375 as the average number of days in a month (365.25 / 12)

    bars_to_future_calc := 100.0 / 30.4375

else

    // For any other timeframe, we default to daily calculation for now or

    // you could add more specific calculations if needed.

    // As the original code defaulted to 100, we'll keep that as a fallback if no specific timeframe matches

    // This is less ideal but maintains original logic for unhandled timeframes.

    bars_to_future_calc := 100.0 / (timeframe.multiplier * (timeframe.isintraday ? 1.0 : 1.0 )) // This line needs more thought for truly general case beyond D, W, M.

    // For this specific 100-day extrapolation, we need to convert 100 days into the current chart's bar duration.

    // The simplest way for non-standard timeframes (beyond D, W, M) is to estimate.

    // Let's refine for a more general approach by calculating days per bar:

    float ms_per_bar = timeframe.in_seconds() * 1000.0

    float days_per_bar = ms_per_bar / (1000 * 60 * 60 * 24)

    if days_per_bar > 0

        bars_to_future_calc := 100.0 / days_per_bar

    else

        bars_to_future_calc := 100.0 // Fallback if days_per_bar is zero (shouldn't happen for valid timeframes)



// Draw extrapolation line on the last bar

var line future_line = na

// We want to update the line only on the last bar of the chart.

// The `barstate.islast` variable is the most robust way to do this.

if barstate.islast

    line.delete(future_line) // Delete the previous line to redraw

    future_bar_index = bar_index + math.round(bars_to_future_calc)

    future_line := line.new(bar_index, power_law, future_bar_index, power_law_future, color=color.green, style=line.style_dashed, width=2)


// Remarks:

// - Calculates Bitcoin price using power law model: P(t) = 2.88 * (t/1000)^5.82, where t is days since Jan 3, 2009.

// - Plots a blue line for the power law and a dashed green line for 100-day extrapolation.

// - Supports daily, weekly, and monthly timeframes by adjusting bar counts for extrapolation.

// - Uses 'barstate.islast' to ensure the extrapolation line is drawn and updated only on the most recent bar.

**********

No comments:

Post a Comment

Thank you!

Bitcoin Power Law Line by JimSixOneEight (TradingView PineScript Indicator)

This is from  https://x.com/JimSixOneEight/  (Jim618)... ********** //@version=5 indicator("Bitcoin Power Law with 100-Day Extrapolatio...