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...
Notas de Lançamento: added color, and extend options, removed some test inputs, optimized array creation process slightly.
Notas de Lançamento: corrected a issue reported by: @marketrading001
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Quer usar esse script no gráfico?

Comentários

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 Resposta
RicardoSantos marketrading001
@marketrading001, thanks, ill update the script, was a oversight in my part :)
+2 Resposta
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.
Resposta
What’s exactly the function of the extended lines feature? R,b,l,n
Resposta
Many thanks for your incredible generosity and brilliant work. I've learned a tremendous amount from your scripts.
Resposta
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?
Resposta
@Deadca7, in case you haven't found it yet, check ll. 73, 78 & 79
Resposta
Início Rastreador de Fundamentos Rastreador Forex Rastreador de Criptomoedas Calendário Econômico Como Funciona Recursos gráficos Preços Indique um Amigo Regras da Casa Central de Ajuda Soluções para Sites & Corretoras Widgets Soluções em Gráficos Biblioteca de Gráficos Lightweight Blog & Notícias Twitter
Perfil Configurações de perfil Conta e Cobrança Amigos indicados Moedas Meus Tíquetes de Suporte Central de Ajuda Mensagens Privadas Conversa Deslogar