Nicolas

Quadratic regression

Category: Indicators By: Nicolas Created: August 22, 2018, 9:57 AM
August 22, 2018, 9:57 AM
Indicators
6 Comments
Quadratic regression

A quadratic regression is the process of finding the equation of the parabola that best fits a set of data. Period of the study can be modified with the “length” setting (default=100).

Converted from a tradingview code.

//PRC_Quadratic Regression | indicator
//22.08.2018
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge

// --- settings 
length = 100
// --- end of settings 

y = close
x1 = barindex
x2 = square(x1)

S11 = summation[length](x2) - square(summation[length](x1))/length
S12 = summation[length](x1*x2) - (summation[length](x1) * summation[length](x2))/length
S22 = summation[length](square(x2)) - square(summation[length](x2))/length
Sy1 = summation[length](y*x1) - (summation[length](y)*summation[length](x1))/length
Sy2 = summation[length](y*x2) - (summation[length](y)*summation[length](x2))/length

max1 = average[length](x1)
max2 = average[length](x2)
may = average[length](y)
b2 = ((Sy1 * S22) - (Sy2*S12))/(S22*S11 - square(S12))
b3 = ((Sy2 * S11) - (Sy1 * S12))/(S22 * S11 - square(S12))
b1 = may - b2*max1 - b3*max2
qr = b1 + b2*x1 + b3*x2

return qr

 

Download
Filename: PRC_Quadratic-Regression.itf
Downloads: 273
Nicolas
Nicolas Legend
I created ProRealCode because I believe in the power of shared knowledge. I spend my time coding new tools and helping members solve complex problems. If you are stuck on a code or need a fresh perspective on a strategy, I am always willing to help. Welcome to the community!
Author’s Profile

Comments

Stephan_V
6 years ago
#

Nicolas, This regression delivers damn good results, especially for trends ! I'm wondering what degree of Polynomial Regression is used, and frankly, I can't recognize any polynomial resolution from your code. Do you have any background and formula that helped you in building that piece ? Thanks, Et toutes mes félicitations pour ce site que tu gères de main de maître ! Ca doit représenter du temps et bcp d'expertise ... Saches que ça aide beaucoup de monde, à commencer par moi-même. Stephan

Nicolas
6 years ago
#

Least square method is used here in order to get the perfect y = ax2 + bx + c

Traderfox06
7 years ago
#

Dear Nicolas, I believe in the high potential of quadratic regression for an automated system. Therefore, I would like to understand in detail the principles how you have coded the algo. All the mathematical derivations I found, look somehow different, e.g. this one: https://www.azdhs.gov/documents/preparedness/state-laboratory/lab-licensure-certification/technical-resources/calibration-training/12-quadratic-least-squares-regression-calib.pdf Could you give me some more detailed information, please? Another question: Does this summation command: S11 = summation[length](x2) - square(summation[length](x1))/length, mean, that this line is like a loop which is processed times every 5 minutes if the period is M5? Thanks and kind regards, Michael

Nicolas
7 years ago
#

S11 variable is not a loop but a ratio calculation. In real time the codes is processed on each new tick received. On history, it is calculated with the Close of each candlestick, same goes for all indicators, not only with this one.

murri
7 years ago
#

Muy interesante. Solo que a mi me aparece no sobre el precio sino en pantalla aparte. ¿Cómo hacerlo para que se sobre imprese con la pantalla del precio? Gracias

Nicolas
7 years ago
#

Agréguelo a la tabla de precios usando el botón de configuración de precios en la tabla.

ProRealCode ProRealCode
Loading...