# Moving Regression Prediction Bands

17837 lượt xem
Introducing the Moving Regression Prediction Bands indicator.

Here I aimed to combine the principles of traditional band indicators (such as Bollinger Bands ), regression channel and outlier detection methods. Its upper and lower bands define an interval in which the current price was expected to fall with a prescribed probability, as predicted by the previous-step result of the local polynomial regression (for the original Moving Regression script, see link below).

Algorithm
1. At every time step, the script performs local polynomial regression of the sample data within the lookback window specified by the Length input parameter.
2. The fitted polynomial is used to construct the Moving Regression time series as well as to extrapolate data, that is, to predict the next data point (MRPrediction).
3. The accuracy of local interpolation is estimated by means of the root-mean-square error (RMSE), that is, the deviation between the fitted polynomial and the observed values.
4. The MRPrediction and RMSE values calculated for the previous bar are then used to build the upper and lower bands, which I define as follows:

Upper Band = MRPrediction_prev + Multiplier*(RMSE_prev)
Lower Band = MRPrediction_prev - Multiplier*(RMSE_prev)

Here the Multiplier is a user-defined parameter that should be interpreted as a quantile in the standard normal distribution (the default value of 2.0 roughly corresponds to the 95% prediction interval).

To visualize the central line, the script offers the following options:
• Previous-Period MR Prediction: MRPrediction_prev time series from the above equation.
• MR: Conventional Moving Regression time series.
• Ribbon: “Previous-Period MR Prediction” and “MR” curves plotted together and colored according to their relative value (green if MR > Previous MR Prediction; red otherwise).

Usage
My original idea was to use the band breakouts as potential trading signals. For example, the price crossing above the upper band is a bullish signal, being a potential sign that price is gaining momentum and is out of a previously predicted trend. The exit signal could be the crossing under the lower band or under the central line.
However, be aware that it is an experimental indicator, so you might fin some better strategies.

Feel free to play around!
Phát hành các Ghi chú: added alerts conditions on Upper Band breakout, Lower Band breakdown and Central Line crossing (in both directions)

Mã nguồn mở

Với tinh thần của TradingView, tác giả đã xuất bản tập lệnh theo mã nguồn mở, vì thế trader có thể dễ dàng hiểu và tùy chỉnh được. Bạn có thể sử dụng miễn phí, hoặc tùy chỉnh lại mã đã được cấp phép bởi Quy tắc Chung. Bạn có thể sử dụng nó trên biểu đồ.

Bạn muốn sử dụng tập lệnh này trên biểu đồ?

## Bình luận

Phản hồi
This publication is now featured in our Editors' Picks: https://www.tradingview.com/scripts/editors-picks/ .
In the name of all TradingViewers, thank you for your valuable contribution to the community, and congrats!
Phản hồi
PineCoders
@PineCoders, Many thanks!
Phản hồi
Wow
Phản hồi
Hey @tbiktag! Check your messages if you don't mind!
Phản hồi
Kudos to you for this Great script. Very useful. Is there a way to make it execute little faster?
I have been getting "too long to execute errors"

Thanks.
Phản hồi
townsolan
@townsolan, That's true. It uses some relatively linear algebra. As soon as I see any technical possibility to reduce the computational time, I'll certainly do that. But so far it might be a good idea to use the code for higher timeframes (15m, hours, day - but surely not seconds).
Phản hồi
Thank you. I liked it.
Phản hồi
methecan
@methecan, thanks for the feedback!
Phản hồi
Super. Thx
Phản hồi
Hồ sơ Tùy chỉnh Hồ sơ Tài khoản và Thanh toán Giới thiệu bạn Xu Ticket Hỗ trợ của tôi Trung tâm Trợ giúp Tin nhắn riêng Trò chuyện Đăng xuất