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.

**********

Monday, July 21, 2025

Bitcoin Power Law Divergence Banana Zone (%) by JimSixOneEight (TradingView PineScript Indicator) Jim618

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

**********

//@version=6
indicator("Bitcoin Power Law Divergence Banana Zone (%)", overlay=false)

//Bitcoin Power Law Divergence - JIM SIX ONE EIGHT - FREE, OPEN SOURCE, Just link to : https://x.com/JimSixOneEight

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

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

divergence_percent = 0.0
if close > 0
    divergence_percent := ((close - power_law) / close) * 100


plot(divergence_percent, "Price Divergence (%)", color.purple, 2)

hline(0, "Zero Line", color.gray, hline.style_dashed)

// Define transparent colors for background fills
// Transparency is the 4th parameter (0-255, where 0 is fully transparent, 255 is fully opaque)
color_bg_red_60_80 = color.rgb(255, 100, 100, 50) // Light red for 60-80% band
color_bg_red_80_100 = color.rgb(200, 0, 0, 50)   // Medium red for 80-100% band
color_bg_red_above_100 = color.rgb(150, 0, 0, 50) // Dark red for above 100%

color_bg_green_60_80 = color.rgb(100, 255, 100, 50) // Light green for -60 to -80% band
color_bg_green_80_100 = color.rgb(0, 200, 0, 50)   // Medium green for -80 to -100% band
color_bg_green_below_100 = color.rgb(0, 150, 0, 50) // Dark green for below -100%

// Plot horizontal lines and store their IDs for filling
id_h60 = hline(60, "+60% Line", color.rgb(255, 50, 50), hline.style_solid)
id_h80 = hline(80, "+80% Line", color.rgb(200, 0, 0), hline.style_solid)
id_h100 = hline(100, "+100% Line", color.rgb(150, 0, 0), hline.style_solid)
id_h_top = hline(150, "", color.new(na, 100), display=display.none) // An invisible upper boundary for the top fill

id_h_minus60 = hline(-60, "-60% Line", color.rgb(50, 255, 50), hline.style_solid)
id_h_minus80 = hline(-80, "-80% Line", color.rgb(0, 200, 0), hline.style_solid)
id_h_minus100 = hline(-100, "-100% Line", color.rgb(0, 150, 0), hline.style_solid)
id_h_bottom = hline(-150, "", color.new(na, 100), display=display.none) // An invisible lower boundary for the bottom fill


// Fill between the fixed horizontal lines
// Positive zones
fill(id_h60, id_h80, color=color_bg_red_60_80, title="Fill 60-80%")
fill(id_h80, id_h100, color=color_bg_red_80_100, title="Fill 80-100%")
fill(id_h100, id_h_top, color=color_bg_red_above_100, title="Fill >100%") // Fill from 100% up to an arbitrary high point

// Negative zones
fill(id_h_minus60, id_h_minus80, color=color_bg_green_60_80, title="Fill -60 to -80%")
fill(id_h_minus80, id_h_minus100, color=color_bg_green_80_100, title="Fill -80 to -100%")
fill(id_h_minus100, id_h_bottom, color=color_bg_green_below_100, title="Fill <-100%") // Fill from -100% down to an arbitrary low point

**********

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...