xmd79

[MAD] Fib retracement

Oct 29th, 2022
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.39 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © djmad
  3. //@version=5
  4.  
  5. indicator('[MAD] Fib retracement', overlay=true)
  6.  
  7. int Starttime = input.time(timestamp("2020-02-19"),title= "B O T T O M - L E F T", inline="B O T T O M - L E F T", confirm = true,group='Line 1')
  8. var Bottom = input.price(defval=100, title= "B O T T O M L E F T", inline="B O T T O M - L E F T", confirm = true,group='Line 1')
  9. var Top = input.price(defval=100, title='T O P',confirm = true)
  10. var decimals_price = input.int(2,"Price decimals",group="decimals trimming",inline="1")
  11. var decimals_percent = input.int(2,"Percent decimals",group="decimals trimming",inline="1")
  12.  
  13.  
  14. channels = array.from(
  15. input.float(1.0 ,"Level",group="Fiblevels",step=0.001)
  16. ,input.float(0.786 ,"Level",group="Fiblevels",step=0.001)
  17.  
  18. ,input.float(0.65 ,"Level",group="Fiblevels",step=0.001)
  19. ,input.float(0.618 ,"Levea",group="Fiblevels",step=0.001)
  20.  
  21. ,input.float(0.5 ,"Level",group="Fiblevels",step=0.001)
  22.  
  23. ,input.float(0.382 ,"Level",group="Fiblevels",step=0.001)
  24. ,input.float(0.35 ,"Level",group="Fiblevels",step=0.001)
  25.  
  26. ,input.float(0.236 ,"Level",group="Fiblevels",step=0.001)
  27. ,input.float(0.0 ,"Level",group="Fiblevels",step=0.001)
  28. )
  29.  
  30. textcolor1=input.color(color.white,"Textcolor")
  31. size1=input.string(size.tiny,options = [size.tiny,size.small,size.normal,size.large])
  32.  
  33.  
  34. linearray = array.new_line(0,na)
  35.  
  36.  
  37. f_round(_val, decimals) =>
  38. // Rounds _val to _decimals places.
  39. _p = math.pow(10, decimals)
  40. math.round(math.abs(_val) * _p) / _p * math.sign(_val)
  41.  
  42. f_fibcalc(Top, Bottom, channels) =>
  43. output = array.new<float>()
  44.  
  45. Diff = Top-Bottom
  46.  
  47. for i = 0 to array.size(channels) -1
  48. array.push(output, Bottom + Diff * array.get(channels,i))
  49. output
  50.  
  51.  
  52. output = f_fibcalc(Top,Bottom, channels)
  53.  
  54. cleareverything() =>
  55. a_allLines = line.all
  56. if array.size(a_allLines) > 0
  57. for i = 0 to array.size(a_allLines) - 1
  58. line.delete(array.get(a_allLines, i))
  59. a_allLabel = label.all
  60. if array.size(a_allLabel) > 0
  61. for i = 0 to array.size(a_allLabel) - 1
  62. label.delete(array.get(a_allLabel, i))
  63. a_allFills = linefill.all
  64. if array.size(a_allFills) > 0
  65. for i = 0 to array.size(a_allFills) - 1
  66. linefill.delete(array.get(a_allFills, i))
  67.  
  68.  
  69. drawout() =>
  70. for i = 0 to array.size(channels)-1
  71. line line1 = na
  72. linefill fill1 = na
  73. label label1 = na
  74. label label2 = na
  75.  
  76. line1 := line.new(x1= Starttime, y1= array.get(output,i),x2 = time, y2 = array.get(output,i), xloc=xloc.bar_time, style=line.style_solid, extend=extend.right,color=input.color(color.white,"Linecolor"))
  77. array.insert(linearray,i,line1)
  78.  
  79. if i == 1
  80. fill1 := linefill.new(array.get(linearray,0),array.get(linearray,1),color=input.color(color.rgb(175, 76, 76, 60),"Fill-Color"))
  81. if i == 3
  82. fill1 := linefill.new(array.get(linearray,2),array.get(linearray,3),color=input.color(color.rgb(175, 172, 76, 60),"Fill-Color"))
  83. if i == 6
  84. fill1 := linefill.new(array.get(linearray,5),array.get(linearray,6),color=input.color(color.rgb(175, 172, 76, 60),"Fill-Color"))
  85. if i == 8
  86. fill1 := linefill.new(array.get(linearray,7),array.get(linearray,8),color=input.color(color.rgb(76, 175, 79, 60),"Fill-Color"))
  87.  
  88. label1 := label.new(x=time <= chart.right_visible_bar_time?time:chart.right_visible_bar_time, y= array.get(output,i),
  89. text = time <= chart.right_visible_bar_time?
  90. " " + str.tostring(array.get(channels,i)) + ' (' + str.tostring(f_round(array.get(output,i),decimals_price)) + ') ' + str.tostring(f_round(array.get(output,i)/close*100-100,decimals_percent)) + '% = ' + str.tostring(f_round(array.get(output,i)-close,decimals_price)) :
  91. "" + str.tostring(array.get(channels,i)) + ' (' + str.tostring(f_round(array.get(output,i),decimals_price)) + ') ',
  92. xloc=xloc.bar_time,
  93. yloc=yloc.price,
  94. color=color.white,
  95. style=label.style_none,
  96. textcolor=textcolor1,
  97. size=size1,
  98. textalign=text.align_left)
  99.  
  100. if i == 8
  101. label2 := label.new(x=time <= chart.right_visible_bar_time?time:chart.right_visible_bar_time, y= array.get(output,i),
  102. text = time <= chart.right_visible_bar_time?
  103. " Range-Up = " + str.tostring(f_round(array.get(output,0)/array.get(output,8)*100-100,decimals_percent)) + '%\n Range-Down = ' + str.tostring(f_round(array.get(output,8)/array.get(output,0)*100-100,decimals_percent)) + '%\n':
  104. "",
  105. xloc=xloc.bar_time,
  106. yloc=yloc.price,
  107. color=color.white,
  108. style=label.style_none,
  109. textcolor=textcolor1,
  110. size=size1,
  111. textalign=text.align_left)
  112.  
  113.  
  114. cleareverything()
  115. drawout()
Advertisement
Add Comment
Please, Sign In to add comment