LinearRegression debut et fin
Forums › ProRealTime forum Français › Support ProBuilder › LinearRegression debut et fin
- This topic has 3 replies, 3 voices, and was last updated 2 years ago by
LucasBest.
Viewing 4 posts - 1 through 4 (of 4 total)
-
-
09/20/2023 at 1:27 PM #221332
Bonjour,
Le code
N=20
LR = LinearRegression[N](close)
donne bien la valeur de l’extrémité droite d’une droite de régression sur 20 périodes.
Mais comment je fais pour avoir la valeur de l’extrémité gauche de cette même droite ?
Merci
09/21/2023 at 10:23 AM #221379Avec le code ci-dessous, tu obtiendras la valeur du premier point de la régression linéaire (courbe en jaune, soit où est localisé le point jaune).
1234567891011121314151617181920212223242526272829303132333435363738394041//PRC_Std and Ste LinRegChannel | indicator//Standard Deviation and Standard Error//Linear Regression Channel//12.03.2019//Nicolas @ www.prorealcode.com//Sharing ProRealTime knowledgedefparam drawonlastbaronly=truedefparam calculateonlastbars=1000// --- settingslookback= 20 //channel period// --- end of settingssumx = 0sumy = 0sumxy = 0sumx2 = 0for cmpt = lookback downto 0 dotmpx = cmpttmpy = close[cmpt]sumy = sumy+tmpysumx = sumx+tmpxsumx2 = sumx2 + (tmpx*tmpx)sumxy = sumxy + (tmpy*tmpx)nextn = lookback+1if (sumx2 = sumx * sumx) then // protection to avoid infinite valuesb = sumxy - sumx * sumyelseb = (n * sumxy - sumx * sumy) / (n * sumx2 - sumx * sumx)endifa = (sumy - b * sumx) / ndrawsegment(barindex[lookback],a+b*lookback,barindex,a+b*0)drawpoint(barindex[lookback],a+b*lookback,3) coloured("yellow")return linearregression[lookback] coloured("red"), a+b*lookback coloured("yellow")09/21/2023 at 8:20 PM #22141309/21/2023 at 11:04 PM #221419Sinon, il y a aussi cette alternative en utilisant les 2 fonctions de probuilder : linearregression et linearregressionslope
LinearRegressionSegment12345678910111213141516171819k = 20 // à ajouter en variable dans la configurationdpok2=DPO[k*2](close)if dpok2=dpok2[1] and dpok2[1]=dpok2[2] and dpok2[2]<>dpok2[3] thenstart=1endifif start=1 and start[1]=0 thenStartIndex = BarindexEndifIf barindex-k+1 = Startindex thenb=linearregression[k](close)a=linearregressionslope[k](close)y=b-a*(k-1)Drawsegment(Startindex,y,barindex,b)Style(dottedline2,4) Coloured("green",255)endifreturn1 user thanked author for this post.
-
AuthorPosts
Viewing 4 posts - 1 through 4 (of 4 total)
