xmd79

Fibonacci Progression With Breaks [LUX]

Apr 19th, 2022
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. // This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
  2. // © LuxAlgo
  3.  
  4. //@version=5
  5. indicator("Fibonacci Progression With Breaks [LUX]",overlay=1,max_labels_count=500,max_lines_count=500)
  6. method = input.string('Atr',options=['Atr','Manual'],inline='inline1')
  7. size = input(1.,'',inline='inline1')
  8. max = input(3,'Sequence Length')
  9. //----
  10. var fib = array.from(1,1)
  11. var dist = 0.,var avg = 0.,var fib_n = 1,var os = 0
  12.  
  13. src = close
  14. n = bar_index
  15.  
  16. if barstate.isfirst
  17. for i = 1 to max
  18. array.push(fib,array.get(fib,i-1) + array.get(fib,i))
  19. //----
  20. if method == 'Atr'
  21. dist := ta.atr(200)*size*array.get(fib,fib_n)
  22. else
  23. dist := size*array.get(fib,fib_n)
  24.  
  25. fib_n := math.abs(src-avg) > dist ? fib_n+1 : fib_n
  26. avg := nz(fib_n > max+1 ? src : avg[1],src)
  27. fib_n := fib_n > max+1 ? 1 : fib_n
  28.  
  29. buy = avg > avg[1]
  30. sell = avg < avg[1]
  31. os := buy ? 1 : sell ? 0 : os
  32.  
  33. tp = avg != avg[1] ? na : os == 1 ? avg + dist : avg - dist
  34. sl = avg != avg[1] ? na : os == 0 ? avg + dist : avg - dist
  35. //----
  36. css = os == 1 ? #0cb51a : #ff1100
  37. plot0 = plot(src,color=na)
  38. plot1 = plot(avg,color=na)
  39. fill(plot0,plot1,color.new(css,80))
  40. //----
  41. plotshape(buy ? low : na,"Buy Label",shape.labelup,location.absolute,#0cb51a,0,text="B",textcolor=color.white,size=size.tiny)
  42. plotshape(sell ? high : na,"Sell Label",shape.labeldown,location.absolute,#ff1100,0,text="S",textcolor=color.white,size=size.tiny)
  43.  
  44. plot(tp,'Target',#0cb51a,1,plot.style_linebr)
  45. plot(sl,'Stop',#ff1100,1,plot.style_linebr)
  46.  
  47. if fib_n > fib_n[1] and os == 1 and src > avg
  48. label.new(n,src,str.tostring(array.get(fib,fib_n-1)) + ' ✅',yloc=yloc.abovebar
  49. ,color=na,style=label.style_label_down,textcolor=color.gray,size=size.small)
  50. else if fib_n > fib_n[1] and os == 1 and src < avg
  51. label.new(n,src,str.tostring(array.get(fib,fib_n-1)) + ' ❌',yloc=yloc.belowbar
  52. ,color=na,style=label.style_label_up,textcolor=color.gray,size=size.small)
  53.  
  54. if fib_n > fib_n[1] and os == 0 and src < avg
  55. label.new(n,src,str.tostring(array.get(fib,fib_n-1)) + ' ✅',yloc=yloc.belowbar
  56. ,color=na,style=label.style_label_up,textcolor=color.gray,size=size.small)
  57. else if fib_n > fib_n[1] and os == 0 and src > avg
  58. label.new(n,src,str.tostring(array.get(fib,fib_n-1)) + ' ❌',yloc=yloc.abovebar
  59. ,color=na,style=label.style_label_down,textcolor=color.gray,size=size.small)
  60.  
Advertisement
Add Comment
Please, Sign In to add comment