ProRealCode - Trading & Coding with ProRealTime™
Buenas Tardes:
Se podría traducir este indicador de Tradingview a nuestra plataforma.
https://es.tradingview.com/script/Fw4QByti-Auto-Fib-Retracement-custom-lines/
GRACIAS
//@version=6
indicator(“Auto Fib Retracement-custom lines”, overlay=true)
devTooltip = “Deviation is a multiplier that affects how much the price should deviate from the previous pivot in order for the bar to become a new pivot.”
depthTooltip = “The minimum number of bars that will be taken into account when calculating the indicator.”
// pivots threshold
threshold_multiplier = input.float(title=”Deviation”, defval=7, minval=0, tooltip=devTooltip)
depth = input.int(title=”Depth”, defval=20, minval=2, tooltip=depthTooltip)
reverse = input(false, “Reverse”, display = display.data_window)
var extendLeft = input(false, “Extend Left | Extend Right”, inline = “Extend Lines”)
var extendRight = input(true, “”, inline = “Extend Lines”)
var extending = extend.none
if extendLeft and extendRight
extending := extend.both
if extendLeft and not extendRight
extending := extend.left
if not extendLeft and extendRight
extending := extend.right
prices = input(true, “Show Prices”, display = display.data_window)
levels = input(true, “Show Levels”, inline = “Levels”, display = display.data_window)
levelsFormat = input.string(“Values”, “”, options = [“Values”, “Percent”], inline = “Levels”, display = display.data_window, active = levels)
labelsPosition = input.string(“Right”, “Labels Position”, options = [“Left”, “Right”], display = display.data_window)
var int backgroundTransparency = input.int(100, “Background Transparency”, minval = 0, maxval = 100, display = display.data_window)
import TradingView/ZigZag/7 as zigzag
update()=>
var settings = zigzag.Settings.new(threshold_multiplier, depth, color(na), false, false, false, false, “Absolute”, true)
var zigzag.ZigZag zigZag = zigzag.newInstance(settings)
var zigzag.Pivot lastP = na
var float startPrice = na
var float height = na
if barstate.islast and zigZag.pivots.size() < 2
runtime.error(“Not enough data to calculate Auto Fib Retracement on the current symbol. Change the chart’s timeframe to a lower one or select a smaller calculation depth using the indicator’s `Depth` settings.”)
settings.devThreshold := ta.atr(10) / close * 100 * threshold_multiplier
if zigZag.update()
lastP := zigZag.lastPivot()
if not na(lastP)
var line lineLast = na
if na(lineLast)
lineLast := line.new(lastP.start, lastP.end, xloc=xloc.bar_time, color=color.gray, width=1, style=line.style_dashed)
else
line.set_first_point(lineLast, lastP.start)
line.set_second_point(lineLast, lastP.end)
startPrice := reverse ? lastP.start.price : lastP.end.price
endPrice = reverse ? lastP.end.price : lastP.start.price
height := (startPrice > endPrice ? -1 : 1) * math.abs(startPrice – endPrice)
[lastP, startPrice, height]
[lastP, startPrice, height] = update()
_draw_line(price, col, lineWidth) =>
var id = line.new(lastP.start.time, lastP.start.price, time, price, xloc=xloc.bar_time, color=col, width=lineWidth, extend=extending)
line.set_xy1(id, lastP.start.time, price)
line.set_xy2(id, lastP.end.time, price)
id
_draw_label(price, txt, txtColor) =>
x = labelsPosition == “Left” ? lastP.start.time : not extendRight ? lastP.end.time : time
labelStyle = labelsPosition == “Left” ? label.style_label_right : label.style_label_left
align = labelsPosition == “Left” ? text.align_right : text.align_left
labelsAlignStrLeft = txt + ‘n n’
labelsAlignStrRight = ‘ ‘ + txt + ‘n n’
labelsAlignStr = labelsPosition == “Left” ? labelsAlignStrLeft : labelsAlignStrRight
var id = label.new(x=x, y=price, xloc=xloc.bar_time, text=labelsAlignStr, textcolor=txtColor, style=labelStyle, textalign=align, color=#00000000)
label.set_xy(id, x, price)
label.set_text(id, labelsAlignStr)
label.set_textcolor(id, txtColor)
_wrap(txt) =>
“(” + str.tostring(txt, format.mintick) + “)”
_label_txt(level, price) =>
l = levelsFormat == “Values” ? str.tostring(level) : str.tostring(level * 100) + “%”
(levels ? l : “”) + (prices ? _wrap(price) : “”)
_crossing_level(series float sr, series float r) =>
(r > sr and r < sr[1]) or (r < sr and r > sr[1])
processLevel(bool show, float value, color colorL, line lineIdOther, int lineWidth) =>
float m = value
r = startPrice + height * m
crossed = _crossing_level(close, r)
if show and not na(lastP)
lineId = _draw_line(r, colorL, lineWidth)
_draw_label(r, _label_txt(m, r), colorL)
if crossed
alert(“Autofib: ” + syminfo.ticker + ” crossing level ” + str.tostring(value))
if not na(lineIdOther)
linefill.new(lineId, lineIdOther, color = color.new(colorL, backgroundTransparency))
lineId
else
lineIdOther
// Grupisani inputi po levelima – svaki level u svom redu
show_0 = input(true, “0”, inline=”0″, display=display.data_window)
value_0 = input(0, “”, inline=”0″, display=display.data_window)
color_0 = input(color.rgb(0, 0, 3), “”, inline=”0″, display=display.data_window)
width_0 = input.int(4, “”, minval=1, maxval=5, inline=”0″, display=display.data_window)
show_0_236 = input(false, “0.236”, inline=”0.236″, display=display.data_window)
value_0_236 = input(0.236, “”, inline=”0.236″, display=display.data_window)
color_0_236 = input(#f44336, “”, inline=”0.236″, display=display.data_window)
width_0_236 = input.int(1, “”, minval=1, maxval=5, inline=”0.236″, display=display.data_window)
show_0_382 = input(true, “0.382”, inline=”0.382″, display=display.data_window)
value_0_382 = input(0.382, “”, inline=”0.382″, display=display.data_window)
color_0_382 = input(color.rgb(255, 174, 0), “”, inline=”0.382″, display=display.data_window)
width_0_382 = input.int(1, “”, minval=1, maxval=5, inline=”0.382″, display=display.data_window)
show_0_5 = input(true, “0.5”, inline=”0.5″, display=display.data_window)
value_0_5 = input(0.5, “”, inline=”0.5″, display=display.data_window)
color_0_5 = input(color.rgb(255, 251, 0), “”, inline=”0.5″, display=display.data_window)
width_0_5 = input.int(1, “”, minval=1, maxval=5, inline=”0.5″, display=display.data_window)
show_0_618 = input(true, “0.618”, inline=”0.618″, display=display.data_window)
value_0_618 = input(0.618, “”, inline=”0.618″, display=display.data_window)
color_0_618 = input(color.rgb(0, 255, 242), “”, inline=”0.618″, display=display.data_window)
width_0_618 = input.int(3, “”, minval=1, maxval=5, inline=”0.618″, display=display.data_window)
show_0_705 = input(true, “0.705”, inline=”0.705″, display=display.data_window)
value_0_705 = input(0.705, “”, inline=”0.705″, display=display.data_window)
color_0_705 = input(#009688, “”, inline=”0.705″, display=display.data_window)
width_0_705 = input.int(3, “”, minval=1, maxval=5, inline=”0.705″, display=display.data_window)
show_0_786 = input(false, “0.786”, inline=”0.786″, display=display.data_window)
value_0_786 = input(0.786, “”, inline=”0.786″, display=display.data_window)
color_0_786 = input(#64b5f6, “”, inline=”0.786″, display=display.data_window)
width_0_786 = input.int(1, “”, minval=1, maxval=5, inline=”0.786″, display=display.data_window)
show_1 = input(true, “1”, inline=”1″, display=display.data_window)
value_1 = input(1, “”, inline=”1″, display=display.data_window)
color_1 = input(#000000, “”, inline=”1″, display=display.data_window)
width_1 = input.int(4, “”, minval=1, maxval=5, inline=”1″, display=display.data_window)
show_1_272 = input(false, “1.272”, inline=”1.272″, display=display.data_window)
value_1_272 = input(1.272, “”, inline=”1.272″, display=display.data_window)
color_1_272 = input(#f4f8f5, “”, inline=”1.272″, display=display.data_window)
width_1_272 = input.int(1, “”, minval=1, maxval=5, inline=”1.272″, display=display.data_window)
show_1_500 = input(false, “1.500”, inline=”1.500″, display=display.data_window)
value_1_500 = input(1.500, “”, inline=”1.500″, display=display.data_window)
color_1_500 = input(#f1f436, “”, inline=”1.500″, display=display.data_window)
width_1_500 = input.int(1, “”, minval=1, maxval=5, inline=”1.500″, display=display.data_window)
show_1_618 = input(false, “1.618”, inline=”1.618″, display=display.data_window)
value_1_618 = input(1.618, “”, inline=”1.618″, display=display.data_window)
color_1_618 = input(#29e6ff, “”, inline=”1.618″, display=display.data_window)
width_1_618 = input.int(1, “”, minval=1, maxval=5, inline=”1.618″, display=display.data_window)
show_1_705 = input(false, “1.705”, inline=”1.705″, display=display.data_window)
value_1_705 = input(1.705, “”, inline=”1.705″, display=display.data_window)
color_1_705 = input(#0333b4, “”, inline=”1.705″, display=display.data_window)
width_1_705 = input.int(1, “”, minval=1, maxval=5, inline=”1.705″, display=display.data_window)
show_2_000 = input(false, “2.000”, inline=”2.000″, display=display.data_window)
value_2_000 = input(2.000, “”, inline=”2.000″, display=display.data_window)
color_2_000 = input(#000000, “”, inline=”2.000″, display=display.data_window)
width_2_000 = input.int(1, “”, minval=1, maxval=5, inline=”2.000″, display=display.data_window)
show_2_618 = input(false, “2.618”, inline=”2.618″, display=display.data_window)
value_2_618 = input(2.618, “”, inline=”2.618″, display=display.data_window)
color_2_618 = input(color.rgb(81, 252, 243), “”, inline=”2.618″, display=display.data_window)
width_2_618 = input.int(1, “”, minval=1, maxval=5, inline=”2.618″, display=display.data_window)
show_2_705 = input(false, “2_705″, inline=”2_705”, display=display.data_window)
value_2_705 = input(2.705, “”, inline=”2_705″, display=display.data_window)
color_2_705 = input(color.rgb(0, 29, 124), “”, inline=”2_705″, display=display.data_window)
width_2_705 = input.int(1, “”, minval=1, maxval=5, inline=”2_705″, display=display.data_window)
show_neg_0_272 = input(false, “-0.272″, inline=”-0.272″, display=display.data_window)
value_neg_0_272 = input(-0.272, “”, inline=”-0.272″, display=display.data_window)
color_neg_0_272 = input(color.rgb(252, 176, 105), “”, inline=”-0.272″, display=display.data_window)
width_neg_0_272 = input.int(1, “”, minval=1, maxval=5, inline=”-0.272″, display=display.data_window)
show_neg_0_500 = input(false, “-0.500″, inline=”-0.500″, display=display.data_window)
value_neg_0_500 = input(-0.500, “”, inline=”-0.500″, display=display.data_window)
color_neg_0_500 = input(#81c784, “”, inline=”-0.500″, display=display.data_window)
width_neg_0_500 = input.int(1, “”, minval=1, maxval=5, inline=”-0.500″, display=display.data_window)
show_neg_0_618 = input(false, “-0.618″, inline=”-0.618″, display=display.data_window)
value_neg_0_618 = input(-0.618, “”, inline=”-0.618″, display=display.data_window)
color_neg_0_618 = input(#20ffe9, “”, inline=”-0.618″, display=display.data_window)
width_neg_0_618 = input.int(1, “”, minval=1, maxval=5, inline=”-0.618″, display=display.data_window)
show_neg_0_705 = input(false, “-0.705″, inline=”-0.705″, display=display.data_window)
value_neg_0_705 = input(-0.705, “”, inline=”-0.705″, display=display.data_window)
color_neg_0_705 = input(#002f96, “”, inline=”-0.705″, display=display.data_window)
width_neg_0_705 = input.int(1, “”, minval=1, maxval=5, inline=”-0.705″, display=display.data_window)
show_neg_1_000 = input(false, “-1_000″, inline=”-1_000″, display=display.data_window)
value_neg_1_000 = input(-1.000, “”, inline=”-1_000″, display=display.data_window)
color_neg_1_000= input(color.rgb(0, 0, 0), “”, inline=”-1_000″, display=display.data_window)
width_neg_1_000 = input.int(1, “”, minval=1, maxval=5, inline=”-1_000″, display=display.data_window)
show_neg_1_618 = input(false, “-1.618″, inline=”-1.618″, display=display.data_window)
value_neg_1_618 = input(-1.618, “”, inline=”-1.618″, display=display.data_window)
color_neg_1_618 = input(#2cf7e2, “”, inline=”-1.618″, display=display.data_window)
width_neg_1_618 = input.int(1, “”, minval=1, maxval=5, inline=”-1.618″, display=display.data_window)
show_neg_1_705 = input(false, “-1.705″, inline=”-1.705″, display=display.data_window)
value_neg_1_705 = input(-1.705, “”, inline=”-1.705″, display=display.data_window)
color_neg_1_705 = input(#003c96, “”, inline=”-1.705″, display=display.data_window)
width_neg_1_705 = input.int(1, “”, minval=1, maxval=5, inline=”-1.705″, display=display.data_window)
lineId0 = processLevel(show_neg_0_705, value_neg_0_705, color_neg_0_705, line(na), width_neg_0_705)
lineId1 = processLevel(show_neg_0_618, value_neg_0_618, color_neg_0_618, lineId0, width_neg_0_618)
lineId2 = processLevel(show_neg_0_500, value_neg_0_500, color_neg_0_500, lineId1, width_neg_0_500)
lineId3 = processLevel(show_neg_0_272, value_neg_0_272, color_neg_0_272, lineId2, width_neg_0_272)
lineId4 = processLevel(show_0, value_0, color_0, lineId3, width_0)
lineId5 = processLevel(show_0_236, value_0_236, color_0_236, lineId4, width_0_236)
lineId6 = processLevel(show_0_382, value_0_382, color_0_382, lineId5, width_0_382)
lineId7 = processLevel(show_0_5, value_0_5, color_0_5, lineId6, width_0_5)
lineId8 = processLevel(show_0_618, value_0_618, color_0_618, lineId7, width_0_618)
lineId9 = processLevel(show_0_705, value_0_705, color_0_705, lineId8, width_0_705)
lineId10 = processLevel(show_0_786, value_0_786, color_0_786, lineId9, width_0_786)
lineId11 = processLevel(show_1, value_1, color_1, lineId10, width_1)
lineId12 = processLevel(show_1_272, value_1_272, color_1_272, lineId11, width_1_272)
lineId13 = processLevel(show_1_500, value_1_500, color_1_500, lineId12, width_1_500)
lineId14 = processLevel(show_1_618, value_1_618, color_1_618, lineId13, width_1_618)
lineId15 = processLevel(show_1_705, value_1_705, color_1_705, lineId14, width_1_705)
lineId16 = processLevel(show_2_000, value_2_000, color_2_000, lineId15, width_2_000)
lineId17 = processLevel(show_2_618, value_2_618, color_2_618, lineId16, width_2_618)
lineId18 = processLevel(show_2_705, value_2_705, color_2_705, lineId17, width_2_705)
lineId19 = processLevel(show_neg_1_000, value_neg_1_000, color_neg_1_000, lineId18, width_neg_1_000)
lineId20 = processLevel(show_neg_1_618, value_neg_1_618, color_neg_1_618, lineId19, width_neg_1_618)
lineId21 = processLevel(show_neg_1_705, value_neg_1_705, color_neg_1_705, lineId20, width_neg_1_705)
Aqui tienes:
//PRC_Auto Fib Retracement custom lines [AleksinAleksandar]
//version = 1
//22.06.2026
//Ivan Gonzalez @ www.prorealcode.com
DEFPARAM drawonlastbaronly = true
//--- Parametros ---
depth = 20 // ventana de barras del ZigZag (Pine "Depth")
reverse = 0 // 0 = 0% en el ultimo extremo; 1 = invertido
showLabels = 1
//--- ZigZag: pivotes Donchian ---
ph = (high = highest[depth](high))
pl = (low = lowest[depth](low))
if ph and not pl then
dir = 1
elsif pl and not ph then
dir = -1
else
dir = dir
endif
dirchanged = dir <> dir[1]
if ph or pl then
if dirchanged then
if dir = 1 then
$zigzag[t+1] = highest[depth](high)
$zigzagidx[t+1] = barindex
t = t + 1
elsif dir = -1 then
$zigzag[t+1] = lowest[depth](low)
$zigzagidx[t+1] = barindex
t = t + 1
endif
else
if dir = 1 and highest[depth](high) > $zigzag[t] then
$zigzag[t] = highest[depth](high)
$zigzagidx[t] = barindex
elsif dir = -1 and lowest[depth](low) < $zigzag[t] then
$zigzag[t] = lowest[depth](low)
$zigzagidx[t] = barindex
endif
endif
endif
//--- Dibujo Fibonacci del ultimo tramo ---
if islastbarupdate and t >= 2 then
$zigzag[0] = undefined
if reverse then
startP = $zigzag[t-1]
endP = $zigzag[t]
else
startP = $zigzag[t]
endP = $zigzag[t-1]
endif
height = endP - startP
x1 = $zigzagidx[t-1]
x2 = barindex
r = startP
drawsegment(x1, r, x2, r) coloured(0,0,0) style(line,4)
if showLabels then
drawtext("0% (#r#)", x2+15, r) coloured(0,0,0)
endif
r = startP + height * 0.382
drawsegment(x1, r, x2, r) coloured(255,174,0) style(line,1)
if showLabels then
drawtext("38.2% (#r#)", x2+15, r) coloured(255,174,0)
endif
r = startP + height * 0.5
drawsegment(x1, r, x2, r) coloured(255,200,0) style(line,1)
if showLabels then
drawtext("50% (#r#)", x2+15, r) coloured(255,200,0)
endif
r = startP + height * 0.618
drawsegment(x1, r, x2, r) coloured(0,200,200) style(line,3)
if showLabels then
drawtext("61.8% (#r#)", x2+15, r) coloured(0,200,200)
endif
r = startP + height * 0.705
drawsegment(x1, r, x2, r) coloured(0,150,136) style(line,3)
if showLabels then
drawtext("70.5% (#r#)", x2+15, r) coloured(0,150,136)
endif
r = startP + height
drawsegment(x1, r, x2, r) coloured(0,0,0) style(line,4)
if showLabels then
drawtext("100% (#r#)", x2+15, r) coloured(0,0,0)
endif
endif
return
This topic contains 1 reply,
has 2 voices, and was last updated by
Iván González
1 day, 12 hours ago.
| Forum: | TradingView to ProRealTime Translation Center Forum |
| Started: | 06/19/2026 |
| Status: | Active |
| Attachments: | No files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.