Trend Duraration Forecast Indicator – Conversion

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #253875 quote
    adeelq79
    Participant
    Average

    Him this looks like a simple but interesting indicator. Please can someone convert it?

    https://www.tradingview.com/script/L3SJFfAQ-Trend-Duration-Forecast-ChartPrime/

    #253889 quote
    jacquesgermain
    Participant
    Senior
    hello : // ====================================================================== // 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 = 0 ONCE bullIndex = 1 ONCE bearIndex = 1 // ====================================================================== // CALCUL HMA // ====================================================================== hmabase = close halfLength = FLOOR(length / 2) IF halfLength < 1 THEN halfLength = 1 ENDIF sqrtLength = FLOOR(POW(length, 0.5)) IF sqrtLength < 1 THEN sqrtLength = 1 ENDIF wma1 = WeightedAverage[halfLength](hmabase) wma2 = WeightedAverage[length](hmabase) tempHma = 2 * wma1 – wma2 hma = WeightedAverage[sqrtLength](tempHma) // ====================================================================== // DÉTECTION DU TREND // ====================================================================== trendUp = 0 trendDown = 0 IF hma > hma[trendLength] THEN trendUp = 1 ELSIF hma < hma[trendLength] THEN trendDown = 1 ENDIF IF 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 = trendCount IF trend = 1 THEN avgDuration = bullAvg ELSE avgDuration = bearAvg ENDIF RETURN hma AS “hma”
    Iván González and robertogozzi thanked this post
    #253890 quote
    jacquesgermain
    Participant
    Senior
    correction cd=round(bearAvg)
    #253891 quote
    adeelq79
    Participant
    Average
    thank you for the quick reply !
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
adeelq79 @adeelq79 Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by adeelq79
5 months ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 11/22/2025
Status: Active
Attachments: No files
Logo Logo
Loading...