CONVERSION INDICADOR TRADINGVIEW:SuperTrend AI
Forums › ProRealTime foro Español › Soporte ProBuilder › CONVERSION INDICADOR TRADINGVIEW:SuperTrend AI
- This topic has 1 reply, 2 voices, and was last updated 3 months ago by Iván.
Viewing 2 posts - 1 through 2 (of 2 total)
-
-
07/12/2024 at 4:19 PM #235183
Solicito, si es posible, convertir el indicador adjunto:
El indicador SuperTrend AI es una nueva forma de cerrar la brecha entre el método de aprendizaje automático de agrupamiento de K-means y los indicadores técnicos. En este caso, aplicamos el agrupamiento de K-means al famoso indicador SuperTrend.
https://www.tradingview.com/script/wP7WWjLL-SuperTrend-AI-Clustering-LuxAlgo/
A ver si Iván el moderador tiene un hueco libre y lo puede traducir.
Muchas gracias.08/01/2024 at 3:55 PM #236021Buenas.
Esto es lo máximo que he conseguido. Es dificil porque no tenemos las mismas funcionalidades en PRT que en TV.123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281//---------------------------------------------------------------////SuperTrend AI Clustering//version = 0//01.08.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//---------------------------------------------------------------////-----Inputs----------------------------------------------------////---------------------------------------------------------------//length=10 //ATR lengthminMult=1maxMult=5step=0.5perfAlpha=10 //Performance memoryfromCluster=1//1=best 2=average 3=worst//---------------------------------------------------------------////-----Average True Range----------------------------------------////---------------------------------------------------------------//atr=averagetruerange[length](close)//---------------------------------------------------------------////-----Supertrend------------------------------------------------////---------------------------------------------------------------//$holderUpper[0]=(high+low)/2$holderLower[0]=(high+low)/2$holderOutput[0]=0$holderPerf[0]=0$holderFactor[0]=0$holderTrend[0]=0$factors[0]=0//---Populate Supertrendif barindex=0 thenn=0for i=0 to floor((maxMult-minMult)/step) do$factors[n+1]=(minMult+i*step)$holderUpper[n+1]=(high+low)/2$holderLower[n+1]=(high+low)/2$holderOutput[n+1]=0$holderPerf[n+1]=0$holderFactor[n+1]=0$holderTrend[n+1]=0n=n+1nextendif//---Compute Supertrend for multiple factorsk=0for factor=0 to floor((maxMult-minMult)/step) doup=(high+low)/2+atr*factordn=(high+low)/2-atr*factorif close > $holderUpper[k] then$holderTrend[k]=1elsif close < $holderUpper[k] then$holderTrend[k]=0else$holderTrend[k]=$holderTrend[k]endifif close[1]<$holderUpper[k] then$holderUpper[k]=min(up,$holderUpper[k])else$holderUpper[k]=upendifif close[1]>$holderLower[k] then$holderLower[k]=max(dn,$holderLower[k])else$holderLower[k]=dnendifif (close[1]-$holderOutput[k])>0 thendiff=1elsif (close[1]-$holderOutput[k])<0 thendiff=-1elsediff=0endif$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]=factork=k+1next//---------------------------------------------------------------////-----K means Clustering----------------------------------------////---------------------------------------------------------------//// Initialize centroids with approximate averagescentroid1 = 0centroid2 = 0centroid3 = 0count = kFOR i = 0 TO count - 1 DOIF i < count / 3 THENcentroid1 = centroid1 + $holderPerf[i]ELSIF i < 2 * count / 3 THENcentroid2 = centroid2 + $holderPerf[i]ELSEcentroid3 = centroid3 + $holderPerf[i]ENDIFNEXTcentroid1 = centroid1 / (count / 3)centroid2 = centroid2 / (count / 3)centroid3 = centroid3 / (count / 3)// Arrays to store the clusters$cluster1Perf[0] = 0$cluster2Perf[0] = 0$cluster3Perf[0] = 0$cluster1Factors[0] = 0$cluster2Factors[0] = 0$cluster3Factors[0] = 0FOR i = 0 TO count - 1 DOdist1 = 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] + 1ELSIF 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] + 1ELSE$cluster3Perf[$cluster3Perf[0]+1] = $holderPerf[i]$cluster3Factors[$cluster3Factors[0]+1] = $holderFactor[i]$cluster3Perf[0] = $cluster3Perf[0] + 1$cluster3Factors[0] = $cluster3Factors[0] + 1ENDIFNEXT// Recalculate centroidscentroid1 = 0centroid2 = 0centroid3 = 0FOR i = 1 TO $cluster1Perf[0] DOcentroid1 = centroid1 + $cluster1Perf[i]NEXTcentroid1 = centroid1 / $cluster1Perf[0]FOR i = 1 TO $cluster2Perf[0] DOcentroid2 = centroid2 + $cluster2Perf[i]NEXTcentroid2 = centroid2 / $cluster2Perf[0]FOR i = 1 TO $cluster3Perf[0] DOcentroid3 = centroid3 + $cluster3Perf[i]NEXTcentroid3 = centroid3 / $cluster3Perf[0]//---------------------------------------------------------------////-----Objective cluster selection-------------------------------////---------------------------------------------------------------//finalFactor = 0finalperf = 0perf = 0fact = 0IF fromCluster = 1 THEN// Best cluster (highest centroid value)if centroid1 > max(centroid2, centroid3) thenfor j = 1 to lastset($cluster1Perf) doperf = perf + $cluster1Perf[j]fact = fact + $cluster1Factors[j]nextfinalFactor = fact / lastset($cluster1Factors)finalPerf = perf / lastset($cluster1Perf)elsif centroid2 > max(centroid1, centroid3) thenfor j = 1 to lastset($cluster2Perf) doperf = perf + $cluster2Perf[j]fact = fact + $cluster2Factors[j]nextfinalFactor = fact / lastset($cluster2Factors)finalPerf = perf / lastset($cluster2Perf)elsefor j = 1 to lastset($cluster3Perf) doperf = perf + $cluster3Perf[j]fact = fact + $cluster3Factors[j]nextfinalFactor = fact / lastset($cluster3Factors)finalPerf = perf / lastset($cluster3Perf)ENDIFELSIF fromCluster = 2 THEN// Average cluster (intermediate centroid value)IF centroid1 > centroid2 and centroid1 < centroid3 THENfor j = 1 to lastset($cluster1Perf) doperf = perf + $cluster1Perf[j]fact = fact + $cluster1Factors[j]nextfinalFactor = fact / lastset($cluster1Factors)finalPerf = perf / lastset($cluster1Perf)elsif centroid2 > centroid1 and centroid2 < centroid3 THENfor j = 1 to lastset($cluster2Perf) doperf = perf + $cluster2Perf[j]fact = fact + $cluster2Factors[j]nextfinalFactor = fact / lastset($cluster2Factors)finalPerf = perf / lastset($cluster2Perf)elsefor j = 1 to lastset($cluster3Perf) doperf = perf + $cluster3Perf[j]fact = fact + $cluster3Factors[j]nextfinalFactor = fact / lastset($cluster3Factors)finalPerf = perf / lastset($cluster3Perf)ENDIFELSIF fromCluster = 3 THEN// Worst cluster (lowest centroid value)IF centroid1 < min(centroid2, centroid3) THENfor j = 1 to lastset($cluster1Perf) doperf = perf + $cluster1Perf[j]fact = fact + $cluster1Factors[j]nextfinalFactor = fact / lastset($cluster1Factors)finalPerf = perf / lastset($cluster1Perf)elsif centroid2 < min(centroid1, centroid3) THENfor j = 1 to lastset($cluster2Perf) doperf = perf + $cluster2Perf[j]fact = fact + $cluster2Factors[j]nextfinalFactor = fact / lastset($cluster2Factors)finalPerf = perf / lastset($cluster2Perf)elsefor j = 1 to lastset($cluster3Perf) doperf = perf + $cluster3Perf[j]fact = fact + $cluster3Factors[j]nextfinalFactor = fact / lastset($cluster3Factors)finalPerf = perf / lastset($cluster3Perf)ENDIFENDIF//---------------------------------------------------------------////---------------------------------------------------------------//newup = (high + low) / 2 + atr * finalfactornewdown = (high + low) / 2 - atr * finalfactorif close[1] < newupper thennewupper = min(newup, newupper)elsenewupper = newupendifif close[1] > newlower thennewlower = max(newdown, newlower)elsenewlower = newdownendifif close > newupper thennewOS = 1elsif close < newlower thennewOS = 0elsenewOS = newOSendifif newOS thennewST = newlowerr = 0g = 255elsenewST = newupperr = 255g = 0endif//---------------------------------------------------------------////---------------------------------------------------------------//return newST style(point,2)coloured(r,g,0)1 user thanked author for this post.
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
Find exclusive trading pro-tools on
Similar topics: