RicardoSantos

Function - Linear Regression

Description:
A Function that returns a linear regression channel using (X,Y) vector points.

Inputs:
_X: Array containing x data points.¹
_Y: Array containing y data points.¹

Note:
¹: _X and _Y size must match.

Outputs:
_predictions: Array with adjusted _Y values at _X.
_max_dev: Max deviation from the mean.
_min_dev: Min deviation from the mean.
_stdev/_sizeX: Average deviation from the mean.

Resources:
https://www.statisticshowto.com/probabil...
https://en.wikipedia.org/wiki/Linear_reg...
版本注释: added color, and extend options, removed some test inputs, optimized array creation process slightly.
版本注释: corrected a issue reported by: @marketrading001
开源脚本

本着真正的TradingView精神,该脚本的作者将其开源发布,因此交易者可以理解和验证它。为作者加油! 您可以免费使用它,但是在发布中重复使用此代码受网站规则的约束。您可以收藏它以在图表上使用。

想在图表上使用此脚本?

评论

Thank you for the script. Very helpful.

Just wanted to note, that there are some arrays that don't necessarily start with index 0 (some have values starting at index 2 for example). So when using this function on those arrays, one gets NaN for the outputs. Adding nz() to the arrays in the calculations helps resolve that problem:

_sumXY := _sumXY + (nz(_Xi) * nz(_Yi))
_sumX2 := _sumX2 + pow(nz(_Xi), 2)
_sumY2 := _sumY2 + pow(nz(_Yi), 2)

Very helpful script.
+2 回复
RicardoSantos marketrading001
@marketrading001, thanks, ill update the script, was a oversight in my part :)
+2 回复
Fantastic work. Absolute must have if you play in crypto, I can only speak from experience in that category.

Only question I have... Are alerts possible? I can't find a way to set them, not very tech oriented.

My express gratitude for an outstanding tool.
回复
What’s exactly the function of the extended lines feature? R,b,l,n
回复
Many thanks for your incredible generosity and brilliant work. I've learned a tremendous amount from your scripts.
回复
Hi Ricardo, i'm not sure what to modify in the script so I can change the STDEV of the dashed aqua line. Can you please help me?
回复
@Deadca7, in case you haven't found it yet, check ll. 73, 78 & 79
回复
首页 股票筛选器 外汇筛选器 加密货币筛选器 财经日历 关于 图表功能 价格 推荐朋友 网站规则 帮助中心 网站 & 经纪商解决方案 插件 图表解决方案 轻量图表库 博客 & 新闻 Twitter
概览 个人资料设置 账户和账单 推荐朋友 代币 我的客服工单 帮助中心 私人消息 在线聊天 退出