BTCUSD Price prediction based on central bank liquidity
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © luca_badoer

//@version=5
indicator('BTCUSD Price prediction based on central bank liquidity', overlay=true)

// Set the coefficients and intercept from the Python regression

scale_factor = 1e30

slope_0 = 0.00000000
slope_1 = 9.02528279e-34 * scale_factor
slope_2 = -1.20534089e-40 * scale_factor
slope_3 = -2.61440807e-33 * scale_factor
slope_4 = -3.85657386e-26 * scale_factor
slope_5 = 3.61867348e-33 * scale_factor
intercept = 233.62774698 * scale_factor

// Calculate the market liquidity using the formula you provided
market_liquidity = (request.security(symbol='FRED:WALCL', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) + request.security(symbol='FRED:JPNASSETS', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) * request.security(symbol='JPYUSD', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) + request.security(symbol='FRED:ECBASSETSW', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) * request.security(symbol='EURUSD', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) + request.security(symbol='CNCBBS', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) * request.security(symbol='FX_IDC:CNYUSD', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) - request.security(symbol='FRED:RRPONTSYD', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close) - request.security(symbol='FRED:WTREGEN', timeframe=timeframe.period, lookahead=barmerge.lookahead_on, expression=close)) / 1000000

// Calculate the potential BTCUSD price based on the market liquidity and regression coefficients
potential_btcusd_price = intercept + slope_1 * market_liquidity + slope_2 * math.pow(market_liquidity, 2) + slope_3 * math.pow(market_liquidity, 3) + slope_4 * math.pow(market_liquidity, 4) + slope_5 * math.pow(market_liquidity, 5)

potential_btcusd_price_scaled = potential_btcusd_price / scale_factor

// Calculate the upper and lower bounds for the confidence intervals

stdev = 4903.59406564

z_score = 1.96 // 95% confidence interval
conf_upper = potential_btcusd_price_scaled + z_score * stdev
conf_lower = math.max(potential_btcusd_price_scaled - z_score * stdev, 0) // limit lower bound of price to $0

// Plot the potential BTCUSD price as a line on the chart
color = color.rgb(243, 33, 72)
color2 = color.rgb(54, 243, 33)

plot(potential_btcusd_price_scaled, 'Potential BTCUSD Price', color=color.new(color.orange, 0), linewidth=2)
//plot(conf_upper, "Upper Bound", color=color, linewidth=1, style=plot.style_linebr)
//plot(conf_lower, "Lower Bound", color=color, linewidth=1, style=plot.style_linebr)

// Fill the area between the lines
fill_color = color.new(color, 90) // 80% transparency
upper_line = plot(conf_upper, "Upper Bound", color=color, linewidth=1, style=plot.style_linebr)
lower_line = plot(conf_lower, "Upper Bound", color=color2, linewidth=1, style=plot.style_linebr)
fill(upper_line, lower_line, color=fill_color)
