Atr Fibonacci Trend Envelopes

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #261211 quote
    Stenozar
    Participant
    Master

    Buongiorno, è possibile tradurre questo indicatore che mi pare interessante?

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

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

    // © BigBeluga


    //@version=6

    indicator(‘ATR Fibonacci Trend Envelopes [BigBeluga]’, overlay = true, max_labels_count = 500, max_lines_count = 500)


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


    grp_calc = “Calculation Settings”

    maType  = input.string(“RMA”, “MA Type”, options=[“SMA”, “EMA”, “WMA”, “HMA”, “RMA”], group=grp_calc, tooltip=”Select the Moving Average type used to calculate the baseline (Basis).”)

    maLength = input.int(100, ‘MA Length’, group=grp_calc, tooltip=”The number of bars used to calculate the trend baseline.”)

    atrLength = input.int(100, ‘ATR Length’, group=grp_calc, tooltip=”The lookback period for Average True Range, used to determine envelope width.”)

    atrMult  = input.float(3.0, ‘ATR Multiplier’, group=grp_calc, tooltip=”Multiplies the ATR to expand or contract the Trend Envelopes.”)


    grp_proj = “Projection Settings”

    showProj = input.bool(true, “Show Projections”, group=grp_proj, tooltip=”Toggle the visibility of dotted line projections for the trend and Fibonacci levels.”)

    projLen  = input.int(50, “Projection Length (Bars)”, minval=1, group=grp_proj, tooltip=”Determines how many bars into the future the levels are projected.”)


    grp_color = “Color & Visual Settings”

    colorUp  = input.color(color.rgb(36, 192, 212), “Uptrend Color”, group=grp_color, tooltip=”Color used for the baseline and labels during a bullish trend.”)

    colorDown = input.color(color.rgb(235, 51, 51), “Downtrend Color”, group=grp_color, tooltip=”Color used for the baseline and labels during a bearish trend.”)

    colorMid = input.color(color.gray, “0.5 Fib Color”, group=grp_color, tooltip=”Color for the 50% Fibonacci retracement level.”)

    baseFill = input.color(color.rgb(255, 123, 0), “Pocket Base Color”, group=grp_color, tooltip=”Base color for the Dynamic Golden Pocket (0.618 – 0.786).”)

    sens   = 0.6 // Sensitivity for dynamic transparency


    grp_dash = “Dashboard Settings”

    showDash = input.bool(true, “Show MTF Dashboard”, group=grp_dash, tooltip=”Toggle the visibility of the Multi-Timeframe status table.”)

    dashLoc  = input.string(position.bottom_right, “Location”, options=[position.top_right, position.bottom_right, position.top_left, position.bottom_left, position.middle_right], group=grp_dash, tooltip=”The corner of the chart where the dashboard is displayed.”)

    dashSize = input.string(size.small, “Size”, options=[size.tiny, size.small, size.normal, size.large], group=grp_dash, tooltip=”The scaling size of the dashboard table and its text.”)

    tf1    = input.timeframe(“5”, “Timeframe 1″, group=grp_dash, tooltip=”The first timeframe to track in the dashboard.”)

    tf2    = input.timeframe(“15”, “Timeframe 2″, group=grp_dash, tooltip=”The second timeframe to track in the dashboard.”)

    tf3    = input.timeframe(“60”, “Timeframe 3″, group=grp_dash, tooltip=”The third timeframe to track in the dashboard.”)

    tf4    = input.timeframe(“240”, “Timeframe 4″, group=grp_dash, tooltip=”The fourth timeframe to track in the dashboard.”)

    // }



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


    // Fibonacci Multipliers

    fibMid  = 0.5

    fibGold1 = 0.618

    fibGold2 = 0.786


    get_ma(source, length, type) =>

      switch type

        “SMA” => ta.sma(source, length)

        “EMA” => ta.ema(source, length)

        “WMA” => ta.wma(source, length)

        “HMA” => ta.hma(source, length)

        “RMA” => ta.rma(source, length)

        => ta.sma(source, length)


    // MTF Function to get Trend and Pocket Status

    get_status(tf) =>

      request.security(syminfo.tickerid, tf, [close, high, low], lookahead=barmerge.lookahead_off)

       

    calc_trend_and_pocket() =>

      b = get_ma(close, maLength, maType)

      a = ta.atr(atrLength)

      u = b + a * atrMult

      l = b – a * atrMult

      var int t = 0

      if ta.crossover(close, u)

        t := 1

      else if ta.crossunder(close, l)

        t := -1

       

      f618 = t == 1 ? l + (u – l) * (1 – fibGold1) : u – (u – l) * (1 – fibGold1)

      f786 = t == 1 ? l + (u – l) * (1 – fibGold2) : u – (u – l) * (1 – fibGold2)

       

      inPocket = (close <= math.max(f618, f786) and close >= math.min(f618, f786))

      [t, inPocket]


    // Current TF Data

    [trend, inPocket] = calc_trend_and_pocket()


    basis   = get_ma(close, maLength, maType)

    atrValue = ta.atr(atrLength)

    upperBand = basis + atrValue * atrMult

    lowerBand = basis – atrValue * atrMult


    fib50 = trend == 1 ? lowerBand + (upperBand – lowerBand) * (1 – fibMid)  : upperBand – (upperBand – lowerBand) * (1 – fibMid)

    fib618 = trend == 1 ? lowerBand + (upperBand – lowerBand) * (1 – fibGold1) : upperBand – (upperBand – lowerBand) * (1 – fibGold1)

    fib786 = trend == 1 ? lowerBand + (upperBand – lowerBand) * (1 – fibGold2) : upperBand – (upperBand – lowerBand) * (1 – fibGold2)


    // Dynamic Color Logic

    pocketMid   = (fib618 + fib786) / 2

    dist     = math.abs(close – pocketMid)

    maxDist    = (upperBand – lowerBand) * 0.5 

    rawTransp   = 65 + (dist / maxDist * 30 * sens)

    dynamicTransp = math.max(0, math.min(90, rawTransp))

    dynamicColor = color.new(baseFill, dynamicTransp)


    // Projection Function

    create_proj(lvl, slope, col, txt, baseline = false) =>

      endVal = lvl + (slope * projLen)

      ln = line.new(bar_index, lvl, bar_index + projLen, endVal, xloc.bar_index, extend.none, col, baseline ? line.style_solid : line.style_dotted, baseline ? 3 : 1)

      lb = label.new(bar_index + projLen, endVal, txt, xloc.bar_index, style=label.style_label_left, color=color.new(color.black, 100), textcolor=col, size=dashSize)

      [ln, lb]

    // Timeframe Format Helper

    format_tf(tf) =>

      float m = str.tonumber(tf)

      if not na(m)

        m >= 1440 ? str.tostring(math.round(m / 1440)) + “D” : 

         m >= 60 ? str.tostring(math.round(m / 60)) + “H” : 

         tf + “m”

      else

        tf

    // }


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


    trendChange = trend != trend[1]

    float level100 = trend == 1 ? lowerBand : upperBand

    trendCol  = trend == 1 ? colorUp : colorDown


    plot(not trendChange ? level100 : na, ‘Trend MA’, color = trendCol, linewidth = 3, style = plot.style_linebr)

    p1 = plot(trend != 0 and not trendChange ? fib618 : na, ‘Fib 0.618’, color = dynamicColor, style = plot.style_linebr)

    p2 = plot(trend != 0 and not trendChange ? fib786 : na, ‘Fib 0.786’, color = dynamicColor, style = plot.style_linebr)

    plot(trend != 0 ? fib50 : na, ‘Fib 0.5’, color = colorMid, style = plot.style_linebr)

    fill(p1, p2, color = dynamicColor, title = ‘Dynamic Golden Pocket’)


    if trendChange

      level = trend == 1 ? lowerBand : upperBand

      style = trend == 1 ? label.style_label_up : label.style_label_down

      label.new(bar_index, level, text = ‘⦿’, color = color(na), textcolor = trend == 1 ? colorUp : colorDown, style = label.style_label_center, size = dashSize)

      label.new(bar_index, level, text = str.tostring(close, format.mintick), color = color(na), textcolor = trend == 1 ? colorUp : colorDown, style = style, size = dashSize)


    // Dashboard Logic

    if showDash and barstate.islast

      var table dash = table.new(dashLoc, 3, 5, bgcolor = color.new(color.black, 40), border_width = 1, border_color = color.new(color.gray, 70))   

      // Header

      table.cell(dash, 0, 0, “TF”, text_color = color.white, text_size = dashSize)

      table.cell(dash, 1, 0, “Trend”, text_color = color.white, text_size = dashSize)

      table.cell(dash, 2, 0, “Pocket”, text_color = color.white, text_size = dashSize)

       

      tfs = array.from(tf1, tf2, tf3, tf4)

      for i = 0 to 3

        curr_tf = array.get(tfs, i)

        [t, p] = request.security(syminfo.tickerid, curr_tf, [trend, inPocket])

         

        row = i + 1

        table.cell(dash, 0, row, format_tf(curr_tf), text_color = color.white, text_size = dashSize)

        table.cell(dash, 1, row, t == 1 ? “BULL” : “BEAR”, bgcolor = t == 1 ? color.new(colorUp, 30) : color.new(colorDown, 30), text_color = color.white, text_size = dashSize)

        table.cell(dash, 2, row, p ? “INSIDE” : “OUT”, bgcolor = p ? color.new(baseFill, 30) : color.new(color.gray, 80), text_color = color.white, text_size = dashSize)


    // Real-time labels & Projections (Original code)

    var line l100 = na, var line l50 = na, var line l618 = na, var line l786 = na

    var label lb100 = na, var label lb50 = na, var label lb618 = na, var label lb786 = na

    var linefill fGold = na


    if barstate.islast and trend != 0

      line.delete(l100), line.delete(l50), line.delete(l618), line.delete(l786)

      label.delete(lb100), label.delete(lb50), label.delete(lb618), label.delete(lb786)

      linefill.delete(fGold)


      s100 = (level100 – level100[4]) / 4

      s50 = (fib50 – fib50[4]) / 4

      s618 = (fib618 – fib618[4]) / 4

      s786 = (fib786 – fib786[4]) / 4


      if showProj

        [ln100, lab100] = create_proj(level100, s100, trendCol, “1.0”, true)

        [ln50, lab50]  = create_proj(fib50, s50, colorMid, “0.5”)

        [ln618, lab618] = create_proj(fib618, s618, baseFill, “0.618”)

        [ln786, lab786] = create_proj(fib786, s786, baseFill, “0.786”)

        fGold := linefill.new(ln618, ln786, dynamicColor)

        l100 := ln100, l50 := ln50, l618 := ln618, l786 := ln786

        lb100 := lab100, lb50 := lab50, lb618 := lab618, lb786 := lab786

    // }

    #261263 quote
    Iván González
    Moderator
    Legend

    Salve. Per future richieste, vi preghiamo di visitare il gruppo Tradingview all’indirizzo https://www.prorealcode.com/group/tradingview-to-prorealtime-translation-center/?tab=feed. Grazie.

    //--------------------------------------------------------//
    //PRC_ATR Fibonacci Trend Envelopes [BigBeluga]
    //version = 0
    //18.05.26
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------------------//
    //-----Inputs---------------------------------------------//
    maType = 3
    maLength = 100
    atrLength = 100
    atrMult = 3.0
    //--------------------------------------------------------//
    //-----Calculations---------------------------------------//
    basis = average[maLength, maType](close)
    atrValue = averagetruerange[atrLength]
    upperBand = basis + atrValue * atrMult
    lowerBand = basis - atrValue * atrMult
    
    if close crosses over upperBand then
       trend = 1
    elsif close crosses under lowerBand then
       trend = -1
    else
       trend = trend[1]
    endif
    
    bandRange = upperBand - lowerBand
    
    if trend = 1 then
       level100 = lowerBand
       fib50 = lowerBand + bandRange * 0.5
       fib618 = lowerBand + bandRange * 0.382
       fib786 = lowerBand + bandRange * 0.214
       r = 36
       g = 192
       b = 212
    else
       level100 = upperBand
       fib50 = upperBand - bandRange * 0.5
       fib618 = upperBand - bandRange * 0.382
       fib786 = upperBand - bandRange * 0.214
       r = 235
       g = 51
       b = 51
    endif
    //--------------------------------------------------------//
    //-----Trend change: linebr equivalent--------------------//
    trendChange = trend  trend[1]
    
    if trend  0 and trendChange = 0 then
       pLevel = level100
       pFib50 = fib50
       pFib618 = fib618
       pFib786 = fib786
    else
       pLevel = undefined
       pFib50 = undefined
       pFib618 = undefined
       pFib786 = undefined
    endif
    //--------------------------------------------------------//
    //-----Golden pocket fill + trend-change marker-----------//
    colorbetween(pFib618, pFib786, 255, 123, 0, 70)
    
    if trendChange and trend  0 and barindex>2*maLength then
       src=close
       drawtext("◉", barindex, level100) coloured(r, g, b)
       drawtext("#src#", barindex, level100+atrValue) coloured(r, g, b)
    endif
    //--------------------------------------------------------//
    RETURN pLevel COLOURED(r, g, b) STYLE(line, 3) AS "Trend MA",       pFib618 COLOURED(255, 123, 0) STYLE(line, 1) AS "Fib 0.618",       pFib786 COLOURED(255, 123, 0) STYLE(line, 1) AS "Fib 0.786",       pFib50 COLOURED(128, 128, 128) STYLE(line, 1) AS "Fib 0.5"
    



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

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Stenozar @stenozar Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 week, 4 days ago.

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 05/16/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...