alexgrover

Quadratic Regression

Fit a quadratic polynomial (parabola) to the last length data points by minimizing the sum of squares between the data and the fitted results. The script can extrapolate the results in the future and can also display the R-squared of the model. Note that this script is subject to some limitations (more in the "Notes" section).

Settings

  • Length : Number of data points to use as input.
  • Offset : Determine the number of past fitted values to be displayed, if 0 only the extrapolated values are displayed, if 55 only the past fitted values are displayed.
  • Src : Input data of the indicator
  • Show R2 : Determine if the value of the R-squared must be displayed, by default true.

    Usage

    When the underlying trend in the price is not linear, we might use more advanced models to estimate it, this is where using a higher-degree regression model might be required, as such a quadratic model (second-degree) is appropriate when the underlying trend is parabolic.


    Here we can see that the quadratic regression (in blue) offer a better fit than a linear one.

    Another advantage of the quadratic regression is that a linear one will always have the same direction, that's not the case with the quadratic regression and as such, it is possible to forecast reversals.


    Above a linear regression (in red) and two quadratic regression (in blue) with both length = 54. Note that for the sake of clarity, the above image uses a quadratic regression to show all the past fitted values and another one to show all the forecasted values.

    The R-Squared is also extremely useful when it comes to measuring the accuracy of the model, with values closer to 1 indicating that the model is appropriate, and thus suggesting that the underlying trend in the price is parabolic. The R-squared can also measure the strength of the trend.

    Notes

    The script uses the function line.new, as such only a maximum of 54 observations are displayed, getting more observations can be done by using an additional quadratic regression like we did in the previous section. Another thing is that line.new use xloc.bar_time, as such it is possible to observe some errors with the displayed results of the indicator, such as:


    This will happen when applying the indicator to symbols with session breaks, I apologize for this inconvenience and I'll try to find solutions. Note however that the indicator will work perfectly on cryptos.

    Summary

    That's an indicator I really wanted to make, even if it is important to note that such models are rarely useful in stock markets, however it is more than possible to create a quadratic regression (with severe limitations) with pinescript.

    Today I turn 21, while I should be celebrating I still wanted to share something with the community, it's also some kind of present to myself that tells me that I am a bit better at using pinescript than last year, and I am glad I could progress (instead of regress, regression, got it?). Thx a lot for reading!
ลบออกจากสคริปส์โปรด เพิ่มเข้าไปในสคริปส์โปรด
« Je suis las des cruautés de mes semblables, qui ne sont pas mes pareils.

« Je prendrai l’essor et je m’envolerai vers la mer.

« Je connaîtrai le goût des brises du large. J’entendrai les grands cris de la tempête.

ความคิดเห็น

Happy B-Day, Alex! 🎁✨

There are a lot of pinescripters out there, with many good ideas.....but you are the MASTER! 💚......Damn! 😅
Thank you sooooo much for all the absolutely brilliant, super well documented, beautiful less coded, perfectly written, ultimate pinescript codes, published in such a high frequenz.

So..... Ladies & Gentlemann! 🎉

STANDING OVATIONS 👏🏼👏🏼👏🏼 for @alexgrover
+4 ตอบกลับ
@iflostio, True !
ตอบกลับ
Wish you a happy birthday. Thanks for sharing the great work.
+2 ตอบกลับ
GREAT WORK BRO. KEEP UP. THANKS YOU.
+1 ตอบกลับ
This one is something I would like to have and it is really worth saying a thanks, and a happy birth day
+1 ตอบกลับ
great job with the script and congrats on the recognition. And happy birthday! I'm no math wiz by any stretch of the imagination but would standard deviations be applicable to this?
+1 ตอบกลับ
@MarraM, Thx, do you mean making a channel out of this? more than possible, however it would be a channel with a low number of values due to the limitations of line.new
ตอบกลับ
Thank you for sharing your amazing work with us Alex!
+1 ตอบกลับ
alexgrover allanster
@allanster, Thx mate
ตอบกลับ
Very Nice !!!
Thank you !!!!

All the best
+1 ตอบกลับ
หน้าแรก ตัวช่วยคัดกรองหุ้น ตัวคัดกรองฟอเร็กซ์ ตัวคัดกรองคริปโต ปฏิทินเศรษฐกิจ มันทำงานได้อย่างไร ฟีเจอร์ของชาร์ต อัตราค่าบริการ แนะนำเพื่อน กฎระเบียบการใช้งาน ศูนย์ช่วยเหลือ โซลูชั่นสำหรับเว็บไซต์ & โบรกเกอร์ วิดเจ็ต ชาร์ตโซลูชั่น Lightweight ชาร์ตไลบรารี บล็อก & ข่าว Twitter
โปรไฟล์ ตั้งค่าโปรไฟล์ บัญชีและการเรียกเก็บเงิน เพื่อนที่ชวนมา เหรียญ ตั๋วการขอความสนับสนุนของฉัน ศูนย์ช่วยเหลือ ไอเดียที่เผยแพร่ ผู้ติดตาม ติดตาม ข้อความส่วนตัว แชท ออกจากระบบ