You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Pine Script中扩展Kaspa幂律趋势曲线至未来周期?

Solution to Extend Kaspa Power Law Curve to Future Years

The core issue with your original script is that it only calculates values for existing historical bars. To project the power law curve into the future, we need to explicitly compute values for future days and draw them using TradingView's polyline functionality. Here's the modified code with future projection capability:

//@version=5
indicator(title='Kaspa Power Law Bands', shorttitle='KAS Power Law', overlay=true)

// Customizable Inputs
start_date = input.time(timestamp(2022, 06, 01, 0, 0), title="Start Date for Day Count")
offset_days = input.int(205, title="Days Since Genesis to Start Date")
project_years = input.int(5, title="Project Years into Future")
a = input.float(-13.39, title="Power Law Coefficient (log10(a))")
b = input.float(4.2654, title="Power Law Exponent (b)")

// Calculate days since genesis for historical bars
days_since_start = request.security('CRYPTO:KASUSD', 'D', ta.barssince(time == start_date))
d = days_since_start + offset_days

// Power Law Curve for Historical Data
historical_y = math.pow(10, a) * math.pow(d, b)

// Plot Historical Curve
plot(historical_y, title='Historical Trend', color=color.gray, linewidth=2)

// Draw Future Projection
if ta.barstate.islast
    // Capture last known point
    last_bar_time = time
    last_bar_price = historical_y
    last_d_value = d
    
    // Calculate total days to project
    total_project_days = project_years * 365
    
    // Clean up existing projection to avoid duplicates
    var polyline future_projection = na
    if not na(future_projection)
        polyline.delete(future_projection)
    
    // Build array of future points
    var array<point> projection_points = array.new_point()
    array.push(projection_points, point.new(last_bar_time, last_bar_price))
    
    // Generate future points
    for day_offset = 1 to total_project_days
        future_d = last_d_value + day_offset
        future_price = math.pow(10, a) * math.pow(future_d, b)
        future_time = last_bar_time + day_offset * 86400000 // Add 1 day in milliseconds
        array.push(projection_points, point.new(future_time, future_price))
    
    // Draw dashed polyline for future projection
    future_projection = polyline.new(
        points=projection_points,
        color=color.blue,
        linewidth=2,
        style=line.style_dashed
    )

Key Modifications Explained:

  • Custom Inputs: Added adjustable parameters for project duration, power law coefficients, and start date to make the script flexible.
  • Future Point Calculation: On the last bar, we calculate the price for each future day using your power law formula, incrementing the day count from the last known value.
  • Polyline Drawing: Uses TradingView's polyline feature to connect all future points into a continuous dashed line extending from the end of the historical curve.

Usage:

  1. Adjust the Project Years input to set how far into the future you want to project (e.g., 10 for 10 years).
  2. Modify a and b values if you update your regression model later.
  3. The historical curve remains solid gray, while the future projection is a dashed blue line.

内容的提问来源于stack exchange,提问作者Abio Genesis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 13:31:23