Enhanced Local Polynomial Regression [Yosiet]

The Mathematical Explanation
The core idea of LPR is to fit a polynomial of degree p at each point x using weighted least squares. The weight of each data point decreases with its distance from x, controlled by a kernel function and a bandwidth parameter.
The general form of the local polynomial estimator is:
β̂(x) = argmin Σ K((Xi - x) / h) (Yi - β0 - β1(Xi - x) - ... - βp(Xi - x)^p)^2
Where:
β̂(x) is the vector of estimated coefficients
K is the kernel function
h is the bandwidth
Xi and Yi are the predictor and response variables
p is the degree of the polynomial
Our implementation uses the Epanechnikov kernel:
K(u) = 3/4 * (1 - u^2) for |u| ≤ 1, 0 otherwise
The Implementation
This script implements LPR for the easier way to interpret its values with the following key components:
- Input Parameters: Can adjust the lookback period, bandwidth, and polynomial degree.
- Kernel Function: The Epanechnikov kernel is used for weighting.
- LPR Function: Implements the core algorithm using matrix operations.
- Signal Generation: Generates buy/sell signals based on crossovers of smoothed price and LPR results.
How to Use
- Apply the indicator to your chart in TradingView.
- Adjust the input parameters:
- Lookback Period: Controls how many past bars are considered.
- Bandwidth: Affects the smoothness of the regression line.
- Polynomial Degree: Determines the complexity of the local fit.
- Signal Smoothing Length: Adjusts the responsiveness of buy/sell signals.
- Monitor buy/sell signals for potential trade entries.
Limitations
- Sensitivity to Parameters: The choice of bandwidth and polynomial degree significantly impacts the results.
- Lag: Like all trend-following indicators, LPR may lag behind rapid price movements.
- Edge Effects: The indicator may be less reliable at the edges of the data (recent bars).
Recommendations
- Parameter Optimization: Experiment with different lookback periods, bandwidths, and polynomial degrees to find the best fit for your trading style and timeframe.
- Combine with Other Indicators: Use LPR in conjunction with momentum oscillators or volume indicators for confirmation.
- Multiple Timeframes: Apply LPR on different timeframes to gain a more comprehensive view of the trend.
- Avoid Overfitting: Be cautious of using high polynomial degrees, as they may lead to overfitting on historical data.
- Consider Market Conditions: LPR works best in trending markets; be aware of its limitations in ranging or highly volatile conditions.
- Backtest Thoroughly: Always backtest strategies based on LPR across different market conditions before live trading.
Conclusion
Local Polynomial Regression offers a sophisticated approach to trend analysis in financial markets. By providing a flexible, adaptive trend line, it can help traders identify potential entry and exit points with greater precision than traditional moving averages. However, like all technical indicators, it should be used as part of a comprehensive trading strategy that includes proper risk management and consideration of fundamental factors.
if you have an strategy or idea and need to make it real through an indicator or trading bot, you can DM or comment
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.
Thông báo miễn trừ trách nhiệm
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Để truy cập nhanh vào biểu đồ, hãy thêm tập lệnh này vào mục yêu thích của bạn — tìm hiểu thêm tại đây.