Trend Duraration Forecast Indicator – Conversion
Forums › ProRealTime English forum › ProBuilder support › Trend Duraration Forecast Indicator – Conversion
- This topic has 3 replies, 2 voices, and was last updated 2 weeks ago by
adeelq79.
-
-
11/22/2025 at 11:57 AM #253875
Him this looks like a simple but interesting indicator. Please can someone convert it?
https://www.tradingview.com/script/L3SJFfAQ-Trend-Duration-Forecast-ChartPrime/
11/22/2025 at 6:33 PM #253889hello :
// ======================================================================
// TREND DURATION FORECAST — PROREALTIME
/// ======================================================================
// ———- PARAMÈTRES ———-
length = 50
trendLength = 3
samples = 10
offset=0.8
// ———- VARIABLES ———-
ONCE trend = 0
ONCE trendCount = 0
ONCE prevTrend = 0
ONCE lastTrendDuration = 0
ONCE showLastTrendText = 0// Historique UP
ONCE bull1 = 0
ONCE bull2 = 0
ONCE bull3 = 0
ONCE bull4 = 0
ONCE bull5 = 0
ONCE bull6 = 0
ONCE bull7 = 0
ONCE bull8 = 0
ONCE bull9 = 0
ONCE bull10 = 0// Historique DOWN
ONCE bear1 = 0
ONCE bear2 = 0
ONCE bear3 = 0
ONCE bear4 = 0
ONCE bear5 = 0
ONCE bear6 = 0
ONCE bear7 = 0
ONCE bear8 = 0
ONCE bear9 = 0
ONCE bear10 = 0ONCE bullIndex = 1
ONCE bearIndex = 1// ======================================================================
// CALCUL HMA
// ======================================================================hmabase = close
halfLength = FLOOR(length / 2)
IF halfLength < 1 THEN
halfLength = 1
ENDIFsqrtLength = FLOOR(POW(length, 0.5))
IF sqrtLength < 1 THEN
sqrtLength = 1
ENDIFwma1 = WeightedAverage[halfLength](hmabase)
wma2 = WeightedAverage[length](hmabase)tempHma = 2 * wma1 – wma2
hma = WeightedAverage[sqrtLength](tempHma)// ======================================================================
// DÉTECTION DU TREND
// ======================================================================trendUp = 0
trendDown = 0IF hma > hma[trendLength] THEN
trendUp = 1
ELSIF hma < hma[trendLength] THEN
trendDown = 1
ENDIFIF trendUp = 1 THEN
newTrend = 1
ELSIF trendDown = 1 THEN
newTrend = -1
ELSE
newTrend = trend
ENDIF// ======================================================================
// CHANGEMENT DE TREND ET HISTORIQUE
// ======================================================================IF newTrend <> trend THEN
// sauvegarde durée et ancienne tendance
lastTrendDuration = trendCount
prevTrend = trend
showLastTrendText = 1// Sauvegarde dans historique UP
IF trend = 1 THEN
IF bullIndex = 1 THEN
bull1 = trendCount
ELSIF bullIndex = 2 THEN
bull2 = trendCount
ELSIF bullIndex = 3 THEN
bull3 = trendCount
ELSIF bullIndex = 4 THEN
bull4 = trendCount
ELSIF bullIndex = 5 THEN
bull5 = trendCount
ELSIF bullIndex = 6 THEN
bull6 = trendCount
ELSIF bullIndex = 7 THEN
bull7 = trendCount
ELSIF bullIndex = 8 THEN
bull8 = trendCount
ELSIF bullIndex = 9 THEN
bull9 = trendCount
ELSIF bullIndex = 10 THEN
bull10 = trendCount
ENDIF
bullIndex = bullIndex + 1
IF bullIndex > samples THEN
bullIndex = 1
ENDIF// Sauvegarde dans historique DOWN
ELSIF trend = -1 THEN
IF bearIndex = 1 THEN
bear1 = trendCount
ELSIF bearIndex = 2 THEN
bear2 = trendCount
ELSIF bearIndex = 3 THEN
bear3 = trendCount
ELSIF bearIndex = 4 THEN
bear4 = trendCount
ELSIF bearIndex = 5 THEN
bear5 = trendCount
ELSIF bearIndex = 6 THEN
bear6 = trendCount
ELSIF bearIndex = 7 THEN
bear7 = trendCount
ELSIF bearIndex = 8 THEN
bear8 = trendCount
ELSIF bearIndex = 9 THEN
bear9 = trendCount
ELSIF bearIndex = 10 THEN
bear10 = trendCount
ENDIF
bearIndex = bearIndex + 1
IF bearIndex > samples THEN
bearIndex = 1
ENDIF
ENDIF// reset compteur pour nouvelle tendance
trendCount = 0
trend = newTrend
ENDIF// ======================================================================
// INCRÉMENTATION DUREE
// ======================================================================trendCount = trendCount + 1
// ======================================================================
// CALCUL MOYENNES
// ======================================================================bullAvg = (bull1 + bull2 + bull3 + bull4 + bull5 + bull6 + bull7 + bull8 + bull9 + bull10) / samples
bearAvg = (bear1 + bear2 + bear3 + bear4 + bear5 + bear6 + bear7 + bear8 + bear9 + bear10) / samples// ======================================================================
// TEXTE SUR DERNIÈRE BOUGIE DE TENDANCE TERMINÉE
// ======================================================================IF showLastTrendText = 1 THEN
IF prevTrend = 1 THEN
cc=round(bullAvg)
DRAWTEXT(“▲ sur #lastTrendDuration#j moy: #cc#”, barindex, hma+0.8) coloured(“green”)
ELSIF prevTrend = -1 THEN
cd=round(bullAvg)
DRAWTEXT(“▼ sur #lastTrendDuration#j moy: #cd#”, barindex,hma-0.8) coloured(“red”)
ENDIF
showLastTrendText = 0
ENDIF// ======================================================================
// TEXTE DURÉE EN COURS (toutes les bougies de la tendance actuelle, décalé)
// ======================================================================
IF ISLASTBARUPDATE then
IF trend = 1 THEN
ca=round(bullAvg)
DRAWTEXT(“▲ dur en cours: #trendCount#j probable: #ca#”, barindex,hma+0.8) coloured(“blue”)
ELSIF trend = -1 THEN
cb=round(bearAvg)
DRAWTEXT(“▼ dur en cours: #trendCount#j probable: #cb#”, barindex, hma-0.8)coloured(“violet”)
ENDIF
endif
currentDuration = trendCountIF trend = 1 THEN
avgDuration = bullAvg
ELSE
avgDuration = bearAvg
ENDIFRETURN hma AS “hma”
2 users thanked author for this post.
11/22/2025 at 7:13 PM #253890correction cd=round(bearAvg)
11/22/2025 at 8:28 PM #253891 -
AuthorPosts
