OPEN-SOURCE SCRIPT
Auto Fib Retracement Advanced

//version=5
indicator("Auto Fib Retracement Advanced", overlay=true, max_lines_count=500) // Increase max_lines_count
leftBars = input.int(10, "Pivot Left Bars")
rightBars = input.int(10, "Pivot Right Bars")
extendRight = input.bool(true, "Extend Lines Right")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
var float lastHighPrice = na
var int lastHighBar = na
var float lastLowPrice = na
var int lastLowBar = na
// Arrays to store line IDs for management
var lines = array.new_line()
levels_values = array.from(0.0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0)
// Update pivot points and redraw lines when a new pivot is confirmed
if not na(swingHigh) or not na(swingLow)
if not na(swingHigh)
lastHighPrice := swingHigh
lastHighBar := bar_index
if not na(swingLow)
lastLowPrice := swingLow
lastLowBar := bar_index
// Delete existing lines before drawing new ones
for i = 0 to array.size(lines) - 1
line.delete(array.get(lines, i))
array.clear(lines)
if not na(lastHighPrice) and not na(lastLowPrice)
isUptrend = lastHighPrice > lastLowPrice
fibRange = math.abs(lastHighPrice - lastLowPrice)
// Draw new lines
for i = 0 to array.size(levels_values) - 1
levelValue = array.get(levels_values, i)
priceLevel = isUptrend ? lastLowPrice + fibRange * levelValue : lastHighPrice - fibRange * levelValue
// Use line.new to create persistent horizontal lines
newLine = line.new(x1=lastLowBar, y1=priceLevel, x2=bar_index + (extendRight ? 500 : 0), y2=priceLevel, color=color.gray, style=line.style_dashed)
array.push(lines, newLine)
indicator("Auto Fib Retracement Advanced", overlay=true, max_lines_count=500) // Increase max_lines_count
leftBars = input.int(10, "Pivot Left Bars")
rightBars = input.int(10, "Pivot Right Bars")
extendRight = input.bool(true, "Extend Lines Right")
swingHigh = ta.pivothigh(high, leftBars, rightBars)
swingLow = ta.pivotlow(low, leftBars, rightBars)
var float lastHighPrice = na
var int lastHighBar = na
var float lastLowPrice = na
var int lastLowBar = na
// Arrays to store line IDs for management
var lines = array.new_line()
levels_values = array.from(0.0, 0.236, 0.382, 0.5, 0.618, 0.786, 1.0)
// Update pivot points and redraw lines when a new pivot is confirmed
if not na(swingHigh) or not na(swingLow)
if not na(swingHigh)
lastHighPrice := swingHigh
lastHighBar := bar_index
if not na(swingLow)
lastLowPrice := swingLow
lastLowBar := bar_index
// Delete existing lines before drawing new ones
for i = 0 to array.size(lines) - 1
line.delete(array.get(lines, i))
array.clear(lines)
if not na(lastHighPrice) and not na(lastLowPrice)
isUptrend = lastHighPrice > lastLowPrice
fibRange = math.abs(lastHighPrice - lastLowPrice)
// Draw new lines
for i = 0 to array.size(levels_values) - 1
levelValue = array.get(levels_values, i)
priceLevel = isUptrend ? lastLowPrice + fibRange * levelValue : lastHighPrice - fibRange * levelValue
// Use line.new to create persistent horizontal lines
newLine = line.new(x1=lastLowBar, y1=priceLevel, x2=bar_index + (extendRight ? 500 : 0), y2=priceLevel, color=color.gray, style=line.style_dashed)
array.push(lines, newLine)
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.
סקריפט קוד פתוח
ברוח האמיתית של TradingView, יוצר הסקריפט הזה הפך אותו לקוד פתוח, כך שסוחרים יוכלו לעיין בו ולאמת את פעולתו. כל הכבוד למחבר! אמנם ניתן להשתמש בו בחינם, אך זכור כי פרסום חוזר של הקוד כפוף ל־כללי הבית שלנו.
כתב ויתור
המידע והפרסומים אינם מיועדים להיות, ואינם מהווים, ייעוץ או המלצה פיננסית, השקעתית, מסחרית או מכל סוג אחר המסופקת או מאושרת על ידי TradingView. קרא עוד ב־תנאי השימוש.