LinearRegression debut et fin

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #221332 quote
    the_giorgiothe_giorgio
    Participant
    Senior

    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

    #221379 quote
    NicolasNicolas
    Keymaster
    Legend

    Avec 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).

    //PRC_Std and Ste LinRegChannel | indicator
    //Standard Deviation and Standard Error
    //Linear Regression Channel
    //12.03.2019
    //Nicolas @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    
    defparam drawonlastbaronly=true
    defparam calculateonlastbars=1000
    // --- settings
    lookback= 20 //channel period
    // --- end of settings
    
    sumx = 0
    sumy = 0
    sumxy = 0
    sumx2 = 0
    
    for cmpt = lookback downto 0 do
    tmpx = cmpt
    tmpy = close[cmpt]
    sumy = sumy+tmpy
    sumx = sumx+tmpx
    sumx2 = sumx2 + (tmpx*tmpx)
    sumxy = sumxy + (tmpy*tmpx)
    next
    
    n = lookback+1
    
    if (sumx2 = sumx * sumx) then // protection to avoid infinite values
    b = sumxy - sumx * sumy
    else
    b = (n * sumxy - sumx * sumy) / (n * sumx2 - sumx * sumx)
    endif
    a = (sumy - b * sumx) / n
    
    drawsegment(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")
    #221413 quote
    the_giorgiothe_giorgio
    Participant
    Senior

    Super

     

    Merci

    #221419 quote
    LucasBestLucasBest
    Participant
    Senior

    Sinon, il y a aussi cette alternative en utilisant les 2 fonctions de probuilder : linearregression et linearregressionslope

    k = 20 // à ajouter en variable dans la configuration
    dpok2=DPO[k*2](close)
    
    if dpok2=dpok2[1] and dpok2[1]=dpok2[2] and dpok2[2]<>dpok2[3] then
    start=1
    endif
    
    if start=1 and start[1]=0 then
    StartIndex = Barindex
    Endif
    
    If barindex-k+1 = Startindex then
    b=linearregression[k](close)
    a=linearregressionslope[k](close)
    y=b-a*(k-1)
    Drawsegment(Startindex,y,barindex,b)Style(dottedline2,4) Coloured("green",255)
    endif
    
    return
    
    Nicolas thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

LinearRegression debut et fin


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by LucasBestLucasBest
3 years, 1 month ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 09/20/2023
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...