Screener Super Trend AI Clustering

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #250715 quote
    Alai-n
    Participant
    Veteran

    Bonjour,

    Je souhaiterais modifier ce code disponible dans la bibliothèque des Indicateurs, le Super Trend AI Clustering.

    Seulement, lorsque je fais une tentative j’ai des erreurs de syntaxe en pagaille que je n’arrive pas à régler!

    Serait-il possible de simplifier l’écriture de ce code afin de pouvoir l’utiliser dans un Screener ?

    Merci

    //---------------------------------------------------------------//
    //SuperTrend AI Clustering
    //version = 2
    //02.06.2025
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //---------------------------------------------------------------//
    //-----Inputs----------------------------------------------------//
    //---------------------------------------------------------------//
    //length=10 // ATR length
    //minMult=1
    //maxMult=5
    //step=0.5
    //perfAlpha=10 // Performance memory
    //fromCluster=1 // 1=best 2=average 3=worst
    maxiter=10 // Número máximo de iteraciones de clustering
    epsilon=0.0001 // Precisión para simular convergencia
    //---------------------------------------------------------------//
    //-----Average True Range----------------------------------------//
    //---------------------------------------------------------------//
    atr=averagetruerange[length](close)
    //---------------------------------------------------------------//
    //-----Supertrend cálculo múltiple-------------------------------//
    //---------------------------------------------------------------//
    $holderUpper[0]=(high+low)/2
    $holderLower[0]=(high+low)/2
    
    k=0
    for factor=0 to floor((maxMult-minMult)/step) do
    up=(high+low)/2+atr*factor
    dn=(high+low)/2-atr*factor
    
    if close > $holderUpper[k] then
    $holderTrend[k]=1
    elsif close < $holderUpper[k] then
    $holderTrend[k]=0
    else
    $holderTrend[k]=$holderTrend[k]
    endif
    
    if close[1]<$holderUpper[k] then
    $holderUpper[k]=min(up,$holderUpper[k])
    else
    $holderUpper[k]=up
    endif
    
    if close[1]>$holderLower[k] then
    $holderLower[k]=max(dn,$holderLower[k])
    else
    $holderLower[k]=dn
    endif
    
    if (close[1]-$holderOutput[k])>0 then
    diff=1
    elsif (close[1]-$holderOutput[k])<0 then
    diff=-1
    else
    diff=0
    endif
    
    $holderPerf[k]=$holderPerf[max(0,k-1)]+2/(perfAlpha+1)*((close-close[1])*diff-$holderPerf[max(0,k-1)])
    
    if $holderTrend[k]=1 then
    $holderOutput[k]=$holderLower[k]
    else
    $holderOutput[k]=$holderUpper[k]
    endif
    
    $holderFactor[k] = (minMult+k*step)
    
    k=k+1
    next
    //---------------------------------------------------------------//
    //-----K-means con convergencia----------------------------------//
    //---------------------------------------------------------------//
    centroid1 = 0
    centroid2 = 0
    centroid3 = 0
    count = k
    
    FOR i = 0 TO count - 1 DO
    IF i < count / 3 THEN
    centroid1 = centroid1 + $holderPerf[i]
    ELSIF i < 2 * count / 3 THEN
    centroid2 = centroid2 + $holderPerf[i]
    ELSE
    centroid3 = centroid3 + $holderPerf[i]
    ENDIF
    NEXT
    
    centroid1 = centroid1 / (count / 3)
    centroid2 = centroid2 / (count / 3)
    centroid3 = centroid3 / (count / 3)
    
    converged = 0
    iter = 0
    
    WHILE iter < maxiter AND converged = 0 DO
    old1 = centroid1
    old2 = centroid2
    old3 = centroid3
    
    $cluster1Perf[0] = 0
    $cluster2Perf[0] = 0
    $cluster3Perf[0] = 0
    $cluster1Factors[0] = 0
    $cluster2Factors[0] = 0
    $cluster3Factors[0] = 0
    
    FOR i = 0 TO count - 1 DO
    dist1 = abs($holderPerf[i] - centroid1)
    dist2 = abs($holderPerf[i] - centroid2)
    dist3 = abs($holderPerf[i] - centroid3)
    
    IF dist1 <= dist2 AND dist1 <= dist3 THEN
    $cluster1Perf[$cluster1Perf[0]+1] = $holderPerf[i]
    $cluster1Factors[$cluster1Factors[0]+1] = $holderFactor[i]
    $cluster1Perf[0] = $cluster1Perf[0] + 1
    $cluster1Factors[0] = $cluster1Factors[0] + 1
    ELSIF dist2 <= dist1 AND dist2 <= dist3 THEN
    $cluster2Perf[$cluster2Perf[0]+1] = $holderPerf[i]
    $cluster2Factors[$cluster2Factors[0]+1] = $holderFactor[i]
    $cluster2Perf[0] = $cluster2Perf[0] + 1
    $cluster2Factors[0] = $cluster2Factors[0] + 1
    ELSE
    $cluster3Perf[$cluster3Perf[0]+1] = $holderPerf[i]
    $cluster3Factors[$cluster3Factors[0]+1] = $holderFactor[i]
    $cluster3Perf[0] = $cluster3Perf[0] + 1
    $cluster3Factors[0] = $cluster3Factors[0] + 1
    ENDIF
    NEXT
    
    centroid1 = 0
    centroid2 = 0
    centroid3 = 0
    
    IF $cluster1Perf[0] > 0 THEN
    FOR i = 1 TO $cluster1Perf[0] DO
    centroid1 = centroid1 + $cluster1Perf[i]
    NEXT
    centroid1 = centroid1 / $cluster1Perf[0]
    ENDIF
    IF $cluster2Perf[0] > 0 THEN
    FOR i = 1 TO $cluster2Perf[0] DO
    centroid2 = centroid2 + $cluster2Perf[i]
    NEXT
    centroid2 = centroid2 / $cluster2Perf[0]
    ENDIF
    IF $cluster3Perf[0] > 0 THEN
    FOR i = 1 TO $cluster3Perf[0] DO
    centroid3 = centroid3 + $cluster3Perf[i]
    NEXT
    centroid3 = centroid3 / $cluster3Perf[0]
    ENDIF
    
    IF abs(centroid1 - old1) < epsilon AND abs(centroid2 - old2) < epsilon
    AND abs(centroid3 - old3) < epsilon THEN
    converged = 1
    ENDIF
    
    iter = iter + 1
    WEND
    //---------------------------------------------------------------//
    //-----Cluster seleccionado y nuevo Supertrend-------------------//
    //---------------------------------------------------------------//
    finalFactor = 0
    finalPerf = 0
    perf = 0
    fact = 0
    
    IF fromCluster = 1 THEN
    // Best
    IF centroid1 > max(centroid2, centroid3) THEN
    FOR j = 1 TO lastset($cluster1Perf) DO
    perf = perf + $cluster1Perf[j]
    fact = fact + $cluster1Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster1Factors)
    if lastset($cluster1Perf) > 0 then
    finalPerf = perf / lastset($cluster1Perf)
    else
    finalPerf = 0
    endif
    ELSIF centroid2 > max(centroid1, centroid3) THEN
    FOR j = 1 TO lastset($cluster2Perf) DO
    perf = perf + $cluster2Perf[j]
    fact = fact + $cluster2Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster2Factors)
    if lastset($cluster2Perf) > 0 then
    finalPerf = perf / lastset($cluster2Perf)
    else
    finalPerf = 0
    endif
    ELSE
    FOR j = 1 TO lastset($cluster3Perf) DO
    perf = perf + $cluster3Perf[j]
    fact = fact + $cluster3Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster3Factors)
    if lastset($cluster3Perf) > 0 then
    finalPerf = perf / lastset($cluster3Perf)
    else
    finalPerf = 0
    endif
    ENDIF
    
    ELSIF fromCluster = 2 THEN
    // Average
    IF centroid1 > centroid2 AND centroid1 < centroid3 THEN
    FOR j = 1 TO lastset($cluster1Perf) DO
    perf = perf + $cluster1Perf[j]
    fact = fact + $cluster1Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster1Factors)
    if lastset($cluster1Perf) > 0 then
    finalPerf = perf / lastset($cluster1Perf)
    else
    finalPerf = 0
    endif
    ELSIF centroid2 > centroid1 AND centroid2 < centroid3 THEN
    FOR j = 1 TO lastset($cluster2Perf) DO
    perf = perf + $cluster2Perf[j]
    fact = fact + $cluster2Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster2Factors)
    if lastset($cluster2Perf) > 0 then
    finalPerf = perf / lastset($cluster2Perf)
    else
    finalPerf = 0
    endif
    ELSE
    FOR j = 1 TO lastset($cluster3Perf) DO
    perf = perf + $cluster3Perf[j]
    fact = fact + $cluster3Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster3Factors)
    if lastset($cluster3Perf) > 0 then
    finalPerf = perf / lastset($cluster3Perf)
    else
    finalPerf = 0
    endif
    ENDIF
    
    ELSIF fromCluster = 3 THEN
    // Worst
    IF centroid1 < min(centroid2, centroid3) THEN
    FOR j = 1 TO lastset($cluster1Perf) DO
    perf = perf + $cluster1Perf[j]
    fact = fact + $cluster1Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster1Factors)
    if lastset($cluster1Perf) > 0 then
    finalPerf = perf / lastset($cluster1Perf)
    else
    finalPerf = 0
    endif
    ELSIF centroid2 < min(centroid1, centroid3) THEN
    FOR j = 1 TO lastset($cluster2Perf) DO
    perf = perf + $cluster2Perf[j]
    fact = fact + $cluster2Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster2Factors)
    if lastset($cluster2Perf) > 0 then
    finalPerf = perf / lastset($cluster2Perf)
    else
    finalPerf = 0
    endif
    ELSE
    FOR j = 1 TO lastset($cluster3Perf) DO
    perf = perf + $cluster3Perf[j]
    fact = fact + $cluster3Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster3Factors)
    if lastset($cluster3Perf) > 0 then
    finalPerf = perf / lastset($cluster3Perf)
    else
    finalPerf = 0
    endif
    ENDIF
    ENDIF
    //---------------------------------------------------------------//
    //-----Renderizado final del Supertrend--------------------------//
    //---------------------------------------------------------------//
    newup = (high + low) / 2 + atr * finalFactor
    newdown = (high + low) / 2 - atr * finalFactor
    
    if close[1] < newupper then
    newupper = min(newup, newupper)
    else
    newupper = newup
    endif
    
    if close[1] > newlower then
    newlower = max(newdown, newlower)
    else
    newlower = newdown
    endif
    
    if close > newupper then
    newOS = 1
    elsif close < newlower then
    newOS = 0
    else
    newOS = newOS
    endif
    
    if newOS and newOS[1]=0 then
    newST = newlower
    r = 0
    g = 255
    transp=0
    elsif newOS then
    newST = newlower
    r = 0
    g = 255
    transp=255
    elsif newOS=0 and newOS[1] then
    newST = newupper
    r = 255
    g = 0
    transp=0
    else
    newST = newupper
    r = 255
    g = 0
    transp=255
    endif
    //---------------------------------------------------------------//
    return newST style(line,2) coloured(r,g,0,transp)
    Capture-decran-2025-09-11-175508.png Capture-decran-2025-09-11-175508.png
    #250724 quote
    robertogozzi
    Moderator
    Master

    Les lignes 156 et 157 étaient séparées, alors qu’elles auraient dû être une seule ligne :

    IF abs(centroid1 - old1) < epsilon AND abs(centroid2 - old2) < epsilon AND abs(centroid3 - old3) < epsilon THEN
    #250743 quote
    Iván González
    Moderator
    Master

    Bonjour. Tu dois supprimer toutes les variables qui ne sont pas utilisées dans le code.

    //-----Inputs
    length=10
    minMult=1
    maxMult=5
    step=0.5
    perfAlpha=10 // Performance memory
    fromCluster=1 // 1=best 2=average 3=worst
    maxiter=10 // Número máximo de iteraciones de clustering
    epsilon=0.0001 // Precisión para simular convergencia
    //-----Average True Range
    atr=averagetruerange[length](close)
    //-----Supertrend cálculo múltiple
    $holderUpper[0]=(high+low)/2
    $holderLower[0]=(high+low)/2
    
    k=0
    for factor=0 to floor((maxMult-minMult)/step) do
       up=(high+low)/2+atr*factor
       dn=(high+low)/2-atr*factor
       
       if close > $holderUpper[k] then
          $holderTrend[k]=1
       elsif close < $holderUpper[k] then
          $holderTrend[k]=0
       else
          $holderTrend[k]=$holderTrend[k]
       endif
       
       if close[1]<$holderUpper[k] then
          $holderUpper[k]=min(up,$holderUpper[k])
       else
          $holderUpper[k]=up
       endif
       
       if close[1]>$holderLower[k] then
          $holderLower[k]=max(dn,$holderLower[k])
       else
          $holderLower[k]=dn
       endif
       
       if (close[1]-$holderOutput[k])>0 then
          diff=1
       elsif (close[1]-$holderOutput[k])<0 then
          diff=-1
       else
          diff=0
       endif
       
       $holderPerf[k]=$holderPerf[max(0,k-1)]+2/(perfAlpha+1)*((close-close[1])*diff-$holderPerf[max(0,k-1)])
       
       if $holderTrend[k]=1 then
          $holderOutput[k]=$holderLower[k]
       else
          $holderOutput[k]=$holderUpper[k]
       endif
       
       $holderFactor[k] = (minMult+k*step)
       
       k=k+1
    next
    //-----K-means con convergencia
    centroid1 = 0
    centroid2 = 0
    centroid3 = 0
    count = k
    
    FOR i = 0 TO count - 1 DO
       IF i < count / 3 THEN
          centroid1 = centroid1 + $holderPerf[i]
       ELSIF i < 2 * count / 3 THEN
          centroid2 = centroid2 + $holderPerf[i]
       ELSE
          centroid3 = centroid3 + $holderPerf[i]
       ENDIF
    NEXT
    
    centroid1 = centroid1 / (count / 3)
    centroid2 = centroid2 / (count / 3)
    centroid3 = centroid3 / (count / 3)
    
    converged = 0
    iter = 0
    
    WHILE iter < maxiter AND converged = 0 DO
       old1 = centroid1
       old2 = centroid2
       old3 = centroid3
       
       $cluster1Perf[0] = 0
       $cluster2Perf[0] = 0
       $cluster3Perf[0] = 0
       $cluster1Factors[0] = 0
       $cluster2Factors[0] = 0
       $cluster3Factors[0] = 0
       
       FOR i = 0 TO count - 1 DO
          dist1 = abs($holderPerf[i] - centroid1)
          dist2 = abs($holderPerf[i] - centroid2)
          dist3 = abs($holderPerf[i] - centroid3)
          
          IF dist1 <= dist2 AND dist1 <= dist3 THEN
             $cluster1Perf[$cluster1Perf[0]+1] = $holderPerf[i]
             $cluster1Factors[$cluster1Factors[0]+1] = $holderFactor[i]
             $cluster1Perf[0] = $cluster1Perf[0] + 1
             $cluster1Factors[0] = $cluster1Factors[0] + 1
          ELSIF dist2 <= dist1 AND dist2 <= dist3 THEN
             $cluster2Perf[$cluster2Perf[0]+1] = $holderPerf[i]
             $cluster2Factors[$cluster2Factors[0]+1] = $holderFactor[i]
             $cluster2Perf[0] = $cluster2Perf[0] + 1
             $cluster2Factors[0] = $cluster2Factors[0] + 1
          ELSE
             $cluster3Perf[$cluster3Perf[0]+1] = $holderPerf[i]
             $cluster3Factors[$cluster3Factors[0]+1] = $holderFactor[i]
             $cluster3Perf[0] = $cluster3Perf[0] + 1
             $cluster3Factors[0] = $cluster3Factors[0] + 1
          ENDIF
       NEXT
       
       centroid1 = 0
       centroid2 = 0
       centroid3 = 0
       
       IF $cluster1Perf[0] > 0 THEN
          FOR i = 1 TO $cluster1Perf[0] DO
             centroid1 = centroid1 + $cluster1Perf[i]
          NEXT
          centroid1 = centroid1 / $cluster1Perf[0]
       ENDIF
       IF $cluster2Perf[0] > 0 THEN
          FOR i = 1 TO $cluster2Perf[0] DO
             centroid2 = centroid2 + $cluster2Perf[i]
          NEXT
          centroid2 = centroid2 / $cluster2Perf[0]
       ENDIF
       IF $cluster3Perf[0] > 0 THEN
          FOR i = 1 TO $cluster3Perf[0] DO
             centroid3 = centroid3 + $cluster3Perf[i]
          NEXT
          centroid3 = centroid3 / $cluster3Perf[0]
       ENDIF
       
       IF abs(centroid1 - old1) < epsilon AND abs(centroid2 - old2) < epsilon AND abs(centroid3 - old3) < epsilon THEN
          converged = 1
       ENDIF
       
       iter = iter + 1
    WEND
    
    //-----Cluster seleccionado y nuevo Supertrend
    finalFactor = 0
    perf = 0
    fact = 0
    
    IF fromCluster = 1 THEN
       // Best
       IF centroid1 > max(centroid2, centroid3) THEN
          FOR j = 1 TO lastset($cluster1Perf) DO
             perf = perf + $cluster1Perf[j]
             fact = fact + $cluster1Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster1Factors)
          
       ELSIF centroid2 > max(centroid1, centroid3) THEN
          FOR j = 1 TO lastset($cluster2Perf) DO
             perf = perf + $cluster2Perf[j]
             fact = fact + $cluster2Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster2Factors)
          
       ELSE
          FOR j = 1 TO lastset($cluster3Perf) DO
             perf = perf + $cluster3Perf[j]
             fact = fact + $cluster3Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster3Factors)
          
       ENDIF
       
    ELSIF fromCluster = 2 THEN
       // Average
       IF centroid1 > centroid2 AND centroid1 < centroid3 THEN
          FOR j = 1 TO lastset($cluster1Perf) DO
             perf = perf + $cluster1Perf[j]
             fact = fact + $cluster1Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster1Factors)
          
       ELSIF centroid2 > centroid1 AND centroid2 < centroid3 THEN
          FOR j = 1 TO lastset($cluster2Perf) DO
             perf = perf + $cluster2Perf[j]
             fact = fact + $cluster2Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster2Factors)
          
       ELSE
          FOR j = 1 TO lastset($cluster3Perf) DO
             perf = perf + $cluster3Perf[j]
             fact = fact + $cluster3Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster3Factors)
          
       ENDIF
       
    ELSIF fromCluster = 3 THEN
       // Worst
       IF centroid1 < min(centroid2, centroid3) THEN
          FOR j = 1 TO lastset($cluster1Perf) DO
             perf = perf + $cluster1Perf[j]
             fact = fact + $cluster1Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster1Factors)
          
       ELSIF centroid2 < min(centroid1, centroid3) THEN
          FOR j = 1 TO lastset($cluster2Perf) DO
             perf = perf + $cluster2Perf[j]
             fact = fact + $cluster2Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster2Factors)
          
       ELSE
          FOR j = 1 TO lastset($cluster3Perf) DO
             perf = perf + $cluster3Perf[j]
             fact = fact + $cluster3Factors[j]
          NEXT
          finalFactor = fact / lastset($cluster3Factors)
          
       ENDIF
    ENDIF
    //-----Renderizado final del Supertrend
    newup = (high + low) / 2 + atr * finalFactor
    newdown = (high + low) / 2 - atr * finalFactor
    
    if close[1] < newupper then
       newupper = min(newup, newupper)
    else
       newupper = newup
    endif
    
    if close[1] > newlower then
       newlower = max(newdown, newlower)
    else
       newlower = newdown
    endif
    
    if close > newupper then
       newOS = 1
    elsif close < newlower then
       newOS = 0
    else
       newOS = newOS
    endif
    
    screener[newOS<>newOS[1]]
    
    Alai-n thanked this post
    #251264 quote
    Alai-n
    Participant
    Veteran

    Bonjour,

    J’ai un problème pour terminer ce Screener, les résultats retournés ne sont pas juste! Ici sur la photo jointe, pour se rendre compte du problème, je l’ai posé comme un indicateur dans une fenêtre sous le prix.

    L’idée initiale est de mettre en évidence la tendance haussière ou baissière du SuperTrend AI Clustering ligne 204 à 230 dans le code. Mais on peut voir clairement qu’il y a une différence notable entre l’indicateur sur le graphique et l’indicateur dans la fenêtre sous le prix…

    Je ne trouve pas la solution !

    //-----Inputs
    length=10
    minMult=1
    maxMult=5
    step=0.5
    perfAlpha=10 // Performance memory
    fromCluster=1 // 1=best 2=average 3=worst
    maxiter=10 // Número máximo de iteraciones de clustering
    epsilon=0.0001 // Precisión para simular convergencia
    //-----Average True Range
    atr=averagetruerange[length](close)
    //-----Supertrend cálculo múltiple
    $holderUpper[0]=(high+low)/2
    $holderLower[0]=(high+low)/2
    
    k=0
    for factor=0 to floor((maxMult-minMult)/step) do
    up=(high+low)/2+atr*factor
    dn=(high+low)/2-atr*factor
       
    if close > $holderUpper[k] then
    $holderTrend[k]=1
    elsif close < $holderUpper[k] then
    $holderTrend[k]=0
    else
    $holderTrend[k]=$holderTrend[k]
    endif
       
    if close[1]<$holderUpper[k] then
    $holderUpper[k]=min(up,$holderUpper[k])
    else
    $holderUpper[k]=up
    endif
       
    if close[1]>$holderLower[k] then
    $holderLower[k]=max(dn,$holderLower[k])
    else
    $holderLower[k]=dn
    endif
       
    if (close[1]-$holderOutput[k])>0 then
    diff=1
    elsif (close[1]-$holderOutput[k])<0 then
    diff=-1
    else
    diff=0
    endif
       
    $holderPerf[k]=$holderPerf[max(0,k-1)]+2/(perfAlpha+1)*((close-close[1])*diff-$holderPerf[max(0,k-1)])
       
    if $holderTrend[k]=1 then
    $holderOutput[k]=$holderLower[k]
    else
    $holderOutput[k]=$holderUpper[k]
    endif
       
    $holderFactor[k] = (minMult+k*step)
       
    k=k+1
    next
    //-----K-means con convergencia
    centroid1 = 0
    centroid2 = 0
    centroid3 = 0
    count = k
    
    FOR i = 0 TO count - 1 DO
    IF i < count / 3 THEN
    centroid1 = centroid1 + $holderPerf[i]
    ELSIF i < 2 * count / 3 THEN
    centroid2 = centroid2 + $holderPerf[i]
    ELSE
    centroid3 = centroid3 + $holderPerf[i]
    ENDIF
    NEXT
    
    centroid1 = centroid1 / (count / 3)
    centroid2 = centroid2 / (count / 3)
    centroid3 = centroid3 / (count / 3)
    
    converged = 0
    iter = 0
    
    WHILE iter < maxiter AND converged = 0 DO
    old1 = centroid1
    old2 = centroid2
    old3 = centroid3
       
    $cluster1Perf[0] = 0
    $cluster2Perf[0] = 0
    $cluster3Perf[0] = 0
    $cluster1Factors[0] = 0
    $cluster2Factors[0] = 0
    $cluster3Factors[0] = 0
       
    FOR i = 0 TO count - 1 DO
    dist1 = abs($holderPerf[i] - centroid1)
    dist2 = abs($holderPerf[i] - centroid2)
    dist3 = abs($holderPerf[i] - centroid3)
          
    IF dist1 <= dist2 AND dist1 <= dist3 THEN
    $cluster1Perf[$cluster1Perf[0]+1] = $holderPerf[i]
    $cluster1Factors[$cluster1Factors[0]+1] = $holderFactor[i]
    $cluster1Perf[0] = $cluster1Perf[0] + 1
    $cluster1Factors[0] = $cluster1Factors[0] + 1
    ELSIF dist2 <= dist1 AND dist2 <= dist3 THEN
    $cluster2Perf[$cluster2Perf[0]+1] = $holderPerf[i]
    $cluster2Factors[$cluster2Factors[0]+1] = $holderFactor[i]
    $cluster2Perf[0] = $cluster2Perf[0] + 1
    $cluster2Factors[0] = $cluster2Factors[0] + 1
    ELSE
    $cluster3Perf[$cluster3Perf[0]+1] = $holderPerf[i]
    $cluster3Factors[$cluster3Factors[0]+1] = $holderFactor[i]
    $cluster3Perf[0] = $cluster3Perf[0] + 1
    $cluster3Factors[0] = $cluster3Factors[0] + 1
    ENDIF
    NEXT
       
    centroid1 = 0
    centroid2 = 0
    centroid3 = 0
       
    IF $cluster1Perf[0] > 0 THEN
    FOR i = 1 TO $cluster1Perf[0] DO
    centroid1 = centroid1 + $cluster1Perf[i]
    NEXT
    centroid1 = centroid1 / $cluster1Perf[0]
    ENDIF
    IF $cluster2Perf[0] > 0 THEN
    FOR i = 1 TO $cluster2Perf[0] DO
    centroid2 = centroid2 + $cluster2Perf[i]
    NEXT
    centroid2 = centroid2 / $cluster2Perf[0]
    ENDIF
    IF $cluster3Perf[0] > 0 THEN
    FOR i = 1 TO $cluster3Perf[0] DO
    centroid3 = centroid3 + $cluster3Perf[i]
    NEXT
    centroid3 = centroid3 / $cluster3Perf[0]
    ENDIF
      
    IF abs(centroid1 - old1) < epsilon AND abs(centroid2 - old2) < epsilon AND abs(centroid3 - old3) < epsilon THEN
    converged = 1
    ENDIF
       
    iter = iter + 1
    WEND
    
    //-----Cluster seleccionado y nuevo Supertrend
    finalFactor = 0
    perf = 0
    fact = 0
    
    IF fromCluster = 1 THEN
    // Best
    IF centroid1 > max(centroid2, centroid3) THEN
    FOR j = 1 TO lastset($cluster1Perf) DO
    perf = perf + $cluster1Perf[j]
    fact = fact + $cluster1Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster1Factors)
          
    ELSIF centroid2 > max(centroid1, centroid3) THEN
    FOR j = 1 TO lastset($cluster2Perf) DO
    perf = perf + $cluster2Perf[j]
    fact = fact + $cluster2Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster2Factors)
          
    ELSE
    FOR j = 1 TO lastset($cluster3Perf) DO
    perf = perf + $cluster3Perf[j]
    fact = fact + $cluster3Factors[j]
    NEXT
    finalFactor = fact / lastset($cluster3Factors)
    ENDIF
    ENDIF
    
    //-----Renderizado final del Supertrend
    newup = (high + low) / 2 + atr * finalFactor
    newdown = (high + low) / 2 - atr * finalFactor
    
    if close[1] < newupper then
    newupper = min(newup, newupper)
    else
    newupper = newup
    endif
    
    if close[1] > newlower then
    newlower = max(newdown, newlower)
    else
    newlower = newdown
    endif
    
    if close > newupper then
    newOS = 1
    elsif close < newlower then
    newOS = 0
    else
    newOS = newOS
    endif
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    if newOS[0]>newOS[1] then
    haussier = 1
    endif
     
    if newOS[0]<newOS[1] then
    haussier = 0
    endif
    //
    if newOS[0]<newOS[1] then
    baissier = 1
    endif
     
    if newOS[0]>newOS[1] then
    baissier = 0
    endif
    
    Signal = 0
    
    If Haussier Then
    Signal = 1
    Endif
    
    If Baissier Then
    Signal = -1
    Endif
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    Return Signal as "Signal"
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    
    Exemple.png Exemple.png
    #252578 quote
    Alai-n
    Participant
    Veteran

    UP

    @Iván je n’arrive pas à finir ce Screener de tendance, post précédent #251264 !

    Je souhaiterais de plus, pouvoir identifier lorsque l’on passe d’une situation haussière à une situation baissière(image ci-jointe) sur l’indicateur “Super Trend AI Clustering”, pour pouvoir l’incorporer dans une approche Multi TimeFrame et je ne m’en sors pas avec NewOs ou Newupper ou Newlower !!!

    Capture-decran-2025-10-14-122447.png Capture-decran-2025-10-14-122447.png
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Screener Super Trend AI Clustering


ProScreener : Scanners de Marché & Détection

New Reply
Author
author-avatar
Alai-n @alai-n Participant
Summary

This topic contains 4 replies,
has 3 voices, and was last updated by Alai-n
4 months, 2 weeks ago.

Topic Details
Forum: ProScreener : Scanners de Marché & Détection
Language: French
Started: 09/11/2025
Status: Active
Attachments: 3 files
Logo Logo
Loading...