Affichage uniquement de la dernière divergence

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #236971 quote
    patokipatoki
    Participant
    New

    Bonjour, j’avais trouvé ce code pour l’affichage de divergence sur le Macd. Il m’affiche toute les divergences passées, mais je souhaite ne garder que la dernière. Quelqu’un aurait-il une solution ?

    Je vous remercie.

    N=15///N is the number of bars to look back for a divergence. Normal values are 20-40. Must be the same in both indicators

    miMACD = exponentialAverage[12](close) – exponentialAverage[26](close)

    IF (BarIndex > 10+1+N) THEN

    ///divergencia bajista
    IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
    extremum2=miMACD[1]
    extremum1=highest[N](miMACD)

    preciomax2=close[1]
    preciomax=Highest[N](close)
    //IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
    IF extremum2<extremum1 THEN
    for i=1 to N
    if mimacd[i]=extremum1 then
    zz=i

    drawsegment (barindex[1], mimacd[1], barindex[zz], mimacd[zz]) coloured(200,200,0)style(line,1)
    endif
    next

    endif
    endif

    ///divergencia alcista
    IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
    extremum22=miMACD[1]
    extremum11=lowest[N](miMACD)

    preciomin2=close[1]
    preciomin=lowest[N](close)
    //IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
    IF extremum22>extremum11 THEN
    for i2=1 to N
    if mimacd[i2]=extremum11[1] then
    zz2=i2

    drawsegment(barindex[1], mimacd[1], barindex[zz2], mimacd[zz2]) coloured(0,200,200)style(line,1)
    endif
    next
    ENDIF

    ENDIF
    endif

    return mimacd as “MACD”, 0 as “0”

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

    Salut Ici vous avez une option sans modifier votre code, en calculant simplement les points du segment sous forme de tableaux. La seule chose que j'ai faite a été d'ajouter à la fin de votre code l'instruction lastbarupdate pour qu'elle dessine simplement

    //defparam drawonlastbaronly=true
    
    N=15///N is the number of bars to look back for a divergence. Normal values are 20-40. Must be the same in both indicators
    
    miMACD = exponentialAverage[12](close) - exponentialAverage[26](close)
    
    IF (BarIndex > 10+1+N) THEN
    ///divergencia bajista
    IF (miMACD[1]>miMACD AND miMACD[1]>miMACD[2]) THEN
    extremum2=miMACD[1]
    extremum1=highest[N](miMACD)
    
    preciomax2=close[1]
    preciomax=Highest[N](close)
    
    IF extremum2<extremum1 THEN
    for i=1 to N
    if mimacd[i]=extremum1 then
    zz=i
    $xx11[0]=barindex[1]
    $yy11[0]=mimacd[1]
    $xx12[0]=barindex[zz]
    $yy12[0]=mimacd[zz]
    endif
    next
    endif
    endif
    
    ///divergencia alcista
    IF (miMACD[1]<miMACD AND miMACD[1]<miMACD[2]) THEN
    extremum22=miMACD[1]
    extremum11=lowest[N](miMACD)
    
    preciomin2=close[1]
    preciomin=lowest[N](close)
    
    IF extremum22>extremum11 THEN
    for i2=1 to N
    if mimacd[i2]=extremum11[1] then
    zz2=i2
    $xx21[0]=barindex[1]
    $yy21[0]=mimacd[1]
    $xx22[0]=barindex[zz2]
    $yy22[0]=mimacd[zz2]
    endif
    next
    ENDIF
    ENDIF
    endif
    if islastbarupdate then
    drawsegment ($xx11[0], $yy11[0], $xx12[0], $yy12[0]) coloured(200,200,0)style(line,1)
    drawsegment($xx21[0], $yy21[0], $xx22[0], $yy22[0]) coloured(0,200,200)style(line,1)
    endif
    
    return mimacd as "MACD", 0 as "0"

    le dernier segment.

    #237209 quote
    patokipatoki
    Participant
    New

    Super, merci beaucoup

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

From idea to ProBuilder code in seconds.

Your coding copilot for ProRealTime™. Ask in plain English — get clean, ready-to-paste indicators, screeners and systems.

Available in 7 languages
Try ProRealAI

Affichage uniquement de la dernière divergence


Support Plateforme : Graphiques, Données & Courtiers

New Reply
Author
author-avatar
patoki @patoki Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by patokipatoki
2 years ago.

Topic Details
Forum: Support Plateforme : Graphiques, Données & Courtiers
Language: French
Started: 09/01/2024
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...