Welcome to the BEST forum for traders

Did you know we're sharing tons of exclusive content here?
Our community is growing quickly. Take a look around and say "Hello".

Utiliser une boucle dans un codage

Apr 1, 2022 - 8:00 AM

Viewed 610 times

https://best-trading-indicator.com/community/bti/forums/4180/topics/56217 COPY
  • Débutant en codage Pinescript j'ai un indicateur de projection de la Tenkan dans ICHIMOKU qui fonctionne bien mais j'aimerai simplifier le code en utilisant une boucle permettant de gagner des lignes de codes. J'ai cherché mais je ne trouve pas la solution.
    Mon code
    //@version=5
    indicator(title=Passive lines, overlay=true)
    tk = input.int(9, minval=1, title=Tenkan length)

    tk8=math.avg(ta.lowest(8), ta.highest(8))
    tk7=math.avg(ta.lowest(7), ta.highest(7))
    tk6=math.avg(ta.lowest(6), ta.highest(6))
    tk5=math.avg(ta.lowest(5), ta.highest(5))
    tk4=math.avg(ta.lowest(4), ta.highest(4))
    tk3=math.avg(ta.lowest(3), ta.highest(3))
    tk2=math.avg(ta.lowest(2), ta.highest(2))

    plot(tk8, color= #00bcd4, offset=1, show_last=1,title=Tenkan)
    plot(tk7, color= #00bcd4, offset=2, show_last=1,title=Tenkan)
    plot(tk6, color= #00bcd4, offset=3, show_last=1,title=Tenkan)
    plot(tk5, color= #00bcd4, offset=4, show_last=1,title=Tenkan)
    plot(tk4, color= #00bcd4, offset=5, show_last=1,title=Tenkan)
    plot(tk3, color= #00bcd4, offset=6, show_last=1,title=Tenkan)
    plot(tk2, color= #00bcd4, offset=7, show_last=1,title=Tenkan)

    0
  • Bonjour

    Je pense que le for sera utile: https://www.tradingview.com/pine-script-reference/v5/#op_for

    Je mettrais les math.avg dans un tableau

    var a = array.new_float(7, 0.)
    
    for i = 0 to 6
       array.set(a, i, math.avg(ta.lowest(i+2), ta.highest(i+2))
    
    

    En revanche, les plots ne pourront pas être dans la boucle for, ça ne marchera pas

    0
  • Is it possible to make a second loop to take the values ​​of a and pass them in a plot at each iteration?
    Thank You

    0
  • not possible to use the plot function in a loop
    Pinescript doesn't allow it

    0
CONTENTS