Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Fibonacci Levels with Extensions", overlay=true)
- // Fibonacci levels
- fibonacciLevels = array.new_float(7)
- array.set(fibonacciLevels, 0, 0.0)
- array.set(fibonacciLevels, 1, 0.236)
- array.set(fibonacciLevels, 2, 0.382)
- array.set(fibonacciLevels, 3, 0.5)
- array.set(fibonacciLevels, 4, 0.618)
- array.set(fibonacciLevels, 5, 0.786)
- array.set(fibonacciLevels, 6, 1.0)
- // Calculate Fibonacci levels between two lines
- fibonacciBetweenLevels(lowLevel, highLevel) =>
- fibRange = highLevel - lowLevel
- fibLevels = array.new_float()
- for level in fibonacciLevels
- fibValue = lowLevel + (fibRange * level)
- array.push(fibLevels, fibValue)
- fibLevels
- // Calculate Fibonacci levels with extensions
- fibonacciWithExtensions() =>
- highestHigh = ta.highest(high, 600)
- lowestLow = ta.lowest(low, 600)
- fibLevels = fibonacciBetweenLevels(lowestLow, highestHigh)
- minGap = 200 // Minimum gap between Fibonacci lines
- while (highestHigh - lowestLow) >= minGap and array.size(fibLevels) < 1000
- lowLevel = ta.lowest(low, 150)
- highLevel = ta.highest(high, 120)
- newLevels = fibonacciBetweenLevels(lowLevel, highLevel)
- for level in newLevels
- array.push(fibLevels, level)
- lowestLow := lowLevel
- highestHigh := highLevel
- fibLevels
- // Get Fibonacci levels with extensions
- fibonacciLevelsExtended = fibonacciWithExtensions()
- // Plot horizontal lines at Fibonacci levels
- for level in fibonacciLevelsExtended
- line.new(x1=bar_index[100], y1=level, x2=bar_index, y2=level, color=color.rgb(0, 0, 0))
- // // // Plot horizontal line at the last Fibonacci level
- // // line.new(x1=bar_index[1], y1=lastFibLevel[array.size(lastFibLevel) - 1])[0], x2=bar_index, y2=lastFibLevel[array.size(lastFibLevel) - 1][0], color=color.rgb(0, 0, 0))
- // // Get the last Fibonacci level
- // lastFibLevel = fibonacciLevelsExtended[array.size(fibonacciLevelsExtended) - 1][0]
- // // Plot horizontal line at the last Fibonacci level
- // line.new(x1=bar_index[1], y1=lastFibLevel, x2=bar_index, y2=lastFibLevel, color=color.rgb(0, 0, 0))
Advertisement
Add Comment
Please, Sign In to add comment