Griffiths Predictor Indicator

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #241659 quote
    Hasardeur
    Participant
    Average
    REM ----------------------------------------------------
    REM Griffiths Predictor Indicator by John F. Ehler from Traders Tips TASC Jan 2025
    REM  ----------------------------------------------------
    
    Length=     18    
    BarsFwd=     2    
    UpperBound= 40   
    LowerBound= 18  
    
    REM arrays
    For count= 0 TO Length+1 Do
    $Coef[count]= 0
    NEXT
    
    REM 2-Pole roofing filter
    HPPrice= (open+close)/2
    HPPeriod= UpperBound
    a1= Exp(-1.414*3.14159/HPPeriod)
    b1= 2*a1*Cos(1.414*180/HPPeriod)
    c2= b1
    c3= -a1*a1
    c1= (1+ c2-c3)/4
    IF 4 <= barindex THEN
    $HighPass[barindex]= c1*(HPPrice - 2*HPPrice[1] + HPPrice[2]) + c2*$HighPass[barindex-1] + c3*$HighPass[barindex-2]
    ELSE
    $HighPass[barindex]= 0
    ENDIF
    
    SSPrice= $HighPass[barindex]
    SSPeriod= LowerBound
    a1= Exp(-1.414*3.14159/SSPeriod)
    b1= 2*a1*Cos(1.414*180/SSPeriod)
    c2= b1
    c3= -a1*a1
    c1= 1-c2-c3
    IF 4 <= barindex THEN
    $SuperSmoother[barindex]= c1*(SSPrice + SSPrice[1])/2 + c2*$SuperSmoother[barindex-1] + c3*$SuperSmoother[barindex-2]
    ELSE
    $SuperSmoother[barindex]= 0
    ENDIF
    LP= $SuperSmoother[barindex]
    
    
    REM common function
    Mu = 1/Length
    IF 1<barindex THEN
    Peak= 0.991 * Peak[1]
    ELSE
    Peak=  0.1
    ENDIF
    IF Peak < Abs(LP) THEN
    Peak= Abs(LP)
    ENDIF
    IF Peak <> 0 THEN
    Signal= LP/Peak
    ENDIF
    REM Perfect cycle test signal
    //Signal = Sin(360*barindex / 30)
    
    FOR Count= 1 TO Length DO
    $XX[count]= Signal[Length-count]
    NEXT
    XBar= 0
    FOR Count= 1 TO Length DO
    XBar= XBar + $XX[Length-count] * $Coef[count]
    Next
    FOR count= 1 TO Length DO
    $coef[count]= $coef[count] + Mu*($XX[Length]-XBar) *$XX[Length-count]
    NEXT
    
    
    REM Prediction
    FOR Advance= 1 TO BarsFwd DO
    XPred= 0
    FOR count= 1 TO Length DO
    XPred = XPred + $XX[Length+1-count] * $coef[count]
    NEXT
    FOR count= advance TO Length-advance DO
    $XX[count]= $XX[count+1]
    NEXT
    FOR count= 1 TO Length-1 DO
    $XX[count]= $XX[count+1]
    NEXT
    $XX[Length]= XPred
    NEXT
    
    Return signal coloured(0,0,250) as "Signal", XPred coloured(250,0,0) as "xPred", XBar[17] as "xBar", $coef[17] coloured(0,150,0) as "Coef"

    Hello together,

    Result of “xBar” is always 0, so the code is not working correct.
    I expect that the error is caused by the chronological series of  “coef”  and “xBar”.
    xBar AND Coef is starting at 0, so the xbar result  is 0. After that coef will be calculated with xBar=0, the result of coef is also not correct.
    $coef[count]=0  (array pre filling, line 10 of code)
    XBar=0
    XBar= XBar + $XX[Length-count] * $Coef[count]
    $coef[count]= $coef[count] + Mu*($XX[Length]-XBar) *$XX[Length-count]

    Could you please help to correct the code.
    Many thanks in advanced

    #241670 quote
    jacquesgermain
    Participant
    Senior

    Hello , here is mine :

    // Griffiths Predictor Indicator by John F. Ehler
    // Adapté pour ProRealTime
    // Paramètres utilisateur
    Length =18
    BarsFwd =2
    UpperBound =40
    LowerBound =18

    // Initialisation des coefficients
    Coef1 = 0
    Coef2 = 0
    Coef3 = 0
    Coef4 = 0
    Coef5 = 0
    Coef6 = 0
    Coef7 = 0
    Coef8 = 0
    Coef9 = 0
    Coef10 = 0
    Coef11 = 0
    Coef12 = 0
    Coef13 = 0
    Coef14 = 0
    Coef15 = 0
    Coef16 = 0
    Coef17 = 0
    Coef18 = 0

    // Filtre passe-haut (High-Pass Filter)
    HPPeriod = UpperBound
    a1HP = EXP(-1.414 * 3.14159 / HPPeriod)
    b1HP = 2 * a1HP * COS(1.414 * 180 / HPPeriod)
    c2HP = b1HP
    c3HP = -(a1HP * a1HP)
    c1HP = (1 + c2HP – c3HP) / 4

    IF BARINDEX > 2 THEN
    HPPrice = (OPEN + CLOSE) / 2
    HighPass = c1HP * (HPPrice – 2 * (OPEN[1] + CLOSE[1]) / 2 + (OPEN[2] + CLOSE[2]) / 2) + c2HP * HighPass[1] + c3HP * HighPass[2]
    ELSE
    HighPass = 0
    ENDIF

    // Super Smoother Filter
    SSPeriod = LowerBound
    a1SS = EXP(-1.414 * 3.14159 / SSPeriod)
    b1SS = 2 * a1SS * COS(1.414 * 180 / SSPeriod)
    c2SS = b1SS
    c3SS = -(a1SS * a1SS)
    c1SS = 1 – c2SS – c3SS

    IF BARINDEX > 2 THEN
    SuperSmoother = c1SS * (HighPass + HighPass[1]) / 2 + c2SS * SuperSmoother[1] + c3SS * SuperSmoother[2]
    ELSE
    SuperSmoother = 0
    ENDIF

    // Signal
    LP = SuperSmoother
    IF BARINDEX > 1 THEN
    Peak = 0.991 * Peak
    ENDIF
    IF ABS(LP) > Peak THEN
    Peak = ABS(LP)
    ENDIF
    IF Peak <> 0 THEN
    Signal = LP / Peak
    ELSE
    Signal = 0
    ENDIF

    // Calcul de XBar
    Mu = 1 / Length
    XBar = Signal[0] * Coef1 + Signal[1] * Coef2 + Signal[2] * Coef3 + Signal[3] * Coef4 + Signal[4] * Coef5 +Signal[5] * Coef6 + Signal[6] * Coef7 + Signal[7] * Coef8 + Signal[8] * Coef9 + Signal[9] * Coef10 +Signal[10] * Coef11 + Signal[11] * Coef12 + Signal[12] * Coef13 + Signal[13] * Coef14 + Signal[14] * Coef15 +Signal[15] * Coef16 + Signal[16] * Coef17 + Signal[17] * Coef18

    // Mise à jour des coefficients
    Coef1 = Coef1 + Mu * (Signal – XBar) * Signal[0]
    Coef2 = Coef2 + Mu * (Signal – XBar) * Signal[1]
    Coef3 = Coef3 + Mu * (Signal – XBar) * Signal[2]
    Coef4 = Coef4 + Mu * (Signal – XBar) * Signal[3]
    Coef5 = Coef5 + Mu * (Signal – XBar) * Signal[4]
    Coef6 = Coef6 + Mu * (Signal – XBar) * Signal[5]
    Coef7 = Coef7 + Mu * (Signal – XBar) * Signal[6]
    Coef8 = Coef8 + Mu * (Signal – XBar) * Signal[7]
    Coef9 = Coef9 + Mu * (Signal – XBar) * Signal[8]
    Coef10 = Coef10 + Mu * (Signal – XBar) * Signal[9]
    Coef11 = Coef11 + Mu * (Signal – XBar) * Signal[10]
    Coef12 = Coef12 + Mu * (Signal – XBar) * Signal[11]
    Coef13 = Coef13 + Mu * (Signal – XBar) * Signal[12]
    Coef14 = Coef14 + Mu * (Signal – XBar) * Signal[13]
    Coef15 = Coef15 + Mu * (Signal – XBar) * Signal[14]
    Coef16 = Coef16 + Mu * (Signal – XBar) * Signal[15]
    Coef17 = Coef17 + Mu * (Signal – XBar) * Signal[16]
    Coef18 = Coef18 + Mu * (Signal – XBar) * Signal[17]

    // Prédiction avec BarsFwd
    XPred = 0
    FOR Advance = 1 TO BarsFwd DO
    ProjectedSignal = Signal[Advance]
    XPred = ProjectedSignal * Coef1 + Signal[Advance + 1] * Coef2 + Signal[Advance + 2] * Coef3 +Signal[Advance + 3] * Coef4 + Signal[Advance + 4] * Coef5 + Signal[Advance + 5] * Coef6 +Signal[Advance + 6] * Coef7 + Signal[Advance + 7] * Coef8 + Signal[Advance + 8] * Coef9 +Signal[Advance + 9] * Coef10 + Signal[Advance + 10] * Coef11 + Signal[Advance + 11] * Coef12 +Signal[Advance + 12] * Coef13 + Signal[Advance + 13] * Coef14 + Signal[Advance + 14] * Coef15 +Signal[Advance + 15] * Coef16 + Signal[Advance + 16] * Coef17 + Signal[Advance + 17] * Coef18
    NEXT

    // Retour des résultats
    RETURN Signal COLOURED(0, 0, 255) AS “Signal”, XPred COLOURED(255, 0, 0) AS “XPred”

    Iván González thanked this post
    #241671 quote
    Hasardeur
    Participant
    Average

    Dear Jacques germain,

    many thanks for your code.
    It was a good idea to substitute the arrays.
    As fa as i can see so fast, your code shows nearly the results as my.
    xBar is also 0, same as my.

    In my opinion we have to figure out the problem further more.

    #241679 quote
    jacquesgermain
    Participant
    Senior
    Initialize the coefficients to non-zero values ​​then xbar will no longer be equal to zero :
    from
    REM arrays
    For count= 0 TO Length+1 Do
    $Coef[count]=0
    NEXT
    
    to
    REM arrays
    For count= 0 TO Length+1 Do
    $Coef[count]= 1/Length
    NEXT
    
    
    #241698 quote
    Hasardeur
    Participant
    Average

    For count= 1 to Length Do
    $Coef[count]= 0
    NEXT

    for Count= 1 to Length DO
    $XX[count]= Signal[Length-count]
    NEXT
    XBar= 0
    for count= 1 to Length DO
    $coef[count]= $coef[count] + Mu*($XX[Length]-XBar) *$XX[Length-count]
    NEXT
    for Count= 1 to Length DO
    XBar= XBar + $XX[Length-count] * $Coef[count]
    Next

    Dear Jacques Germain,

    your suggest is an elegant solution.
    I tryed it by changing the position of coef and xbar calculation.
    So the start figure of coef is a calculatest at xbar=o , with this coef the xBar will be calculateed.

    #241701 quote
    jacquesgermain
    Participant
    Senior

    this one works :

    Length= 18
    BarsFwd= 2
    UpperBound= 40
    LowerBound= 18

    REM arrays
    For count= 0 TO Length+1 Do
    $Coef[count]= 1/Length
    NEXT

    REM 2-Pole roofing filter
    HPPrice= (open+close)/2
    HPPeriod= UpperBound
    a1= Exp(-1.414*3.14159/HPPeriod)
    b1= 2*a1*Cos(1.414*180/HPPeriod)
    c2= b1
    c3= -a1*a1
    c1= (1+ c2-c3)/4
    IF 4 <= barindex THEN
    $HighPass[barindex]= c1*(HPPrice – 2*HPPrice[1] + HPPrice[2]) + c2*$HighPass[barindex-1] + c3*$HighPass[barindex-2]
    ELSE
    $HighPass[barindex]= 0
    ENDIF

    SSPrice= $HighPass[barindex]
    SSPeriod= LowerBound
    a1= Exp(-1.414*3.14159/SSPeriod)
    b1= 2*a1*Cos(1.414*180/SSPeriod)
    c2= b1
    c3= -a1*a1
    c1= 1-c2-c3
    IF 4 <= barindex THEN
    $SuperSmoother[barindex]= c1*(SSPrice + SSPrice[1])/2 + c2*$SuperSmoother[barindex-1] + c3*$SuperSmoother[barindex-2]
    ELSE
    $SuperSmoother[barindex]= 0
    ENDIF
    LP= $SuperSmoother[barindex]

    REM common function
    Mu = 1/Length
    IF 1<barindex THEN
    Peak= 0.991 * Peak[1]
    ELSE
    Peak= 0.1
    ENDIF
    IF Peak < Abs(LP) THEN
    Peak= Abs(LP)
    ENDIF
    IF Peak <> 0 THEN
    Signal= LP/Peak
    ENDIF
    REM Perfect cycle test signal
    //Signal = Sin(360*barindex / 30)

    FOR Count= 1 TO Length DO
    $XX[count]= Signal[Length-count]
    NEXT
    XBar= 0
    FOR Count= 1 TO Length DO
    XBar= XBar + $XX[Length-count] * $Coef[count]
    Next
    FOR count= 1 TO Length DO
    $coef[count]= $coef[count] + Mu*($XX[Length]-XBar) *$XX[Length-count]
    NEXT

    REM Prediction
    FOR Advance= 1 TO BarsFwd DO
    XPred= 0
    FOR count= 1 TO Length DO
    XPred = XPred + $XX[Length+1-count] * $coef[count]
    NEXT
    FOR count= advance TO Length-advance DO
    $XX[count]= $XX[count+1]
    NEXT
    FOR count= 1 TO Length-1 DO
    $XX[count]= $XX[count+1]
    NEXT
    $XX[Length]= XPred
    NEXT

    Return signal coloured(0,0,250) as “Signal”, XPred coloured(250,0,0) as “xPred”, XBar[17] as “xBar”, $coef[17] coloured(0,150,0) as “Coef”

    #241712 quote
    Hasardeur
    Participant
    Average

    By comparing the both versions (GPI and GPI_Test), in my oppinion, the GPI version is more synchron to the chart.

    REM initial array filling
    FOR count= 1 TO Length Do
    $Coef[count]= 0
    NEXT

    FOR count= 1 TO Length DO
    $coef[count]= $coef[count] + Mu*($XX[Length]-XBar) *$XX[Length-count]
    NEXT
    for Count= 1 to Length DO
    XBar= XBar + $XX[Length-count] * $Coef[count]
    Next

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Griffiths Predictor Indicator


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Hasardeur @hasardeur Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by Hasardeur
1 year, 1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 12/21/2024
Status: Active
Attachments: No files
Logo Logo
Loading...