CONVERTION RVOL TW

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #265494 quote
    Armand2020Armand2020
    Participant
    Senior

    BONJOUR SERAIT TIL POSSIBLE DE CONVERTIR CE CODE MERCI:


    //@version=6

    indicator(shorttitle = ‘RVol Multi-Timeframes’, title = ‘Relative Volume Multi-Timeframes (Multi-Levels)’, precision = 2, max_bars_back = 5000)


    // Sécurité temporelle assouplie (Seuls les graphiques en secondes sont exclus)

    if timeframe.isseconds

        runtime.error(‘RVol n’est pas valide sur les graphiques en secondes’)


    // ==========================================

    // ⚙️ ENTRÉES & PARAMÈTRES

    // ==========================================

    var string G_PARAM  = “Configuration Générale”

    var string G_THRESH = “Seuils RVol (Niveaux)”

    var string G_COLORS = “Couleurs des Niveaux”

    var string G_MA     = “Configuration Moyenne Mobile”


    // Paramètres généraux

    days = input.int(10, minval = 1, title = ‘Moyenne sur N périodes (ou jours)’, group = G_PARAM)



    // Seuils RVol (Du plus haut au plus bas)

    thresVeryHigh = input.float(2.0, minval = 0.0, step = 0.1, title = ‘Seuil : Volume Très Élevé’, group = G_THRESH)

    thresHigh     = input.float(1.5, minval = 0.0, step = 0.1, title = ‘Seuil : Volume Élevé’, group = G_THRESH)

    thresModerate = input.float(1.2, minval = 0.0, step = 0.1, title = ‘Seuil : Volume Modéré’, group = G_THRESH)


    // Couleurs d’origine strictement restaurées

    c_veryHigh = input.color(color.rgb(200, 247, 255), title = ‘Couleur : Très Élevé 🔴’, group = G_COLORS)

    c_high     = input.color(#20bbb8, title = ‘Couleur : Élevé 🟠’, group = G_COLORS)

    c_moderate = input.color(color.rgb(0, 255, 251, 59), title = ‘Couleur : Modéré 🟢’, group = G_COLORS)

    c_low      = input.color(#26a6a43b, title = ‘Couleur : Faible ⚪’, group = G_COLORS)


    // Paramètres de la Moyenne de Wilder (RMA)

    wilderLength = input.int(10, minval = 1, title = ‘Longueur de Wilder’, group = G_MA)

    c_maUp       = input.color(color.rgb(255, 255, 255), title = ‘Wilder en hausse’, group = G_MA)

    c_maDown     = input.color(color.rgb(212, 0, 255), title = ‘Wilder en baisse’, group = G_MA)


    // ==========================================

    // 📊 FONCTIONS & LOGIQUE DE CALCUL

    // ==========================================

    isNewDay() =>

        t = time(‘1D’)

        (na(t[1]) and not na(t)) or t[1] < t


    float rVol = na


    // Détection si c’est un Future (les marchés 24h génèrent des erreurs sur le script d’origine)

    is24hMarket = syminfo.type == “futures” or syminfo.type == “forex” or syminfo.type == “crypto”


    if timeframe.isintraday

        // — LOGIQUE INTRADAY ACTIONS (Basée sur le temps) —

        var cVol = 0.0

        var newDayBars = array.new_int()


        if isNewDay()

            cVol := 0

            array.push(newDayBars, bar_index)

            if array.size(newDayBars) > days + 1

                array.shift(newDayBars)

            line.new(bar_index, 0, bar_index, 0, extend = extend.left, color = color.gray, style = line.style_dotted)


        timeSessionStart = time(‘1D’)

        cVol := cVol + volume


        aVol = 0.0

        len = array.size(newDayBars)

        if len >= days + 1

            for i = 0 to len – 2 by 1

                b1 = array.get(newDayBars, i)

                b2 = array.get(newDayBars, i + 1)


                daysBetweenSessions = math.round((timeSessionStart – timeSessionStart[bar_index – b1]) / (24 * 60 * 60 * 1000))

                tLookup = timestamp(year(time), month(time), dayofmonth(time) – daysBetweenSessions, hour(time), minute(time), second(time))


                int lo = math.max(0, b1) – 1

                int hi = math.max(0, b2)

                while 1 + lo < hi

                    int mi = lo + math.floor((hi – lo) / 2)

                    if tLookup < time[bar_index – mi]

                        hi := mi

                    else

                        lo := mi

                lo := lo < b1 ? hi : lo

                bClosest = b1 < b2 ? lo : -1


                tClosest = time[bar_index – bClosest]

                aVol := aVol + (tLookup >= tClosest ? cVol[bar_index – bClosest] / days : 0)

       

        rVol := aVol > 0 ? cVol / aVol : na

    else

        // — LOGIQUE STANDARD POUR FUTURES, CRYPTO, DAILY & WEEKLY —

        avgVol = ta.rma(volume, days)

        rVol := avgVol > 0 ? volume / avgVol : na


    // ==========================================

    // 📈 CALCUL DE LA MOYENNE DE WILDER (RMA) DU RVOL

    // ==========================================

    var float rVolWilder = na

    var float lastRVolPrevDay = na

    alpha = 1.0 / wilderLength


    // Capture et sauvegarde de la valeur brute du RVol de la dernière barre juste avant le changement de jour

    if isNewDay()

        lastRVolPrevDay := rVol[1]


    isResetPeriod = (timeframe.isintraday ) ? isNewDay() : bar_index == 0


    // Modification : Initialisation stricte sur le RVol de la dernière barre du jour précédent

    if isResetPeriod

        rVolWilder := nz(lastRVolPrevDay, rVol)

    else

        rVolWilder := na(rVolWilder[1]) ? nz(lastRVolPrevDay, rVol) : alpha * rVol + (1.0 – alpha) * rVolWilder[1]


    // Détermination de la couleur (Dynamique selon la pente)

    maColor = rVolWilder >= rVolWilder[1] ? c_maUp : c_maDown


    // ==========================================

    // 🎨 ATTRIBUTION DES COULEURS EN NIVEAUX

    // ==========================================

    highlightColor = rVol >= thresVeryHigh ? c_veryHigh :

                     rVol >= thresHigh     ? c_high :

                     rVol >= thresModerate ? c_moderate : c_low


    // ==========================================

    // 📈 REPRÉSENTATION VISUELLE & LIGNES

    // ==========================================

    hline(1.0, title = ‘Ligne Neutre (Moyenne)’, color = color.gray, linestyle = hline.style_solid)

    hline(1.2, title = ‘Référence Modéré’, color = color.silver, linestyle = hline.style_dotted)

    hline(1.5, title = ‘Référence Élevé’, color = color.orange, linestyle = hline.style_dotted)

    hline(2.0, title = ‘Référence Très Élevé’, color = color.red, linestyle = hline.style_dotted)


    // Affichage du RVol sous forme de colonnes

    plot(rVol, style = plot.style_columns, color = highlightColor, display = display.all – display.price_scale)


    // Affichage de la Moyenne Mobile de Wilder

    plot(rVolWilder, title = “Moyenne Wilder RVol”, color = maColor, linewidth = 1)


Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Armand2020 @armand2020 Participant
Summary

This topic contains 1 voice and has 0 replies.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 10/06/2026
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...