moyenne des Moy3plushauts et des Moy3plusbas

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #266017 quote
    finplusfinplus
    Participant
    Master

    Bonsoir,

    ci-dessous une copie de l’indicateur que certains animateurs de ce site m’ont développé.


    /////////////////////////////////////KAMA 150
    
    Period = 150
    FastPeriod = 2
    SlowPeriod = 50
     
    Fastest = 2 / (FastPeriod + 1)
    Slowest = 2 / (SlowPeriod + 1)
    if barindex < Period+1 then
    Kama=close
    else
    Num = abs(xclose-xclose[Period])
    Den = summation[Period](abs(xclose-xclose[1]))
    ER = Num / Den
    Alpha = SQUARE(ER *(Fastest - Slowest )+ Slowest)
    KAMA = (Alpha * Close) + ((1 -Alpha)* Kama[1])
    endif
     
    
    ///////////////////////////////////////////////////////////////////: Distance Cours KAMA
     
    xClose = (Open+High+Low+Close)/4
    Distance = (xclose- kama)
    moy = average[50]((distance))
    
    
    if Moy<Moy[1] and Moy[1]>Moy[2] and Moy[1]>0 then
    ///RetB5=RetB4
    ///RetB4=RetB3
    RetB3=RetB2
    RetB2=RetB1
    RetB1=Moy[1]
    BandeHaute=(RetB1+RetB2+RetB3)/3
    endif
    
    if Moy>Moy[1] and Moy[1]<Moy[2] and Moy[1]<0 then
    ///RetH5=RetH4
    ///RetH4=RetH3
    RetH3=RetH2
    RetH2=RetH1
    RetH1=Moy[1]
    BandeBasse=(RetH1+RetH2+RetH3)/3
    endif
    
    for i=0 to 49
    $montab[i]=distance[i]
    Next
    
    arraysort($montab,ascend)
    moy3plusBas = ($montab[0] + $montab[1] + $montab[2]) / 3
    moy3plusHauts = ($montab[49] + $montab[48] + $montab[47]) / 3
    
    
    if (distance > moy3plushauts) then
    drawcandle (0,0, distance, distance) COLOURED (32, 0, 192)
    endif
    
    if (distance < moy3plusbas) then
    drawcandle (0,0, distance, distance) COLOURED (235,0,0)
    endif
    
    if (distance > moy) and (distance < moy3plushauts) and (distance > 0) then
    drawcandle (0, 0, distance, distance) coloured (0, 204, 255)
    endif
    
    if (Distance < moy) and (distance > moy3plusbas) and (distance < 0) then
    drawcandle (0, 0, distance, distance) coloured (255, 204, 153)
    endif
    
    
    
    moy3plus = average[50](moy3plushauts - moy3plusbas)
    aplushauts = moy+(moy3plus/2)
    aplusbas = moy-(moy3plus/2)
    
    
    
    
    lookbackBars = 320 // Fenetre d'analyse (~2 mois en 1h)
    minPeakDist = 15  // Distance min entre pics (barres)
    
    
    // ================================================================
    // NEW: Ligne des 3 pics les plus hauts de moy3plusHauts
    // ================================================================
    once peakCntH = 0
    
    // Detecter pic local de moy3plusHauts
    IF moy3plusHauts < moy3plusHauts[1] AND moy3plusHauts[1] >= moy3plusHauts[2] THEN
    canStore = 1
    // Si trop proche du dernier pic stocke, garder le plus haut
    IF peakCntH > 0 THEN
    lastBarH = $peakBarH[peakCntH - 1]
    IF barindex - 1 - lastBarH < minPeakDist THEN
    IF moy3plusHauts[1] > $peakValH[peakCntH - 1] THEN
    $peakValH[peakCntH - 1] = moy3plusHauts[1]
    $peakBarH[peakCntH - 1] = barindex - 1
    ENDIF
    canStore = 0
    ENDIF
    ENDIF
    IF canStore THEN
    $peakValH[peakCntH] = moy3plusHauts[1]
    $peakBarH[peakCntH] = barindex - 1
    peakCntH = peakCntH + 1
    ENDIF
    ENDIF
    
    // Trouver les 3 plus hauts dans la fenetre
    h1 = 0
    h2 = 0
    h3 = 0
    IF peakCntH > 0 THEN
    FOR i = 0 TO peakCntH - 1 DO
    IF barindex - $peakBarH[i] <= lookbackBars THEN
    IF $peakValH[i] > h1 THEN
    h3 = h2
    h2 = h1
    h1 = $peakValH[i]
    ELSIF $peakValH[i] > h2 THEN
    h3 = h2
    h2 = $peakValH[i]
    ELSIF $peakValH[i] > h3 THEN
    h3 = $peakValH[i]
    ENDIF
    ENDIF
    NEXT
    ENDIF
    
    IF h3 > 0 THEN
    lineHaut = (h1 + h2 + h3) / 3
    ELSIF h2 > 0 THEN
    lineHaut = (h1 + h2) / 2
    ELSIF h1 > 0 THEN
    lineHaut = h1
    ENDIF
    
    // ================================================================
    // NEW: Ligne des 3 creux les plus bas de moy3plusBas
    // ================================================================
    once peakCntL = 0
    
    // Detecter creux local de moy3plusBas
    IF moy3plusBas > moy3plusBas[1] AND moy3plusBas[1] <= moy3plusBas[2] THEN
    canStoreL = 1
    // Si trop proche du dernier creux stocke, garder le plus bas
    IF peakCntL > 0 THEN
    lastBarL = $peakBarL[peakCntL - 1]
    IF barindex - 1 - lastBarL < minPeakDist THEN
    IF moy3plusBas[1] < $peakValL[peakCntL - 1] THEN
    $peakValL[peakCntL - 1] = moy3plusBas[1]
    $peakBarL[peakCntL - 1] = barindex - 1
    ENDIF
    canStoreL = 0
    ENDIF
    ENDIF
    IF canStoreL THEN
    $peakValL[peakCntL] = moy3plusBas[1]
    $peakBarL[peakCntL] = barindex - 1
    peakCntL = peakCntL + 1
    ENDIF
    ENDIF
    
    // Trouver les 3 plus bas dans la fenetre
    l1 = 0
    l2 = 0
    l3 = 0
    IF peakCntL > 0 THEN
    FOR i = 0 TO peakCntL - 1 DO
    IF barindex - $peakBarL[i] <= lookbackBars THEN
    IF $peakValL[i] < l1 THEN
    l3 = l2
    l2 = l1
    l1 = $peakValL[i]
    ELSIF $peakValL[i] < l2 THEN
    l3 = l2
    l2 = $peakValL[i]
    ELSIF $peakValL[i] < l3 THEN
    l3 = $peakValL[i]
    ENDIF
    ENDIF
    NEXT
    ENDIF
    
    IF l3 < 0 THEN
    lineBas = (l1 + l2 + l3) / 3
    ELSIF l2 < 0 THEN
    lineBas = (l1 + l2) / 2
    ELSIF l1 < 0 THEN
    lineBas = l1
    ENDIF
    
    
    // ================================================================
    RETURN distance AS "Distance", moy AS "Distance Moy", BandeHaute AS "Bande Haute", BandeBasse AS "Bande Basse", moy3plusHauts AS "FilterUp", moy3plusBas AS "FilterDn", lineHaut AS "Ligne Haute", lineBas AS "Ligne Basse", aplushauts as "aplushauts", aplusbas as "aplusbas"
    



    Ma demande est la suivante : je souhaiterai que soit tracée la moyenne des 5 ou 6 derniers Moy3plushauts et des 5 ou 6 derniers Moy3plusbas.

    Par exemple, j’ai joint un graphique USD CAD en Timeframe 1 heure qui date du lundi 2 novembre à 19h30 environ.

    J’ai marqué avec une flèche les Moy3plushauts à retenir (selon moi) en ne prenant en compte que les Moy3plushauts qui ont une certaine durée (par exemple un trait plat qui dure 24 X 1 heure). Autrement dit, je souhaite exclure les Moy3plushauts qui ne dure que quelques UT. Selon mes calculs faits à la louche, la moyenne des 5 moy3plushauts identifiés aboutirait à une ligne horizontale = 0,0026.


    En outre, je ne sais pas quel historique de calcul il faut prendre. Je suis sur Prorealtime V12.


    Merci pour votre aide.

    Capture-decran-2026-11-02-a-19.34.08-scaled.png Capture-decran-2026-11-02-a-19.34.08-scaled.png
    #266019 quote
    finplusfinplus
    Participant
    Master

    Je précise que la ligne horizontale a été tracée par moi-même “à la main” et est censée représenter le rendu finale.

    Merci.

    #266021 quote
    Iván GonzálezIván González
    Moderator
    Legend

    bonjour! Voici le code avec deux nouvelles lignes (en vert).

    Les deux paramètres sont en tête du code :

    • minDuree = 24 : durée minimale d’un palier, en barres (votre exemple de 24 x 1 heure)
    • nbPaliers = 5 : nombre de paliers dans la moyenne (mettez 6 si vous préférez)
    //-------------------------------------------------//
    // PRC_KAMA Distance Enhanced
    // version = 2
    // 03.11.2026
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    //-------------------------------------------------//
    
    // === INPUTS ===
    Period = 150
    FastPeriod = 2
    SlowPeriod = 50
    lookbackBars = 320  // Fenetre d'analyse (~2 mois en 1h)
    minPeakDist = 15    // Distance min entre pics (barres)
    minDuree = 24       // Duree minimale d'un palier de FilterUp / FilterDn (barres)
    nbPaliers = 5       // Nombre de paliers dans la moyenne
    
    // === KAMA ===
    Fastest = 2 / (FastPeriod + 1)
    Slowest = 2 / (SlowPeriod + 1)
    
    IF barindex < Period + 1 THEN
       Kama = close
    ELSE
       Num = abs(xclose - xclose[Period])
       Den = summation[Period](abs(xclose - xclose[1]))
       ER = Num / Den
       Alpha = SQUARE(ER * (Fastest - Slowest) + Slowest)
       KAMA = (Alpha * Close) + ((1 - Alpha) * Kama[1])
    ENDIF
    
    // === DISTANCE COURS-KAMA ===
    xClose = (Open + High + Low + Close) / 4
    Distance = (xclose - kama)
    moy = average[50](distance)
    
    // === BANDE HAUTE (rolling 3 peaks of moy) ===
    IF Moy < Moy[1] AND Moy[1] > Moy[2] AND Moy[1] > 0 THEN
       RetB3 = RetB2
       RetB2 = RetB1
       RetB1 = Moy[1]
       BandeHaute = (RetB1 + RetB2 + RetB3) / 3
    ENDIF
    
    // === BANDE BASSE (rolling 3 troughs of moy) ===
    IF Moy > Moy[1] AND Moy[1] < Moy[2] AND Moy[1] < 0 THEN
       RetH3 = RetH2
       RetH2 = RetH1
       RetH1 = Moy[1]
       BandeBasse = (RetH1 + RetH2 + RetH3) / 3
    ENDIF
    
    // === FILTER (top/bottom 3 of distance over 50 bars) ===
    FOR i = 0 TO 49 DO
       $montab[i] = distance[i]
    NEXT
    
    arraysort($montab, ascend)
    moy3plusBas = ($montab[0] + $montab[1] + $montab[2]) / 3
    moy3plusHauts = ($montab[49] + $montab[48] + $montab[47]) / 3
    
    // === CANDLE COLORING ===
    IF distance > moy3plushauts THEN
       drawcandle(0, 0, distance, distance) coloured(32, 0, 192)
    ENDIF
    IF distance < moy3plusbas THEN
       drawcandle(0, 0, distance, distance) coloured(235, 0, 0)
    ENDIF
    IF distance > moy AND distance < moy3plushauts AND distance > 0 THEN
       drawcandle(0, 0, distance, distance) coloured(0, 204, 255)
    ENDIF
    IF Distance < moy AND distance > moy3plusbas AND distance < 0 THEN
       drawcandle(0, 0, distance, distance) coloured(255, 204, 153)
    ENDIF
    
    moy3plus = average[50](moy3plushauts - moy3plusbas)
    aplushauts = moy + (moy3plus / 2)
    aplusbas = moy - (moy3plus / 2)
    
    // ================================================================
    // Ligne des 3 pics les plus hauts de moy3plusHauts
    // ================================================================
    once peakCntH = 0
    
    // Detecter pic local de moy3plusHauts
    IF moy3plusHauts < moy3plusHauts[1] AND moy3plusHauts[1] >= moy3plusHauts[2] THEN
       canStore = 1
       // Si trop proche du dernier pic stocke, garder le plus haut
       IF peakCntH > 0 THEN
          lastBarH = $peakBarH[peakCntH - 1]
          IF barindex - 1 - lastBarH < minPeakDist THEN
             IF moy3plusHauts[1] > $peakValH[peakCntH - 1] THEN
                $peakValH[peakCntH - 1] = moy3plusHauts[1]
                $peakBarH[peakCntH - 1] = barindex - 1
             ENDIF
             canStore = 0
          ENDIF
       ENDIF
       IF canStore THEN
          $peakValH[peakCntH] = moy3plusHauts[1]
          $peakBarH[peakCntH] = barindex - 1
          peakCntH = peakCntH + 1
       ENDIF
    ENDIF
    
    // Trouver les 3 plus hauts dans la fenetre
    h1 = 0
    h2 = 0
    h3 = 0
    IF peakCntH > 0 THEN
       FOR i = 0 TO peakCntH - 1 DO
          IF barindex - $peakBarH[i] <= lookbackBars THEN
             IF $peakValH[i] > h1 THEN
                h3 = h2
                h2 = h1
                h1 = $peakValH[i]
             ELSIF $peakValH[i] > h2 THEN
                h3 = h2
                h2 = $peakValH[i]
             ELSIF $peakValH[i] > h3 THEN
                h3 = $peakValH[i]
             ENDIF
          ENDIF
       NEXT
    ENDIF
    
    IF h3 > 0 THEN
       lineHaut = (h1 + h2 + h3) / 3
    ELSIF h2 > 0 THEN
       lineHaut = (h1 + h2) / 2
    ELSIF h1 > 0 THEN
       lineHaut = h1
    ENDIF
    
    // ================================================================
    // Ligne des 3 creux les plus bas de moy3plusBas
    // ================================================================
    once peakCntL = 0
    
    // Detecter creux local de moy3plusBas
    IF moy3plusBas > moy3plusBas[1] AND moy3plusBas[1] <= moy3plusBas[2] THEN
       canStoreL = 1
       // Si trop proche du dernier creux stocke, garder le plus bas
       IF peakCntL > 0 THEN
          lastBarL = $peakBarL[peakCntL - 1]
          IF barindex - 1 - lastBarL < minPeakDist THEN
             IF moy3plusBas[1] < $peakValL[peakCntL - 1] THEN
                $peakValL[peakCntL - 1] = moy3plusBas[1]
                $peakBarL[peakCntL - 1] = barindex - 1
             ENDIF
             canStoreL = 0
          ENDIF
       ENDIF
       IF canStoreL THEN
          $peakValL[peakCntL] = moy3plusBas[1]
          $peakBarL[peakCntL] = barindex - 1
          peakCntL = peakCntL + 1
       ENDIF
    ENDIF
    
    // Trouver les 3 plus bas dans la fenetre
    l1 = 0
    l2 = 0
    l3 = 0
    IF peakCntL > 0 THEN
       FOR i = 0 TO peakCntL - 1 DO
          IF barindex - $peakBarL[i] <= lookbackBars THEN
             IF $peakValL[i] < l1 THEN
                l3 = l2
                l2 = l1
                l1 = $peakValL[i]
             ELSIF $peakValL[i] < l2 THEN
                l3 = l2
                l2 = $peakValL[i]
             ELSIF $peakValL[i] < l3 THEN
                l3 = $peakValL[i]
             ENDIF
          ENDIF
       NEXT
    ENDIF
    
    IF l3 < 0 THEN
       lineBas = (l1 + l2 + l3) / 3
    ELSIF l2 < 0 THEN
       lineBas = (l1 + l2) / 2
    ELSIF l1 < 0 THEN
       lineBas = l1
    ENDIF
    
    // ================================================================
    // NEW: Moyenne des N derniers paliers de moy3plusHauts et moy3plusBas
    // Un palier = FilterUp (ou FilterDn) reste plat pendant au moins minDuree barres
    // ================================================================
    once nPalH = 0
    once nPalB = 0
    
    // Duree du palier en cours (barres consecutives sans changement)
    IF moy3plusHauts = moy3plusHauts[1] THEN
       dureeH = dureeH + 1
    ELSE
       dureeH = 1
    ENDIF
    IF moy3plusBas = moy3plusBas[1] THEN
       dureeB = dureeB + 1
    ELSE
       dureeB = 1
    ENDIF
    
    // Un palier est retenu une seule fois : a la barre ou il atteint minDuree
    // (on ignore le demarrage de la KAMA et de la fenetre de 50 barres)
    IF barindex > Period + 50 THEN
       IF dureeH = minDuree THEN
          $palH[nPalH] = moy3plusHauts
          nPalH = nPalH + 1
       ENDIF
       IF dureeB = minDuree THEN
          $palB[nPalB] = moy3plusBas
          nPalB = nPalB + 1
       ENDIF
    ENDIF
    
    // Moyenne des nbPaliers derniers paliers retenus
    IF nPalH >= nbPaliers THEN
       sommeH = 0
       FOR k = nPalH - nbPaliers TO nPalH - 1 DO
          sommeH = sommeH + $palH[k]
       NEXT
       moyPalH = sommeH / nbPaliers
    ELSE
       moyPalH = undefined
    ENDIF
    IF nPalB >= nbPaliers THEN
       sommeB = 0
       FOR k = nPalB - nbPaliers TO nPalB - 1 DO
          sommeB = sommeB + $palB[k]
       NEXT
       moyPalB = sommeB / nbPaliers
    ELSE
       moyPalB = undefined
    ENDIF
    
    // ================================================================
    RETURN distance AS "Distance", moy AS "Distance Moy", BandeHaute AS "Bande Haute", BandeBasse AS "Bande Basse", moy3plusHauts AS "FilterUp", moy3plusBas AS "FilterDn", lineHaut AS "Ligne Haute", lineBas AS "Ligne Basse", aplushauts AS "aplushauts", aplusbas AS "aplusbas", moyPalH AS "Moy Paliers Hauts" coloured(0, 150, 0) style(line, 3), moyPalB AS "Moy Paliers Bas" coloured(0, 150, 0) style(line, 3)
    
    
    finplus thanked this post
    MNQXXXX-5-minutos.png MNQXXXX-5-minutos.png
    #266032 quote
    finplusfinplus
    Participant
    Master

    merci pour ce travail. je vais le tester et vous ferai un retour.

    Bonne soirée.

Viewing 4 posts - 1 through 4 (of 4 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

moyenne des Moy3plushauts et des Moy3plusbas


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
finplus @finplus Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by finplusfinplus
2 days, 18 hours ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 11/02/2026
Status: Active
Attachments: 2 files
ProRealCode ProRealCode
Loading...