traduzione codice TW Aroon Oscillator [BigBeluga]

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #257322 quote
    Msport71
    Participant
    Junior

    buongiorno,


    chiedo cortese traduzione codice in oggetto che mi piacerebbe testare.


    Grazie per il consueto aiuto.


    https://www.tradingview.com/script/dI6UrTRB-Aroon-Oscillator-BigBeluga/


    // This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International  

    // https://creativecommons.org/licenses/by-nc-sa/4.0/ 

    // © BigBeluga 


    //@version=5 

    indicator(“Aroon Oscillator [BigBeluga]”, max_bars_back = 500, format = format.percent, max_labels_count = 500) 


    // INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ 

    int  length    = input.int(29, “Aroon Length”) 

    int  smooth    = input.int(25, “Smooth”) 

    int  sign_len   = input.int(10, “Signal Line”) 

    int  gain_limit  = 10 


    bool  m_rev_sig  = input.bool(true, “Plot Mean Reversion”, group = “Signals”) 

    bool  trend_sig  = input.bool(true, “Plot Trend Signals”, group = “Signals”) 


    color color_up   = input.color(color.lime, “Up”, inline = “Col”, group = “Color”) 

    color color_dn   = input.color(color.blue, “Down”, inline = “Col”, group = “Color”) 

    // } 



    // CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ 

    // Zero Lag Function John Ehlers 

    zero_lag(src, length, gain_limit) => 

      // Initialize variables 

      float alpha    = 2 / (length + 1) 

      float ema     = na 

      float ec      = na 

      float least_error = 1000000 

      float best_gain  = 0 


      // Initialize EMA 

      ema := na(ema[1]) ? src : alpha * src + (1 – alpha) * nz(ema[1]) 


      // Loop to find the best gain 

      for int value = -gain_limit to gain_limit 

        // Calculate gain and EC 

        float gain = value / 10 

        ec := na(ec[1]) ? src : alpha * (ema + gain * (src – nz(ec[1]))) + (1 – alpha) * nz(ec[1]) 


        // Calculate error 

        float error = src – ec 


        // Check if this gain results in a smaller error 

        if math.abs(error) < least_error 

          least_error := math.abs(error) 

          best_gain  := gain 


      // Recalculate EC using the best gain 

      ec := na(ec[1]) ? src : alpha * (ema + best_gain * (src – nz(ec[1]))) + (1 – alpha) * nz(ec[1]) 

      ec 


    aroon(simple int len, smooth) => 

      float aroonDown  = 100 * (ta.lowestbars(low, len) + len) / len 

      float aroonUp   = 100 * (ta.highestbars(high, len) + len) / len 

      float src     = aroonUp – aroonDown 

      zero_lag(src, smooth, gain_limit) 


    float aroon_osc  = aroon(length, smooth) 

    float sig_line  = ta.sma(aroon_osc, sign_len) 


    color color_sig  = color.new(chart.fg_color, 85) 

    // } 



    // PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{ 

    p1  = plot(aroon_osc, “Aroon Oscillator”, color = color.from_gradient(aroon_osc, -80, 80, color_dn, color_up)) 

    p0  = plot(0, “Zero Line”, color = color.new(chart.fg_color, 50)) 


    plot(sig_line, “Signal Line”, color = bar_index % 2 == 0 ? color.new(chart.fg_color, 50) : na) 


    fill(p1, p0, 0, -100, na, color_dn) 

    fill(p1, p0, 100, 0, color_up, na) 


    bgcolor(ta.crossover(aroon_osc, 0) ? color.new(color_up, 85) : na) 

    bgcolor(ta.crossover(aroon_osc, 0) and trend_sig ? color.new(color_up, 85) : na, force_overlay = true) 


    bgcolor(ta.crossunder(aroon_osc, 0) ? color.new(color_dn, 85) : na) 

    bgcolor(ta.crossunder(aroon_osc, 0) and trend_sig ? color.new(color_dn, 85) : na, force_overlay = true) 


    // Align plotchar and label declarations with types and columns 

    plotchar(ta.crossover(aroon_osc, 0) and trend_sig, “Long (Chart)”, “🢁”,  

         location = location.bottom,  

         color  = color_up,  

         size   = size.tiny,  

         force_overlay = true,  

         text   = “Long”,  

         textcolor = chart.fg_color) 


    plotchar(ta.crossunder(aroon_osc, 0) and trend_sig, “Short (Chart)”, “🢃”,  

         location = location.top,  

         color  = color_dn,  

         size   = size.tiny,  

         force_overlay = true,  

         text   = “Short”,  

         textcolor = chart.fg_color) 


    if barstate.islast 

      label.delete( 

         label.new(bar_index, aroon_osc, str.tostring(math.round(aroon_osc), format.percent), 

             color   = color(na),  

             textcolor = aroon_osc > 0 ? color_up : color_dn,  

             style   = label.style_label_left)[1] 

             ) 


    if m_rev_sig 

      if ta.crossover(aroon_osc, sig_line) 

        label.new(bar_index, low, “●nreversionnup”,  

             color     = color(na),  

             textcolor   = color.new(color_up, 50),  

             style     = label.style_label_up,  

             force_overlay = true) 


      if ta.crossunder(aroon_osc, sig_line)  

        label.new(bar_index, high, “reversionndownn●”,  

             color     = color(na),  

             textcolor   = color_dn,  

             style     = label.style_label_down,  

             force_overlay = true) 


    plotchar(ta.crossover(aroon_osc, sig_line) ? aroon_osc[1] : na, “Mean reversion Up”, “●”,  

         location = location.absolute,  

         color  = color_up, 

         size   = size.tiny,  

         offset  = -1) 


    plotchar(ta.crossunder(aroon_osc, sig_line) ? aroon_osc[1] : na, “Mean reversion Down”, “●”,  

         location = location.absolute,  

         color  = color_dn,  

         size   = size.tiny,  

         offset  = -1) 


    plotchar(ta.crossover(aroon_osc, 0) ? 0 : na, “Long”, “▲”, location = location.absolute, color = color_up, size = size.tiny) 

    plotchar(ta.crossunder(aroon_osc, 0) ? 0 : na, “Short”, “▼”, location = location.absolute, color = color_dn, size = size.tiny) 


    bgcolor(aroon_osc > 0 ? color.new(color_up, 95) : color.new(color_dn, 95)) 

    // } 


    #257334 quote
    Iván González
    Moderator
    Master

    Ecco qui:

    // -------------------------------------------------
    //PRC_Aroon Oscillator [BigBeluga]
    //version = 0
    //02.02.2026
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // -------------------------------------------------
    // --- PARAMETROS ---
    // -------------------------------------------------
    aroonLen = 29       // Aroon Length
    smoothLen = 25      // Zero Lag Smooth period
    signalLen = 10      // Signal Line (SMA)
    gainLimit = 10      // Gain Limit para Zero Lag Ehlers
    plotMRev = 1        // 1 = Mostrar Mean Reversion signals, 0 = No
    plotTrend = 1       // 1 = Mostrar Trend signals, 0 = No
    // -------------------------------------------------
    // --- AROON UP / DOWN ---
    // -------------------------------------------------
    aroonSrc = AroonUp[aroonLen]-aroondown[aroonLen]//myaroonUp - myaroonDn
    // -------------------------------------------------
    // --- ZERO LAG FILTER (John Ehlers) ---
    // -------------------------------------------------
    myAlpha = 2.0 / (smoothLen + 1)
    
    IF barindex <= aroonLen THEN
       myEma = aroonSrc
       ec = aroonSrc
    ELSE
       // EMA estandar
       myEma = myAlpha * aroonSrc + (1 - myAlpha) * myEma[1]
       
       // Buscar mejor ganancia (-1.0 a +1.0, paso 0.1)
       leastError = 1000000
       bestGain = 0
       
       FOR testVal = 0 TO 2 * gainLimit DO
          // testVal 0..20 -> testGain -1.0..+1.0
          testGain = (testVal - gainLimit) / 10.0
          testEc = myAlpha * (myEma + testGain * (aroonSrc - ec[1])) + (1 - myAlpha) * ec[1]
          testError = ABS(aroonSrc - testEc)
          IF testError < leastError THEN
             leastError = testError
             bestGain = testGain
          ENDIF
       NEXT
       
       // EC final con la ganancia optima
       ec = myAlpha * (myEma + bestGain * (aroonSrc - ec[1])) + (1 - myAlpha) * ec[1]
    ENDIF
    
    aroonOsc = ec
    // -------------------------------------------------
    // --- SIGNAL LINE (SMA) ---
    // -------------------------------------------------
    sigLine = average[signalLen](aroonOsc)
    // -------------------------------------------------
    // --- DETECCION DE CRUCES ---
    // -------------------------------------------------
    longSig = (aroonOsc crosses over 0)
    shortSig = (aroonOsc crosses under 0)
    revUpSig = (aroonOsc crosses over sigLine)
    revDnSig = (aroonOsc crosses under sigLine)
    // -------------------------------------------------
    // --- COLOR OSCILADOR ---
    // -------------------------------------------------
    IF aroonOsc > 60 THEN
       r1 = 0
       g1 = 255
       b1 = 0
    ELSIF aroonOsc > 20 THEN
       r1 = 50
       g1 = 200
       b1 = 0
    ELSIF aroonOsc > -20 THEN
       r1 = 25
       g1 = 128
       b1 = 128
    ELSIF aroonOsc > -60 THEN
       r1 = 0
       g1 = 50
       b1 = 200
    ELSE
       r1 = 0
       g1 = 0
       b1 = 255
    ENDIF
    // -------------------------------------------------
    // --- COLOR FILL (zona entre oscilador y cero) ---
    // -------------------------------------------------
    IF aroonOsc >= 0 THEN
       rFill = 0
       gFill = 255
       bFill = 0
    ELSE
       rFill = 0
       gFill = 0
       bFill = 255
    ENDIF
    COLORBETWEEN(aroonOsc, 0, rFill, gFill, bFill, 40)
    // -------------------------------------------------
    // --- BACKGROUND en cruces con cero ---
    // -------------------------------------------------
    IF longSig AND plotTrend THEN
       BACKGROUNDCOLOR(0, 255, 0, 30)
    ENDIF
    IF shortSig AND plotTrend THEN
       BACKGROUNDCOLOR(0, 0, 255, 30)
    ENDIF
    // -------------------------------------------------
    // --- SENALES VISUALES EN PANEL DEL OSCILADOR ---
    // -------------------------------------------------
    // Trend signals: punto en linea cero
    IF longSig AND plotTrend THEN
       drawtext("▲",barindex,0)coloured(0, 255, 0)
    ENDIF
    IF shortSig AND plotTrend THEN
       drawtext("▼",barindex,0)coloured(0, 0, 255)
    ENDIF
    
    // Mean Reversion: punto en el oscilador
    IF revUpSig AND plotMRev THEN
       DRAWPOINT(barindex, aroonOsc, 3) coloured(0, 200, 0)
    ENDIF
    IF revDnSig AND plotMRev THEN
       DRAWPOINT(barindex, aroonOsc, 3) coloured(0, 0, 200)
    ENDIF
    
    // -------------------------------------------------
    RETURN aroonOsc coloured(r1, g1, b1) AS "Aroon Osc", sigLine coloured(120, 120, 120) style(dottedline2) AS "Signal", 0 coloured(150, 150, 150) AS "Zero"
    


    Msport71 thanked this post
    #257339 quote
    Nicolas
    Keymaster
    Master

    Un’altra versione dell’oscillatore aroon qui:

    Aroon Oscillator

    Msport71 and robertogozzi thanked this post
    #257347 quote
    Msport71
    Participant
    Junior

    Grazie e mille!

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

traduzione codice TW Aroon Oscillator [BigBeluga]


Supporto Piattaforma: Grafici, Dati e Broker

New Reply
Author
author-avatar
Msport71 @carlo-pasca Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Msport71
23 hours, 17 minutes ago.

Topic Details
Forum: Supporto Piattaforma: Grafici, Dati e Broker
Language: Italian
Started: 02/02/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...