xmd79

Fibonacci Levels with Extensions

May 26th, 2023
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. //@version=5
  2. indicator("Fibonacci Levels with Extensions", overlay=true)
  3.  
  4. // Fibonacci levels
  5. fibonacciLevels = array.new_float(7)
  6. array.set(fibonacciLevels, 0, 0.0)
  7. array.set(fibonacciLevels, 1, 0.236)
  8. array.set(fibonacciLevels, 2, 0.382)
  9. array.set(fibonacciLevels, 3, 0.5)
  10. array.set(fibonacciLevels, 4, 0.618)
  11. array.set(fibonacciLevels, 5, 0.786)
  12. array.set(fibonacciLevels, 6, 1.0)
  13.  
  14. // Calculate Fibonacci levels between two lines
  15. fibonacciBetweenLevels(lowLevel, highLevel) =>
  16. fibRange = highLevel - lowLevel
  17. fibLevels = array.new_float()
  18. for level in fibonacciLevels
  19. fibValue = lowLevel + (fibRange * level)
  20. array.push(fibLevels, fibValue)
  21. fibLevels
  22.  
  23. // Calculate Fibonacci levels with extensions
  24. fibonacciWithExtensions() =>
  25. highestHigh = ta.highest(high, 600)
  26. lowestLow = ta.lowest(low, 600)
  27. fibLevels = fibonacciBetweenLevels(lowestLow, highestHigh)
  28.  
  29. minGap = 200 // Minimum gap between Fibonacci lines
  30. while (highestHigh - lowestLow) >= minGap and array.size(fibLevels) < 1000
  31. lowLevel = ta.lowest(low, 150)
  32. highLevel = ta.highest(high, 120)
  33. newLevels = fibonacciBetweenLevels(lowLevel, highLevel)
  34. for level in newLevels
  35. array.push(fibLevels, level)
  36.  
  37. lowestLow := lowLevel
  38. highestHigh := highLevel
  39.  
  40. fibLevels
  41.  
  42. // Get Fibonacci levels with extensions
  43. fibonacciLevelsExtended = fibonacciWithExtensions()
  44.  
  45. // Plot horizontal lines at Fibonacci levels
  46. for level in fibonacciLevelsExtended
  47. line.new(x1=bar_index[100], y1=level, x2=bar_index, y2=level, color=color.rgb(0, 0, 0))
  48.  
  49.  
  50. // // // Plot horizontal line at the last Fibonacci level
  51. // // 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))
  52.  
  53. // // Get the last Fibonacci level
  54. // lastFibLevel = fibonacciLevelsExtended[array.size(fibonacciLevelsExtended) - 1][0]
  55.  
  56. // // Plot horizontal line at the last Fibonacci level
  57. // line.new(x1=bar_index[1], y1=lastFibLevel, x2=bar_index, y2=lastFibLevel, color=color.rgb(0, 0, 0))
  58.  
Advertisement
Add Comment
Please, Sign In to add comment