Recherche avec une boucle DOWNTO

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #236669 quote
    LoulouteLouloute
    Participant
    Average

    Bonjour, je souhaite trouver le barIndex correspondant au croisement de close avec price1 en partant en marche arrière à partir d’un barIndex défini mais je n’y arrive pas. Quelqu’un peut-il regarder mon code ci-dessous pour essayer de voir ce qui ne va pas ?

    Merci !!

     

    Price1 = (high + low)/2

    for g = 30 downTo 0 do
    once a = 1
    if close[a] crosses over price1[a] then
    //if open[a] <= price1[a] and close[a] > price1[] then
    drawVLine(g) style (dottedLine,3)
    //break
    else
    a = a + 1
    endIf
    next

     

    if close crosses over price1 then
    drawVLine(barindex)
    endIf

    return

    Test.itf
    #236671 quote
    drubydruby
    Participant
    New

     

    price1 = (high+low)/2
    
    if islastbarupdate then
    for i = 0 to 30
    
    if close[i] crosses over price1[i] then
    drawVline(barindex-i)coloured("violet",100)style(dottedline,1)
    drawtext(barindex-i,barindex-i,10)anchor(bottom,index,yshift)
    break
    endif
    
    next
    
    endif
    
    return

     

     

    price1 = (high+low)/2
    
    condition = (close crosses over price1)
    
    bar = barssince(condition,0)
    
    print(bar)
    
    if condition then
    drawVline(barindex)coloured("violet",100)style(dottedline,1)
    drawtext(barindex,barindex,10)anchor(bottom,index,yshift)
    endif
    
    return close as"close", price1 as"price1" coloured("red")style(dottedline,1) 
    
    
    
    
    
    Screenshot-2024-08-24-114610.png Screenshot-2024-08-24-114610.png
    #236681 quote
    LoulouteLouloute
    Participant
    Average

    Bonjour Druby,

    Les 2 codes cherchent dans le sens des barIndex et non dans le sens inverse à partir d’un barIndex défini …

    Ce que je recherche c’est trouver le premier croisement mais en repartant en arrière à partir d’un barIndex défini, c’est pour cette raison que j’ai essayé avec la fonction downTo … Exemple, rechercher le 1er croisement de close avec price1 à partir du barIndex = 30 mais cherchant en sens inverse du déroulement normal.

    Un grand merci tout de même, c’est sympa !!

    #236684 quote
    drubydruby
    Participant
    New

    Salut Louloute, je ne suis pas sûr de suivre ta description.

    Mais voici une autre tentative.

    Cela commence à barindex=30, regarde en arrière vers barindex = 0
    jusqu’à ce que la condition IF soit remplie ou que la boucle se termine.

     

     

    price1 = (high+low)/2
    
    if barindex >= 30 then
    
    for i = 30 downto 0
    
    x =  barindex-i
    
    if close[x] crosses over price1[x] then
    
    drawVline(barindex[x])coloured("violet",100)style(dottedline,1)
    drawtext(barindex[x],barindex[x],10)anchor(bottom,index,yshift)
    
    break
    endif
    next
    
    endif
    
    return close as"close", price1 as"price1" coloured("red")style(dottedline,1)
    robertogozzi thanked this post
    Screenshot-2024-08-24-161941.png Screenshot-2024-08-24-161941.png
    #236686 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Cette version imprimera la ligne verticale sur la barre correspondant au premier croisement survenu à partir des barres arrière LOOKBACK.

    baridx est le numéro BARINDEX où le croisement a eu lieu.

    //defparam drawonlastbaronly = true
    LookBack  = 30
    price1    = (high+low)/2
    condition = (close[LookBack] crosses over price1[LookBack])
    IF BarIndex > LookBack THEN
       bar    = barssince(condition,0)
       baridx = barindex[bar + LookBack]
       drawVLine(baridx)
    ENDIF
    return

    Pour voir les numéros BARINDEX, utilisez cet indicateur :

    RETURN BarIndex AS "BarIndex"
    #236720 quote
    LoulouteLouloute
    Participant
    Average

    C’est exactement le comportement attendu ! Merci Druby et merci Robertogozzi.

    Cependant je n’arrive pas à comprendre pourquoi mon code ne donne rien … Avez-vous une idée ?

    #236725 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Ceci est votre code modifié. Maintenant ça marche.
    N contient le numéro de la bougie à partir de laquelle partir. Il peut aussi être 0, mais pas négatif.

    N      = 30
    Price1 = (high + low)/2
    for g = N to BarIndex
       if close[g] crosses over price1[g] then
          drawVLine(barindex[g]) style (dottedLine,3)
          break
       endIf
    next
    return
Viewing 7 posts - 1 through 7 (of 7 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

Recherche avec une boucle DOWNTO


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
Louloute @louloute Participant
Summary

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

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 08/24/2024
Status: Active
Attachments: 3 files
ProRealCode ProRealCode
Loading...