Traduzione codice “Indicatore di tendenza”

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #246802 quote
    Ciccarelli Franco
    Participant
    Junior

    Ivan, gentilmente puoi tradurre il codice allegato? Mi sembra interessante.

     

    // @version= 5
    indicator ( “Segnali di tendenza a ritardo zero (MTF) + Filtro laterale” , overlay = true ) 

    // === INPUT ===
    // Input di tendenza a ritardo zero
    lunghezza = input.int ( 70 , “Lunghezza” , gruppo = “Calcoli principali” )       
    mult = input.float ( 1.2 , “Moltiplicatore di banda” , gruppo = “Calcoli principali” )       
    t1 = input.timeframe ( “5” , “Intervallo di tempo 1” , gruppo = “Intervalli di tempo aggiuntivi” )       
    t2 = input.timeframe ( “15” , “Intervallo di tempo 2” , gruppo = “Intervalli di tempo aggiuntivi” )       
    t3 = input.timeframe ( “60” , “Intervallo di tempo 3” , gruppo = “Intervalli di tempo aggiuntivi” )       
    t4 = input.timeframe ( “240” , “Intervallo di tempo 4” , gruppo = “Intervalli di tempo aggiuntivi” )       
    t5 = input.timeframe ( “1D” , “Intervallo di tempo 5” , gruppo = “Intervalli di tempo aggiuntivi” )       
    verde = input.color ( #00ffbb , “Colore rialzista” , gruppo = “Aspetto” )       
    rosso = input.color ( #ff1100 , “Colore ribassista” , gruppo = “Aspetto” )       
    fillBullColor1Input = input.color ( #00ffbb , “Riempimento esterno rialzista” , gruppo = “Aspetto” )       
    fillBullColor2Input = input.color ( #00ffbb , “Riempimento interno rialzista” , gruppo = “Aspetto” )       
    fillBearColor1Input = input.color ( #ff1100 , “Riempimento esterno ribassista” , gruppo = “Aspetto” )       
    fillBearColor2Input = input.colore ( #ff1100 , “Riempimento interno ribassista” , gruppo = “Aspetto” )      

    // Input di mercato laterale
    rsiLength = input ( 14 , title = “Lunghezza RSI” , group = “Filtro mercato laterale” )     
    adxLength = input ( 14 , title = “Lunghezza ADX” , group = “Filtro mercato laterale” )     
    showSidewaysCircles = input.bool ( true , “Mostra cerchi laterali” , group = “Filtro mercato laterale” )     
    circleColor = input.color ( color.gray , “Colore cerchio laterale” , group = “Filtro mercato laterale” )    

    // === CALCOLO DEL MERCATO LATERALE ===
    rsiValue = ta.rsi ( close , rsiLength )    
    tr = ta.tr ( true )   
    upMove = high ta.highest ( high [ 1 ] , 1 )      
    downMove = ta.lowest ( low [ 1 ] , 1 ) low      
    diPlus = ta.rma ( upMove > downMove e upMove > 0 ? upMove : 0 , adxLength ) / ta.rma ( tr , adxLength ) * 100                   
    diMinus = ta.rma ( downMove > upMove e downMove > 0 ? downMove : 0 , adxLength ) / ta.rma ( tr , adxLength ) * 100                   
    dx = math.abs ( diPlus diMinus ) / ( diPlus + diMinus ) * 100           
    adx = ta.rma ( dx , adxLength )    
    rsiCondition = rsiValue > 40 e rsiValue < 60         
    adxCondition = adx <= 25 e adx < diPlus e adx < diMinus             
    lateralmente = rsiCondition e adxCondition    

    // Traccia il mercato lateralmente come una
    forma circolare ( showSidewaysCircles e lateralmente ? chiudi : in , titolo = “Mercato Sideways” , style = shape.labelup , location = location.belowbar , color = circleColor );          

    // === CALCOLO DEL TREND A RITARDO ZERO ===
    src = close   
    lag = math.floor (( length 1 ) / 2 )       
    zlema = ta.ema ( src + ( src src [ lag ]) , length )        
    volatility = ta.highest ( ta.atr ( length ) , length * 3 ) * mult        
    var trend = 0   

    se non lateralmente   se ta.crossover ( chiusura , zlema + volatilità ) tendenza : = 1 altrimenti se ta.crossunder ( chiusura , zlema volatilità ) tendenza : = -1
            
              
             
              

    zlemaColor = trend == 1 ? color.new ( verde , 70 ) : trend == -1 ? color.new ( rosso , 70 ) : na                 
    m = plot ( zlema , titolo = “Base a ritardo zero” , larghezza riga = 2 , colore = zlemaColor )      
    superiore = plot ( trend == -1 ? zlema + volatilità : na , stile = plot.style_linebr , colore = color.new ( rosso , 90 ) , titolo = “Banda di deviazione superiore” )               
    ​​inferiore = plot ( trend == 1 ? zlema volatilità : na , stile = plot.style_linebr , colore = color.new ( verde , 90 ) , titolo = “Banda di deviazione inferiore” )              

    riempimento ( m , superiore , ( apri + chiudi ) / 2 , zlema + volatilità , colore.nuovo ( fillBearColor1Input , 90 ) , colore.nuovo ( fillBearColor2Input , 70 ))              
    riempimento ( m , inferiore , ( apri + chiudi ) / 2 , zlema volatilità , colore.nuovo ( fillBullColor1Input , 90 ) , colore.nuovo ( fillBullColor2Input , 70 ))             

    plotshape ( non lateralmente e ta.crossover ( trend , 0 ) ? zlema + volatilità : na , “Trend ribassista” , shape.labeldown , location.absolute , rosso , testo = “▼” , colore del testo = chart.fg_color , dimensione = size.small )                  
    plotshape ( non lateralmente e ta.crossover ( trend , 0 ) ? zlema volatilità : na , “Trend rialzista” , shape.labelup , location.absolute , verde , testo = “▲” , colore del testo = chart.fg_color , dimensione = size.small )                 

    plotchar ( non lateralmente e ta.crossover ( chiudi , zlema ) e trend == 1 e trend [ 1 ] == 1 ? zlema volatilità * 1,5 : na , “Entrata rialzista” , “▲” , posizione.assoluta , verde , dimensione = dimensione.piccola )                          
    plotchar ( non lateralmente e ta.crossunder ( chiudi , zlema ) e trend == -1 e trend [ 1 ] == -1 ? zlema + volatilità * 1,5 : na , “Entrata ribassista” , “▼” , posizione.assoluta , rosso , dimensione = dimensione.piccola )                         

    s1 = richiesta.sicurezza ( syminfo.tickerid , t1 , tendenza )     
    s2 = richiesta.sicurezza ( syminfo.tickerid , t2 , tendenza )     
    s3 = richiesta.sicurezza ( syminfo.tickerid , t3 , tendenza )     
    s4 = richiesta.sicurezza ( syminfo.tickerid , t4 , tendenza )     
    s5 = richiesta.sicurezza ( syminfo.tickerid , t5 , tendenza )    

    s1a = s1 == 1 ? “Rialzista” : “Ribassista”         
    s2a = s2 == 1 ? “Rialzista” : “Ribassista”         
    s3a = s3 == 1 ? “Rialzista” : “Ribassista”         
    s4a = s4 == 1 ? “Rialzista” : “Ribassista”         
    s5a = s5 == 1 ? “Rialzista” : “Ribassista”        

    se barstate.islast  var data_table = table.new ( posizione = position.top_right , colonne = 2 , righe = 6 , colore sfondo = chart.bg_color , larghezza bordo = 1 , colore bordo = chart.fg_color , colore cornice = chart.fg_color , larghezza cornice = 1 ) table.cell ( data_table , text_halign = text.align_center , colonna = 0 , riga = 0 , testo = “Intervallo di tempo” , colore testo = chart.fg_color ) table.cell ( data_table , text_halign = text.align_center , colonna = 1 , riga = 0 , testo = “Segnale” , colore testo = chart.fg_color )
                  
             
             

        table.cell ( data_table , text_halign = text.align_center , column = 0 , row = 1 , text = t1 , text_color = chart.fg_color )      table.cell ( data_table , text_halign = text.align_center , column = 1 , row = 1 , text = s1a , text_color = chart.fg_color , bgcolor = s1a == “Ottimista” ? color.new ( green , 70 ) : color.new ( red , 70 ))
                      

        table.cell ( data_table , text_halign = text.align_center , column = 0 , row = 2 , text = t2 , text_color = chart.fg_color )      table.cell ( data_table , text_halign = text.align_center , column = 1 , row = 2 , text = s2a , text_color = chart.fg_color , bgcolor = s2a == “Ottimista” ? color.new ( green , 70 ) : color.new ( red , 70 ))
                      

        table.cell ( data_table , text_halign = text.align_center , column = 0 , row = 3 , text = t3 , text_color = chart.fg_color )      table.cell ( data_table , text_halign = text.align_center , column = 1 , row = 3 , text = s3a , text_color = chart.fg_color , bgcolor = s3a == “Ottimista” ? color.new ( green , 70 ) : color.new ( red , 70 ))
                      

        table.cell ( data_table , text_halign = text.align_center , column = 0 , row = 4 , text = t4 , text_color = chart.fg_color )      table.cell ( data_table , text_halign = text.align_center , column = 1 , row = 4 , text = s4a , text_color = chart.fg_color , bgcolor = s4a == “Ottimista” ? color.new ( green , 70 ) : color.new ( red , 70 ))
                      

        table.cell ( data_table , text_halign = text.align_center , column = 0 , row = 5 , text = t5 , text_color = chart.fg_color )      table.cell ( data_table , text_halign = text.align_center , column = 1 , row = 5 , text = s5a , text_color = chart.fg_color , bgcolor = s5a == “Ottimista” ? color.new ( green , 70 ) : color.new ( red , 70 ))
                      

    // === AVVISI ===
    alertcondition ( non laterale e ta.crossover ( close , zlema ) e trend == 1 e trend [ 1 ] == 1 , “Segnale di ingresso rialzista” , message = “Segnale di ingresso rialzista rilevato. Si consideri l’inserimento di  una posizione lunga.” )               
    alertcondition ( non laterale e ta.crossunder ( close , zlema ) e trend == -1 e trend [ 1 ] == -1 , “Segnale di ingresso ribassista” , message = “Segnale di ingresso ribassista rilevato. Si consideri l’inserimento di  una posizione corta.” )               
    alertcondition ( non laterale e ta.crossover ( trend , 0 ) , “Tendenza rialzista” )      
    alertcondition ( non laterale e ta.crossunder ( trend , 0 ) , “Tendenza ribassista” )      
    alertcondition ( non laterale e ta.cross ( trend , 0 ) , “Tendenza (rialzista o ribassista)” )    

    Grazie

    #246811 quote
    Iván González
    Moderator
    Master

    Ciao. Posso tradurlo, ma ho bisogno di un codice funzionante. Quello che hai fornito sembra una traduzione dall’inglese all’italiano e contiene diversi errori.
    Se mi fornisci il codice funzionante e, soprattutto, lo aggiungi con il pulsante “Add PRT code”, posso farlo.

    #246819 quote
    Msport71
    Participant
    Junior

    Salvo errori, c’è già questa versione senza tabella timeframes:

    Zero Lag Trend Signals Indicator by AlgoAlpha

    #246820 quote
    Ciccarelli Franco
    Participant
    Junior
    //@version=5
    indicator(""Zero Lag Trend Signals (MTF) + Sideways Filter"", overlay=true)
    
    // === INPUTS ===
    // Zero Lag Trend Inputs
    length = input.int(70, ""Length"", group = ""Main Calculations"")
    mult = input.float(1.2, ""Band Multiplier"", group = ""Main Calculations"")
    t1 = input.timeframe(""5"", ""Time frame 1"", group = ""Extra Timeframes"")
    t2 = input.timeframe(""15"", ""Time frame 2"", group = ""Extra Timeframes"")
    t3 = input.timeframe(""60"", ""Time frame 3"", group = ""Extra Timeframes"")
    t4 = input.timeframe(""240"", ""Time frame 4"", group = ""Extra Timeframes"")
    t5 = input.timeframe(""1D"", ""Time frame 5"", group = ""Extra Timeframes"")
    green = input.color(#00ffbb, ""Bullish Color"", group = ""Appearance"")
    red = input.color(#ff1100, ""Bearish Color"", group = ""Appearance"")
    fillBullColor1Input = input.color(#00ffbb, ""Bullish Fill Outer"", group = ""Appearance"")
    fillBullColor2Input = input.color(#00ffbb, ""Bullish Fill Inner"", group = ""Appearance"")
    fillBearColor1Input = input.color(#ff1100, ""Bearish Fill Outer"", group = ""Appearance"")
    fillBearColor2Input = input.color(#ff1100, ""Bearish Fill Inner"", group = ""Appearance"")
    
    // Sideways Market Inputs
    rsiLength = input(14, title=""RSI Length"", group=""Sideways Market Filter"")
    adxLength = input(14, title=""ADX Length"", group=""Sideways Market Filter"")
    showSidewaysCircles = input.bool(true, ""Show Sideways Circles"", group=""Sideways Market Filter"")
    circleColor = input.color(color.gray, ""Sideways Circle Color"", group=""Sideways Market Filter"")
    
    // === SIDEWAYS MARKET CALCULATION ===
    rsiValue = ta.rsi(close, rsiLength)
    tr = ta.tr(true)
    upMove = high - ta.highest(high[1], 1)
    downMove = ta.lowest(low[1], 1) - low
    diPlus = ta.rma(upMove > downMove and upMove > 0 ? upMove : 0, adxLength) / ta.rma(tr, adxLength) * 100
    diMinus = ta.rma(downMove > upMove and downMove > 0 ? downMove : 0, adxLength) / ta.rma(tr, adxLength) * 100
    dx = math.abs(diPlus - diMinus) / (diPlus + diMinus) * 100
    adx = ta.rma(dx, adxLength)
    rsiCondition = rsiValue > 40 and rsiValue < 60
    adxCondition = adx <= 25 and adx < diPlus and adx < diMinus
    sideways = rsiCondition and adxCondition
    
    // Plot sideways market as a circle
    plotshape(showSidewaysCircles and sideways ? close : na, title=""Sideways Market"", style=shape.labelup, location=location.belowbar, color=circleColor)
    
    // === ZERO LAG TREND CALCULATION ===
    src = close
    lag = math.floor((length - 1) / 2)
    zlema = ta.ema(src + (src - src[lag]), length)
    volatility = ta.highest(ta.atr(length), length * 3) * mult
    var trend = 0
    
    if not sideways
        if ta.crossover(close, zlema + volatility)
            trend := 1
        else if ta.crossunder(close, zlema - volatility)
            trend := -1
    
    zlemaColor = trend == 1 ? color.new(green, 70) : trend == -1 ? color.new(red, 70) : na
    m = plot(zlema, title=""Zero Lag Basis"", linewidth=2, color=zlemaColor)
    upper = plot(trend == -1 ? zlema + volatility : na, style=plot.style_linebr, color=color.new(red, 90), title=""Upper Deviation Band"")
    lower = plot(trend == 1 ? zlema - volatility : na, style=plot.style_linebr, color=color.new(green, 90), title=""Lower Deviation Band"")
    
    fill(m, upper, (open + close) / 2, zlema + volatility, color.new(fillBearColor1Input, 90), color.new(fillBearColor2Input, 70))
    fill(m, lower, (open + close) / 2, zlema - volatility, color.new(fillBullColor1Input, 90), color.new(fillBullColor2Input, 70))
    
    plotshape(not sideways and ta.crossunder(trend, 0) ? zlema + volatility : na, ""Bearish Trend"", shape.labeldown, location.absolute, red, text=""▼"", textcolor=chart.fg_color, size=size.small)
    plotshape(not sideways and ta.crossover(trend, 0) ? zlema - volatility : na, ""Bullish Trend"", shape.labelup, location.absolute, green, text=""▲"", textcolor=chart.fg_color, size=size.small)
    
    plotchar(not sideways and ta.crossover(close, zlema) and trend == 1 and trend[1] == 1 ? zlema - volatility * 1.5 : na, ""Bullish Entry"", ""▲"", location.absolute, green, size=size.tiny)
    plotchar(not sideways and ta.crossunder(close, zlema) and trend == -1 and trend[1] == -1 ? zlema + volatility * 1.5 : na, ""Bearish Entry"", ""▼"", location.absolute, red, size=size.tiny)
    
    s1 = request.security(syminfo.tickerid, t1, trend)
    s2 = request.security(syminfo.tickerid, t2, trend)
    s3 = request.security(syminfo.tickerid, t3, trend)
    s4 = request.security(syminfo.tickerid, t4, trend)
    s5 = request.security(syminfo.tickerid, t5, trend)
    
    s1a = s1 == 1 ? ""Bullish"" : ""Bearish""
    s2a = s2 == 1 ? ""Bullish"" : ""Bearish""
    s3a = s3 == 1 ? ""Bullish"" : ""Bearish""
    s4a = s4 == 1 ? ""Bullish"" : ""Bearish""
    s5a = s5 == 1 ? ""Bullish"" : ""Bearish""
    
    if barstate.islast
        var data_table = table.new(position=position.top_right, columns=2, rows=6, bgcolor=chart.bg_color, border_width=1, border_color=chart.fg_color, frame_color=chart.fg_color, frame_width=1)
        table.cell(data_table, text_halign=text.align_center, column=0, row=0, text=""Time Frame"", text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=0, text=""Signal"", text_color=chart.fg_color)
    
        table.cell(data_table, text_halign=text.align_center, column=0, row=1, text=t1, text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=1, text=s1a, text_color=chart.fg_color, bgcolor=s1a == ""Bullish"" ? color.new(green, 70) : color.new(red, 70))
    
        table.cell(data_table, text_halign=text.align_center, column=0, row=2, text=t2, text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=2, text=s2a, text_color=chart.fg_color, bgcolor=s2a == ""Bullish"" ? color.new(green, 70) : color.new(red, 70))
    
        table.cell(data_table, text_halign=text.align_center, column=0, row=3, text=t3, text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=3, text=s3a, text_color=chart.fg_color, bgcolor=s3a == ""Bullish"" ? color.new(green, 70) : color.new(red, 70))
    
        table.cell(data_table, text_halign=text.align_center, column=0, row=4, text=t4, text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=4, text=s4a, text_color=chart.fg_color, bgcolor=s4a == ""Bullish"" ? color.new(green, 70) : color.new(red, 70))
    
        table.cell(data_table, text_halign=text.align_center, column=0, row=5, text=t5, text_color=chart.fg_color)
        table.cell(data_table, text_halign=text.align_center, column=1, row=5, text=s5a, text_color=chart.fg_color, bgcolor=s5a == ""Bullish"" ? color.new(green, 70) : color.new(red, 70))
    
    // === ALERTS ===
    alertcondition(not sideways and ta.crossover(close, zlema) and trend == 1 and trend[1] == 1, ""Bullish Entry Signal"", message=""Bullish Entry Signal detected. Consider entering a long position."")
    alertcondition(not sideways and ta.crossunder(close, zlema) and trend == -1 and trend[1] == -1, ""Bearish Entry Signal"", message=""Bearish Entry Signal detected. Consider entering a short position."")
    alertcondition(not sideways and ta.crossover(trend, 0), ""Bullish Trend"")
    alertcondition(not sideways and ta.crossunder(trend, 0), ""Bearish Trend"")
    alertcondition(not sideways and ta.cross(trend, 0), ""(Bullish or Bearish) Trend"")
    
    #246830 quote
    Iván González
    Moderator
    Master

    Adesso sì!

    //-------------------------------------//
    //PRC_Zero Lag Trend Signals + Sideways filter
    //version = 0
    //06.05.25
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //-------------------------------------//
    //---Inputs
    //-------------------------------------//
    length=70
    mult=1.2
    src=close
    rsilength=14
    adxlength=14
    showSideways=1
    //-------------------------------------//
    // Sideways market calculation
    //-------------------------------------//
    //---RSI
    rsivalue=rsi[rsilength](close)
    rsiCondition=rsiValue>40 and rsiValue<60
    //---ADX
    pdi=DIplus[adxlength](close)
    mdi=DIminus[adxlength](close)
    iadx=ADX[adxlength]
    adxCondition=iadx<=25 and iadx<pdi and iadx<mdi
    //---Sideways
    sideways=rsiCondition and adxCondition
    if showSideways and sideways then
    drawpoint(barindex,low-tr,2)coloured("grey")
    endif
    //-------------------------------------//
    // Zlema calculation
    //-------------------------------------//
    lag=floor((length-1)/2)
    
    myzlema=average[length,1](src+(src-src[lag]))
    //-------------------------------------//
    // Volatility calculation
    //-------------------------------------//
    atr=averagetruerange[length](close)
    volatil=highest[length*3](atr)*mult
    //-------------------------------------//
    // Trend condition
    //-------------------------------------//
    once trend=0
    if sideways=0 then
    if close crosses over myzlema+volatil then
    trend=1
    r=0
    g=255
    elsif close crosses under myzlema-volatil then
    trend=-1
    r=255
    g=0
    endif
    endif
    //-------------------------------------//
    // Signals and colors
    //-------------------------------------//
    if trend=-1 then
    upper=myzlema+volatil
    alpha1=90
    lower=myzlema
    alpha2=0
    if trend<>trend[1] and sideways=0 then
    drawarrowdown(barindex,upper+0.25*atr)coloured(r,g,0,175)
    endif
    else
    upper=myzlema
    alpha1=0
    lower=myzlema-volatil
    alpha2=90
    if trend<>trend[1] and sideways=0 then
    drawarrowup(barindex,lower-0.25*atr)coloured(r,g,0,175)
    endif
    endif
    
    if close crosses over myzlema and trend=1 and trend[1]=1 and sideways=0 then
    drawtext("▲",barindex,myzlema-volatil*1.5)coloured("green")
    elsif close crosses under myzlema and trend=-1 and trend[1]=-1 and sideways=0 then
    drawtext("▼",barindex,myzlema+volatil*1.5)coloured("red")
    endif
    if barindex > 4*length then
    colorbetween(myzlema,upper,r,g,0,alpha1)
    colorbetween(myzlema,lower,r,g,0,alpha2)
    endif
    //-------------------------------------//
    return myzlema as "Zero Lag Basis"style(line,2)coloured(r,g,0)
    #246832 quote
    Ciccarelli Franco
    Participant
    Junior

    Grazie funziona bene, ma non ci sono etichette sui vari TF

    #246833 quote
    Iván González
    Moderator
    Master

    Quando avremo le funzioni nella v13, potrò farlo facilmente.
    Per ora si può fare solo copiando e incollando il codice più volte, tante quante sono le timeframe che vogliamo visualizzare.

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

Traduzione codice “Indicatore di tendenza”


ProBuilder: Indicatori & Strumenti Personalizzati

New Reply
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Iván González
9 months ago.

Topic Details
Forum: ProBuilder: Indicatori & Strumenti Personalizzati
Language: Italian
Started: 05/05/2025
Status: Active
Attachments: No files
Logo Logo
Loading...