如何在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
polylinefeature to connect all future points into a continuous dashed line extending from the end of the historical curve.
Usage:
- Adjust the
Project Yearsinput to set how far into the future you want to project (e.g., 10 for 10 years). - Modify
aandbvalues if you update your regression model later. - The historical curve remains solid gray, while the future projection is a dashed blue line.
内容的提问来源于stack exchange,提问作者Abio Genesis
相关产品推荐
相关产品推荐

