Advertisement
xmd79

Moving Fib Based on Donchain/Pivot/BB

Dec 9th, 2023
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 47.12 KB | None | 0 0
  1. // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © rapmadarang
  3.  
  4. //@version=5
  5. indicator(title="Moving Fib Based on Donchain/Pivot/BB", overlay=true)
  6.  
  7. //---------------------------------------------------------------------------------------------------------------------//
  8. //General input
  9. //---------------------------------------------------------------------------------------------------------------------//
  10.  
  11. Basis_of_HL = input.string("Donchain",title="High Low Basis",options=["Donchain","Pivot","Bollinger Bands"],tooltip="This will determine which point the indicator will consider as the high and low for the Fibonacci overlay.")
  12. Bias=input.string("Bull",options=["Bull","Bear"], tooltip = "This will determine where the Fibonacci overlay will start, whether it is from the low or high. Select 'Bull' for standard Fib, and choose 'Bear' for reverse Fib")
  13. period_length=input.int(200,title = "Period Length", group="Donchain", tooltip = "This will determine how many periods the indicator will consider when determining the high and low, if the setting is configured for Donchian.")
  14. donchain_src = input(close, title="Source",group="Donchain")
  15.  
  16. //Pivot Settings
  17. leftLenH = input.int(title="Pivot High", defval=20, minval=1, inline="Pivot High", group="Pivot Settings")
  18. rightLenH = input.int(title="/", defval=20, minval=1, inline="Pivot High", group="Pivot Settings")
  19. leftLenL = input.int(title="Pivot Low", defval=20, minval=1, inline="Pivot Low", group="Pivot Settings")
  20. rightLenL = input.int(title="/", defval=20, minval=1, inline="Pivot Low", group="Pivot Settings")
  21.  
  22. //Bollinger Bands Settings
  23. length = input.int(20, minval=1,group="Bollinger Bands Settings")
  24. maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"],group="Bollinger Bands Settings")
  25. src = input(close, title="Source",group="Bollinger Bands Settings")
  26. mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev",group="Bollinger Bands Settings")
  27.  
  28. //Log Scale toggle
  29. Log_scale =input.bool(false,title="Fib levels on log scale")
  30.  
  31. //Background Color, Fill and Transparency Settings
  32. Background_color_bool=input.string("Multi Color",title="Background Color Fill",options=["Multi Color","Single Color"],group="Background",
  33. tooltip="Provides the option to switch between a multi-color background, a single-color background, or no background.")
  34. Background_color_color=input.color(color.rgb(33, 149, 243, 80),title="Color",group="Background",
  35. tooltip="Provides an option to select background and line colors when the Background Color Fill is toggled to Single Color.")
  36.  
  37.  
  38. //Labels Settings
  39. Labels_toggle = input.bool(true,title="Labels",group="Labels",inline="label")
  40. Label_prices = input.bool(true,title="Show Prices", group="Labels")
  41. Label_int_float = input.string("Decimal",title=" ",options=["Decimal","Percent"] ,group="Labels",inline="label")
  42. line_width = input.int(1,title="Line Width",group="Line Settings")
  43.  
  44.  
  45. //Fib levels customization
  46. first_line_bool = input.bool(true,inline="1st line",title="",group="Fibonacci Levels")
  47. first_line_float = input.float(0,inline="1st line",title=" ",group="Fibonacci Levels")
  48. first_line_color = input.color(color.rgb(43, 42, 42),inline="1st line",title="",group="Fibonacci Levels")
  49. second_line_bool = input.bool(true,inline="2nd line",title="",group="Fibonacci Levels")
  50. second_line_float = input.float(0.236,inline="2nd line",title=" ",group="Fibonacci Levels")
  51. second_line_color = input.color(color.rgb(243, 33, 33),inline="2nd line",title="",group="Fibonacci Levels")
  52. third_line_bool = input.bool(true,inline="3rd line",title="",group="Fibonacci Levels")
  53. third_line_float = input.float(0.382,inline="3rd line",title=" ",group="Fibonacci Levels")
  54. third_line_color = input.color(color.rgb(138, 196, 30),inline="3rd line",title="",group="Fibonacci Levels")
  55. fourth_line_bool = input.bool(true,inline="4th line",title="",group="Fibonacci Levels")
  56. fourth_line_float = input.float(0.5,inline="4th line",title=" ",group="Fibonacci Levels")
  57. fourth_line_color = input.color(color.rgb(81, 182, 22),inline="4th line",title="",group="Fibonacci Levels")
  58. fifth_line_bool = input.bool(true,inline="5th line",title="",group="Fibonacci Levels")
  59. fifth_line_float = input.float(0.618,inline="5th line",title=" ",group="Fibonacci Levels")
  60. fifth_line_color = input.color(color.rgb(36, 109, 49),inline="5th line",title="",group="Fibonacci Levels")
  61. sixth_line_bool = input.bool(true,inline="6th line",title="",group="Fibonacci Levels")
  62. sixth_line_float = input.float(0.786,inline="6th line",title=" ",group="Fibonacci Levels")
  63. sixth_line_color = input.color(color.rgb(47, 101, 145),inline="6th line",title="",group="Fibonacci Levels")
  64. seventh_line_bool = input.bool(true,inline="7th line",title="",group="Fibonacci Levels")
  65. seventh_line_float = input.float(1,inline="7th line",title=" ",group="Fibonacci Levels")
  66. seventh_line_color = input.color(color.rgb(43, 42, 42),inline="7th line",title="",group="Fibonacci Levels")
  67.  
  68. //Fib extension customization
  69. first_extension_bool = input.bool(true,inline="1st extension",title="",group="Fibonacci Extension")
  70. first_extension_float = input.float(1.272,inline="1st extension",title=" ",group="Fibonacci Extension")
  71. first_extension_color = input.color(color.rgb(57, 23, 149),inline="1st extension",title="",group="Fibonacci Extension")
  72. second_extension_bool = input.bool(false,inline="2nd extension",title="",group="Fibonacci Extension")
  73. second_extension_float = input.float(1.618,inline="2nd extension",title=" ",group="Fibonacci Extension")
  74. second_extension_color = input.color(color.rgb(23, 120, 149),inline="2nd extension",title="",group="Fibonacci Extension")
  75. third_extension_bool = input.bool(false,inline="3rd extension",title="",group="Fibonacci Extension")
  76. third_extension_float = input.float(2,inline="3rd extension",title=" ",group="Fibonacci Extension")
  77. third_extension_color = input.color(color.rgb(23, 149, 101),inline="3rd extension",title="",group="Fibonacci Extension")
  78. fourth_extension_bool = input.bool(false,inline="4th extension",title="",group="Fibonacci Extension")
  79. fourth_extension_float = input.float(2.414,inline="4th extension",title=" ",group="Fibonacci Extension")
  80. fourth_extension_color = input.color(color.rgb(44, 149, 23),inline="4th extension",title="",group="Fibonacci Extension")
  81. fifth_extension_bool = input.bool(false,inline="5th extension",title="",group="Fibonacci Extension")
  82. fifth_extension_float = input.float(2.618,inline="5th extension",title=" ",group="Fibonacci Extension")
  83. fifth_extension_color = input.color(color.rgb(147, 149, 23),inline="5th extension",title="",group="Fibonacci Extension")
  84. sixth_extension_bool = input.bool(false,inline="6th extension",title="",group="Fibonacci Extension")
  85. sixth_extension_float = input.float(2.718,inline="6th extension",title=" ",group="Fibonacci Extension")
  86. sixth_extension_color = input.color(color.rgb(149, 80, 23),inline="6th extension",title="",group="Fibonacci Extension")
  87. seventh_extension_bool = input.bool(false,inline="7th extension",title="",group="Fibonacci Extension")
  88. seventh_extension_float = input.float(3.141,inline="7th extension",title=" ",group="Fibonacci Extension")
  89. seventh_extension_color = input.color(color.rgb(149, 23, 23),inline="7th extension",title="",group="Fibonacci Extension")
  90. eight_extension_bool = input.bool(false,inline="8th extension",title="",group="Fibonacci Extension")
  91. eight_extension_float = input.float(3.618,inline="8th extension",title=" ",group="Fibonacci Extension")
  92. eight_extension_color = input.color(color.rgb(149, 23, 101),inline="8th extension",title="",group="Fibonacci Extension")
  93. ninth_extension_bool = input.bool(false,inline="9th extension",title="",group="Fibonacci Extension")
  94. ninth_extension_float = input.float(4.236,inline="9th extension",title=" ",group="Fibonacci Extension")
  95. ninth_extension_color = input.color(color.rgb(103, 23, 149),inline="9th extension",title="",group="Fibonacci Extension")
  96.  
  97.  
  98. //Fib Fill Customization
  99. main_1st_block_fill = input.color(color.rgb(243, 33, 33, 90),title="Block 1",group="Fib BG Color")
  100. main_2nd_block_fill =input.color(color.rgb(138, 196, 30, 90),title="Block 2",group="Fib BG Color")
  101. main_3rd_block_fill =input.color(color.rgb(138, 196, 30, 90),title="Block 3",group="Fib BG Color")
  102. main_4th_block_fill =input.color(color.rgb(30, 196, 182, 90),title="Block 4",group="Fib BG Color")
  103. main_5th_block_fill =input.color(color.rgb(36, 53, 109, 90),title="Block 5",group="Fib BG Color")
  104. main_6th_block_fill =input.color(color.rgb(43, 42, 42, 90),title="Block 6",group="Fib BG Color")
  105. ex_7th_block_fill =input.color(color.rgb(243, 33, 177, 90),title="Block 7",group="Fib BG Color")
  106. ex_8th_block_fill =input.color(color.rgb(33, 44, 243, 90),title="Block 8",group="Fib BG Color")
  107. ex_9th_block_fill =input.color(color.rgb(8, 143, 210, 90),title="Block 9",group="Fib BG Color")
  108. ex_10th_block_fill =input.color(color.rgb(8, 210, 62, 90),title="Block 10",group="Fib BG Color")
  109. ex_11th_block_fill =input.color(color.rgb(8, 149, 210, 90),title="Block 11",group="Fib BG Color")
  110. ex_12th_block_fill =input.color(color.rgb(8, 210, 72, 90),title="Block 12",group="Fib BG Color")
  111. ex_13th_block_fill =input.color(color.rgb(210, 170, 8, 90),title="Block 13",group="Fib BG Color")
  112. ex_14th_block_fill =input.color(color.rgb(149, 8, 210, 90),title="Block 14",group="Fib BG Color")
  113. ex_15th_block_fill =input.color(color.rgb(207, 8, 210, 90),title="Block 15",group="Fib BG Color")
  114.  
  115.  
  116.  
  117. //---------------------------------------------------------------------------------------------------------------------//
  118. //Calculate the highest and lowest price of the selected time frame
  119. //---------------------------------------------------------------------------------------------------------------------//
  120.  
  121. var float highest_price = na
  122. var float lowest_price = na
  123.  
  124. if Basis_of_HL=="Donchain"
  125. highest_price := ta.highest(Log_scale==true ? math.log(high) : high,period_length)
  126. lowest_price := ta.lowest(Log_scale==true ? math.log(low) : low,period_length)
  127.  
  128. ph = ta.pivothigh(leftLenH, rightLenH)
  129. pl = ta.pivotlow(leftLenL, rightLenL)
  130. var float pivot_high = high
  131. var float pivot_low = low
  132.  
  133. pivot_high := ph !=0 ? ph : pivot_high
  134. pivot_low := pl !=0 ? pl : pivot_low
  135.  
  136.  
  137. if Basis_of_HL=="Pivot"
  138. highest_price := Log_scale==false ? pivot_high : math.log(pivot_high)
  139. lowest_price := Log_scale==false ? pivot_low : math.log(pivot_low)
  140.  
  141. ma(source, length, _type) =>
  142. switch _type
  143. "SMA" => ta.sma(source, length)
  144. "EMA" => ta.ema(source, length)
  145. "SMMA (RMA)" => ta.rma(source, length)
  146. "WMA" => ta.wma(source, length)
  147. "VWMA" => ta.vwma(source, length)
  148.  
  149. basis = ma(src, length, maType)
  150. dev = mult * ta.stdev(src, length)
  151. upper = basis + dev
  152. lower = basis - dev
  153.  
  154.  
  155. if Basis_of_HL=="Bollinger Bands"
  156. highest_price := Log_scale==false ? upper : math.log(upper)
  157. lowest_price := Log_scale==false ? lower : math.log(lower)
  158.  
  159.  
  160.  
  161. //Calculated Fibonacci retracement levels
  162. //Bull
  163. fib0 = highest_price
  164. fib236 = highest_price - (highest_price - lowest_price) * second_line_float
  165. fib382 = highest_price - (highest_price - lowest_price) * third_line_float
  166. fib50 = highest_price - (highest_price - lowest_price) * fourth_line_float
  167. fib618 = highest_price - (highest_price - lowest_price) * fifth_line_float
  168. fib786 = highest_price - (highest_price - lowest_price) * sixth_line_float
  169. fib100 = lowest_price
  170.  
  171.  
  172.  
  173. //Bear
  174. fib100B = highest_price
  175. fib786B = lowest_price - (lowest_price - highest_price) * sixth_line_float
  176. fib618B = lowest_price - (lowest_price - highest_price) * fifth_line_float
  177. fib50B = lowest_price - (lowest_price - highest_price) * fourth_line_float
  178. fib382B = lowest_price - (lowest_price - highest_price) * third_line_float
  179. fib236B = lowest_price - (lowest_price - highest_price) * second_line_float
  180. fib0B = lowest_price
  181.  
  182.  
  183. fx=highest_price
  184. f2=Bias=="Bull" and second_line_bool==true ? fib236
  185. :Bias=="Bear" and sixth_line_bool==true ? fib786B
  186. :na
  187. f3=Bias=="Bull" and third_line_bool==true ? fib382
  188. :Bias=="Bear" and fifth_line_bool==true ? fib618B
  189. :na
  190. f4=Bias=="Bull" and fourth_line_bool==true ? fib50
  191. :Bias=="Bear" and fourth_line_bool==true ? fib50B
  192. :na
  193. f5=Bias=="Bull" and fifth_line_bool==true ? fib618
  194. :Bias=="Bear" and third_line_bool==true ? fib382B
  195. :na
  196. f5b=Bias=="Bull" and sixth_line_bool==true ? fib786
  197. :Bias=="Bear" and second_line_bool==true ? fib236B
  198. :na
  199. fy=lowest_price
  200.  
  201. //Calculations of Fibonacci extension levels
  202. //Bull
  203. ex_fib_1272 = highest_price - (highest_price - lowest_price) * first_extension_float
  204. ex_fib_1618 = highest_price - (highest_price - lowest_price) * second_extension_float
  205. ex_fib_2 = highest_price - (highest_price - lowest_price) * third_extension_float
  206. ex_fib_2414 = highest_price - (highest_price - lowest_price) * fourth_extension_float
  207. ex_fib_2618 = highest_price - (highest_price - lowest_price) * fifth_extension_float
  208. ex_fib_2718 = highest_price - (highest_price - lowest_price) * sixth_extension_float
  209. ex_fib_3141 = highest_price - (highest_price - lowest_price) * seventh_extension_float
  210. ex_fib_3618 = highest_price - (highest_price - lowest_price) * eight_extension_float
  211. ex_fib_4236 = highest_price - (highest_price - lowest_price) * ninth_extension_float
  212.  
  213. //Bear
  214. ex_fib_1272B = lowest_price - (lowest_price - highest_price) * first_extension_float
  215. ex_fib_1618B = lowest_price - (lowest_price - highest_price) * second_extension_float
  216. ex_fib_2B = lowest_price - (lowest_price - highest_price) * third_extension_float
  217. ex_fib_2414B = lowest_price - (lowest_price - highest_price) * fourth_extension_float
  218. ex_fib_2618B = lowest_price - (lowest_price - highest_price) * fifth_extension_float
  219. ex_fib_2718B = lowest_price - (lowest_price - highest_price) * sixth_extension_float
  220. ex_fib_3141B = lowest_price - (lowest_price - highest_price) * seventh_extension_float
  221. ex_fib_3618B = lowest_price - (lowest_price - highest_price) * eight_extension_float
  222. ex_fib_4236B = lowest_price - (lowest_price - highest_price) * ninth_extension_float
  223.  
  224. fex1=Bias=="Bull" and first_extension_bool==true ? ex_fib_1272
  225. :Bias=="Bear" and first_extension_bool==true ? ex_fib_1272B
  226. :na
  227. fex2=Bias=="Bull" and second_extension_bool==true ? ex_fib_1618
  228. :Bias=="Bear" and second_extension_bool==true ? ex_fib_1618B
  229. :na
  230. fex3=Bias=="Bull" and third_extension_bool==true ? ex_fib_2
  231. :Bias=="Bear" and third_extension_bool==true ? ex_fib_2B
  232. :na
  233. fex4=Bias=="Bull" and fourth_extension_bool==true ? ex_fib_2414
  234. :Bias=="Bear" and fourth_extension_bool==true ? ex_fib_2414B
  235. :na
  236. fex5=Bias=="Bull" and fifth_extension_bool==true ? ex_fib_2618
  237. :Bias=="Bear" and fifth_extension_bool==true ? ex_fib_2618B
  238. :na
  239. fex6=Bias=="Bull" and sixth_extension_bool==true ? ex_fib_2718
  240. :Bias=="Bear" and sixth_extension_bool==true ? ex_fib_2718B
  241. :na
  242. fex7=Bias=="Bull" and seventh_extension_bool==true ?ex_fib_3141
  243. :Bias=="Bear" and seventh_extension_bool==true? ex_fib_3141B
  244. :na
  245. fex8=Bias=="Bull" and eight_extension_bool==true ? ex_fib_3618
  246. :Bias=="Bear" and eight_extension_bool==true ? ex_fib_3618B
  247. :na
  248. fex9=Bias=="Bull"and ninth_extension_bool==true ?ex_fib_4236
  249. :Bias=="Bear" and ninth_extension_bool==true ? ex_fib_4236B
  250. :na
  251.  
  252.  
  253. //---------------------------------------------------------------------------------------------------------------------//
  254. //Plot and Fill Fibonacci retracement main levels
  255. //---------------------------------------------------------------------------------------------------------------------//
  256. plot(first_line_bool==true and Bias=="Bull" and Log_scale==true ? math.exp(fx) : seventh_line_bool==true and Bias=="Bear" and Log_scale==true ? math.exp(fx)
  257. :first_line_bool==true and Bias=="Bull" and Log_scale==false ? fx : seventh_line_bool==true and Bias=="Bear" and Log_scale==false ? fx : na
  258. ,color=Background_color_bool=="Single Color" ? Background_color_color
  259. :Bias=="Bull" ? first_line_color
  260. :Bias=="Bear" ? seventh_line_color : na, linewidth=line_width, style=plot.style_line)
  261. plot(Log_scale==true ? math.exp(f2) : f2, color=Background_color_bool=="Single Color" ? Background_color_color
  262. :Bias=="Bull" ? second_line_color
  263. :Bias=="Bear" ? sixth_line_color : na, linewidth=line_width, style=plot.style_line)
  264. plot(Log_scale==true ? math.exp(f3) : f3, color= Background_color_bool=="Single Color" ? Background_color_color
  265. :Bias=="Bull" ? third_line_color
  266. :Bias=="Bear" ? fifth_line_color : na , linewidth=line_width, style=plot.style_line)
  267. plot(Log_scale==true ? math.exp(f4) : f4, color=Background_color_bool=="Single Color" ? Background_color_color : fourth_line_color, linewidth=1, style=plot.style_line)
  268. plot(Log_scale==true ? math.exp(f5) : f5, color=Background_color_bool=="Single Color" ? Background_color_color
  269. :Bias=="Bull" ? fifth_line_color
  270. :Bias=="Bear" ? third_line_color : na , linewidth=line_width, style=plot.style_line)
  271. plot(Log_scale==true ? math.exp(f5b) : f5b,color=Background_color_bool=="Single Color" ? Background_color_color
  272. :Bias=="Bull" ? sixth_line_color
  273. :Bias=="Bear" ? second_line_color : na , linewidth=line_width, style=plot.style_line)
  274. plot(seventh_line_bool== true and Bias=="Bull" and Log_scale==true ? math.exp(fy) : first_line_bool==true and Bias=="Bear" and Log_scale==true ? math.exp(fy)
  275. :seventh_line_bool== true and Bias=="Bull" and Log_scale==false ? fy : first_line_bool==true and Bias=="Bear" and Log_scale==false ? fy : na
  276. ,color=Background_color_bool=="Single Color" ? Background_color_color
  277. :Bias=="Bull" ? seventh_line_color
  278. :Bias=="Bear" ? first_line_color : na, linewidth=line_width, style=plot.style_line)
  279.  
  280.  
  281. var count = 0
  282. count := count + 1
  283.  
  284. var mainfib_float_sorted = array.new<float>()
  285. mainfib_float = array.from(f2,f3,f4,f5,f5b)
  286. for mainfib_sort in mainfib_float
  287. if count >= period_length
  288. array.push(mainfib_float_sorted,mainfib_sort)
  289. array.sort(mainfib_float_sorted, order.ascending)
  290.  
  291.  
  292. fill_line_1A = Bias=="Bull" ? highest_price : lowest_price
  293. fill_line_1B = Bias=="Bull" ? array.max(mainfib_float_sorted) : array.min(mainfib_float_sorted)
  294. fill1A = plot(Log_scale ==true ? math.exp(fill_line_1A) : fill_line_1A,color=color.rgb(255, 255, 255, 100))
  295. fill1B = plot(Log_scale ==true ? math.exp(fill_line_1B) : fill_line_1B,color=color.rgb(255, 255, 255, 100))
  296. fill(fill1A,fill1B, color = Background_color_bool=="Single Color" ? Background_color_color : main_1st_block_fill)
  297. index_of_fill_line_1B = array.binary_search(mainfib_float_sorted,fill_line_1B)
  298. if count >= period_length
  299. array.remove(mainfib_float_sorted,index_of_fill_line_1B)
  300.  
  301.  
  302. fill_line_2 = Bias=="Bull" ? array.max(mainfib_float_sorted) : array.min(mainfib_float_sorted)
  303. fill12 = plot(Log_scale ==true ? math.exp(fill_line_2) : fill_line_2,color=color.rgb(255, 255, 255, 100))
  304. fill(fill1B,fill12, color=Background_color_bool=="Single Color" ? Background_color_color : main_2nd_block_fill)
  305. index_of_fill_line_2 = array.binary_search(mainfib_float_sorted,fill_line_2)
  306. if count >= period_length
  307. array.remove(mainfib_float_sorted,index_of_fill_line_2)
  308.  
  309. fill_line_3 = Bias=="Bull" ? array.max(mainfib_float_sorted) : array.min(mainfib_float_sorted)
  310. fill13 = plot(Log_scale ==true ? math.exp(fill_line_3) : fill_line_3,color=color.rgb(255, 255, 255, 100))
  311. fill(fill12,fill13, color=Background_color_bool=="Single Color" ? Background_color_color : main_3rd_block_fill)
  312. index_of_fill_line_3 = array.binary_search(mainfib_float_sorted,fill_line_3)
  313. if count >= period_length
  314. array.remove(mainfib_float_sorted,index_of_fill_line_3)
  315.  
  316. fill_line_4 = Bias=="Bull" ? array.max(mainfib_float_sorted) : array.min(mainfib_float_sorted)
  317. fill14 = plot(Log_scale ==true ? math.exp(fill_line_4) : fill_line_4,color=color.rgb(255, 255, 255, 100))
  318. fill(fill13,fill14, color=Background_color_bool=="Single Color" ? Background_color_color : main_4th_block_fill)
  319. index_of_fill_line_4 = array.binary_search(mainfib_float_sorted,fill_line_4)
  320. if count >= period_length
  321. array.remove(mainfib_float_sorted,index_of_fill_line_4)
  322.  
  323.  
  324. fill_line_5 = Bias=="Bull" ? array.max(mainfib_float_sorted) : array.min(mainfib_float_sorted)
  325. fill15 = plot(Log_scale ==true ? math.exp(fill_line_5) : fill_line_5,color=color.rgb(255, 255, 255, 100))
  326. fill(fill14,fill15, color=Background_color_bool=="Single Color" ? Background_color_color : main_5th_block_fill)
  327. index_of_fill_line_5 = array.binary_search(mainfib_float_sorted,fill_line_5)
  328. if count >= period_length
  329. array.remove(mainfib_float_sorted,index_of_fill_line_5)
  330.  
  331. mainfib_float_sorted := array.new<float>()
  332.  
  333. fill_line_6 = Bias=="Bull" ? lowest_price : highest_price
  334. fill16 = plot(Log_scale ==true ? math.exp(fill_line_6) : fill_line_6,color=color.rgb(255, 255, 255, 100))
  335. fill(fill15,fill16, color=Background_color_bool=="Single Color" ? Background_color_color : main_6th_block_fill)
  336.  
  337.  
  338. //---------------------------------------------------------------------------------------------------------------------//
  339. //Plot Fibonacci Extensions
  340. //---------------------------------------------------------------------------------------------------------------------//
  341. plot(Log_scale ==true ? math.exp(fex1) : fex1, color= Background_color_bool=="Single Color" ? Background_color_color : first_extension_color, linewidth=line_width, style=plot.style_line)
  342. plot(Log_scale ==true ? math.exp(fex2) :fex2, color= Background_color_bool=="Single Color" ? Background_color_color : second_extension_color, linewidth=line_width, style=plot.style_line)
  343. plot(Log_scale ==true ? math.exp(fex3) :fex3, color=Background_color_bool=="Single Color" ? Background_color_color : third_extension_color, linewidth=line_width, style=plot.style_line)
  344. plot(Log_scale ==true ? math.exp(fex4) :fex4, color=Background_color_bool=="Single Color" ? Background_color_color : fourth_extension_color, linewidth=line_width, style=plot.style_line)
  345. plot(Log_scale ==true ? math.exp(fex5) :fex5, color= Background_color_bool=="Single Color" ? Background_color_color : fifth_extension_color, linewidth=line_width, style=plot.style_line)
  346. plot(Log_scale ==true ? math.exp(fex6) :fex6, color=Background_color_bool=="Single Color" ? Background_color_color :sixth_extension_color, linewidth=line_width, style=plot.style_line)
  347. plot(Log_scale ==true ? math.exp(fex7) :fex7, color=Background_color_bool=="Single Color" ? Background_color_color : seventh_extension_color, linewidth=line_width, style=plot.style_line)
  348. plot(Log_scale ==true ? math.exp(fex8) :fex8, color=Background_color_bool=="Single Color" ? Background_color_color : eight_extension_color, linewidth=line_width, style=plot.style_line)
  349. plot(Log_scale ==true ? math.exp(fex9) :fex9, color=Background_color_bool=="Single Color" ? Background_color_color : ninth_extension_color, linewidth=line_width, style=plot.style_line)
  350.  
  351.  
  352. //Array for Fib extension prices
  353. var Extension_Float_Sorted = array.new<float>()
  354.  
  355. extension_float = array.from(fex1,fex2,fex3,fex4,fex5,fex6,fex7,fex8,fex9)
  356.  
  357. for extension_sort in extension_float
  358. if extension_sort != 0
  359. array.push(Extension_Float_Sorted,extension_sort)
  360.  
  361.  
  362. //Array for Fib extension Fib float
  363. var Fib_Extension_Float_Sorted = array.new<float>()
  364.  
  365. Fib_Extension_Float = array.from(first_extension_bool==true ? first_extension_float : na,
  366. second_extension_bool==true ? second_extension_float : na,
  367. third_extension_bool==true ? third_extension_float : na,
  368. fourth_extension_bool==true ? fourth_extension_float : na,
  369. fifth_extension_bool==true ? fifth_extension_float : na,
  370. sixth_extension_bool==true ? sixth_extension_float : na,
  371. seventh_extension_bool==true ? seventh_extension_float : na,
  372. eight_extension_bool==true ? eight_extension_float : na,
  373. ninth_extension_bool==true ? ninth_extension_float : na)
  374.  
  375. for extension_sort2 in Fib_Extension_Float
  376. if extension_sort2 != 0
  377. array.push(Fib_Extension_Float_Sorted,extension_sort2)
  378.  
  379.  
  380. //Array for Fib extension color
  381. color_array = array.from(first_extension_color,second_extension_color,third_extension_color,fourth_extension_color,fifth_extension_color,sixth_extension_color,seventh_extension_color,eight_extension_color,ninth_extension_color)
  382.  
  383. var color_array_index_sorted = array.new<int>()
  384. for index_get in extension_float
  385. for index_get2 in Extension_Float_Sorted
  386. if index_get==index_get2
  387. array.push(color_array_index_sorted,array.indexof(extension_float,index_get))
  388.  
  389. //---------------------------------------------------------------------------------------------------------------------//
  390. //Labels for Main Fib
  391. //---------------------------------------------------------------------------------------------------------------------//
  392. main_label_function(labels_true,log_true,bool1,bool2,trend,main_label_charpoint,decimal_or_percent,price1,price2,fib_float,fib_float2,price_display,color1,color2) =>
  393. var label label_main_function = na
  394. if labels_true==true and ((bool1== true and trend=="Bull") or (bool2== true and trend=="Bear"))
  395. label_main_function := label.new(main_label_charpoint, text=decimal_or_percent=="Decimal" and trend=="Bull"
  396. ? str.tostring(fib_float)+" "+(price_display==true
  397. ? "("+str.format("{0,number,#.#}", price1)+")" :na):decimal_or_percent=="Percent" and trend=="Bull"
  398. ? str.tostring(fib_float*100)+"%"+" "+(price_display==true
  399. ? "("+str.format("{0,number,#.#}", price1)+")" :na):decimal_or_percent=="Decimal" and trend=="Bear"
  400. ? str.tostring(fib_float2)+" "+(price_display==true
  401. ? "("+str.format("{0,number,#.#}", price2)+")" :na) :decimal_or_percent=="Percent" and trend=="Bear"
  402. ? str.tostring(fib_float2*100)+"%"+" "+(price_display==true
  403. ? "("+str.format("{0,number,#.#}", price2)+")" :na):na, style=label.style_none, textcolor = trend=="Bull" ? color1 : color2)
  404.  
  405.  
  406. label_1_char_point = chart.point.from_index(bar_index+2, Log_scale ==true ? math.exp(highest_price):highest_price)
  407. var label label_1 = na
  408. label_1.delete()
  409. label_1 := main_label_function(Labels_toggle,Log_scale,first_line_bool,seventh_line_bool,Bias,label_1_char_point,Label_int_float,
  410. Log_scale ==true ? math.exp(highest_price)
  411. :highest_price,Log_scale ==true ? math.exp(highest_price):highest_price,first_line_float,seventh_line_float,
  412. Label_prices,Background_color_bool=="Single Color" ? Background_color_color : first_line_color,
  413. Background_color_bool=="Single Color" ? Background_color_color :seventh_line_color)
  414.  
  415. main_label_chart_point(index,Biasx,Log_scale_x,fib1,fib2) =>
  416. main_label_chart_point_x = chart.point.from_index(index, Biasx=="Bull" and Log_scale_x==false ? fib1
  417. :Biasx=="Bull" and Log_scale_x==true ? math.exp(fib1)
  418. :Biasx=="Bear" and Log_scale_x==false ? fib2
  419. :Biasx=="Bear" and Log_scale_x==true ? math.exp(fib2)
  420. :na)
  421.  
  422. label_2_char_point = main_label_chart_point(bar_index+2,Bias,Log_scale,fib236,fib786B)
  423. var label label_2 = na
  424. label_2.delete()
  425. label_2 := main_label_function(Labels_toggle,Log_scale,second_line_bool,sixth_line_bool,Bias,label_2_char_point,Label_int_float,
  426. Bias=="Bull" and Log_scale==false ? fib236 :Bias=="Bull" and Log_scale==true ? math.exp(fib236) :na,
  427. Bias=="Bear" and Log_scale==false ? fib786B :Bias=="Bear" and Log_scale==true ? math.exp(fib786B) :na,
  428. second_line_float,sixth_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :second_line_color,Background_color_bool=="Single Color" ? Background_color_color :sixth_line_color)
  429.  
  430. label_3_char_point = main_label_chart_point(bar_index+2,Bias,Log_scale,fib382,fib618B)
  431. var label label_3 = na
  432. label_3.delete()
  433. label_3 := main_label_function(Labels_toggle,Log_scale,third_line_bool,fifth_line_bool,Bias,label_3_char_point,Label_int_float,Bias=="Bull" and Log_scale==false ? fib382
  434. :Bias=="Bull" and Log_scale==true ? math.exp(fib382) : na,Bias=="Bear" and Log_scale==false ? fib618B
  435. :Bias=="Bear" and Log_scale==true ? math.exp(fib618B) : na,
  436. third_line_float,fifth_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :third_line_color,Background_color_bool=="Single Color" ? Background_color_color :fifth_line_color)
  437.  
  438. label_4_char_point = main_label_chart_point(bar_index+2,Bias,Log_scale,fib50,fib50B)
  439. var label label_4 = na
  440. label_4.delete()
  441. label_4 := main_label_function(Labels_toggle,Log_scale,fourth_line_bool,fourth_line_bool,Bias,label_4_char_point,Label_int_float,
  442. Bias=="Bull" and Log_scale==false ? fib50 :Bias=="Bull" and Log_scale==true ? math.exp(fib50) : na,
  443. Bias=="Bear" and Log_scale==false ? fib50B :Bias=="Bear" and Log_scale==true ? math.exp(fib50B) :na,
  444. fourth_line_float,fourth_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :fourth_line_color,Background_color_bool=="Single Color" ? Background_color_color :fourth_line_color)
  445.  
  446. label_5_char_point = main_label_chart_point(bar_index+2,Bias,Log_scale,fib618,fib382B)
  447. var label label_5 = na
  448. label_5.delete()
  449. label_5 := main_label_function(Labels_toggle,Log_scale,fifth_line_bool,third_line_bool,Bias,label_5_char_point,Label_int_float,
  450. Bias=="Bull" and Log_scale==false ? fib618 :Bias=="Bull" and Log_scale==true ? math.exp(fib618) : na,
  451. Bias=="Bear" and Log_scale==false ? fib382B :Bias=="Bear" and Log_scale==true ? math.exp(fib382B) : na,
  452. fifth_line_float,third_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :fifth_line_color,Background_color_bool=="Single Color" ? Background_color_color :third_line_color)
  453.  
  454. label_6_char_point = main_label_chart_point(bar_index+2,Bias,Log_scale,fib786,fib236B)
  455. var label label_6 = na
  456. label_6.delete()
  457. label_6 := main_label_function(Labels_toggle,Log_scale,sixth_line_bool,second_line_bool,Bias,label_6_char_point,Label_int_float,
  458. Bias=="Bull" and Log_scale==false ? fib786 :Bias=="Bull" and Log_scale==true ? math.exp(fib786) : na,
  459. Bias=="Bear" and Log_scale==false ? fib236B :Bias=="Bear" and Log_scale==true ? math.exp(fib236B) : na,
  460. sixth_line_float,second_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :sixth_line_color,Background_color_bool=="Single Color" ? Background_color_color :second_line_color)
  461.  
  462. label_7_char_point = chart.point.from_index(bar_index+2, Log_scale ==true ? math.exp(lowest_price):lowest_price)
  463. var label label_7 = na
  464. label_7.delete()
  465. label_7 := main_label_function(Labels_toggle,Log_scale,seventh_line_bool,first_line_bool,Bias,label_7_char_point,Label_int_float,
  466. Log_scale ==true ? math.exp(lowest_price):lowest_price,
  467. Log_scale ==true ? math.exp(lowest_price):lowest_price,
  468. seventh_line_float,first_line_float,Label_prices,Background_color_bool=="Single Color" ? Background_color_color :seventh_line_color,Background_color_bool=="Single Color" ? Background_color_color :first_line_color)
  469.  
  470. //---------------------------------------------------------------------------------------------------------------------//
  471. //Plot, Fill and Label function for Fib Extension
  472. //---------------------------------------------------------------------------------------------------------------------//
  473. label_function(label_swtich,trend,label_chartpoint,percent_or_decimal,fib_number,prices_switch,price1,price2,color) =>
  474. var label new_labels = na
  475. if label_swtich==true
  476. new_labels := label.new(label_chartpoint, text=percent_or_decimal=="Decimal" and trend=="Bull" ? str.tostring(fib_number)+" "+(prices_switch==true ? "("+str.format("{0,number,#.#}", price1)+")" :na)
  477. :percent_or_decimal=="Percent" and trend=="Bull" ? str.tostring(fib_number*100)+"%"+" "+(prices_switch==true ? "("+str.format("{0,number,#.#}", price1)+")" :na)
  478. :percent_or_decimal=="Decimal" and trend=="Bear" ? str.tostring(fib_number)+" "+(prices_switch==true ? "("+str.format("{0,number,#.#}", price2)+")" :na)
  479. :percent_or_decimal=="Percent" and trend=="Bear" ? str.tostring(fib_number*100)+"%"+" "+(prices_switch==true ? "("+str.format("{0,number,#.#}", price2)+")" :na):na ,
  480. style=label.style_none, textcolor = color)
  481.  
  482. chart_point_ex_function(index,Biasx,Log_scale_x,Extension_Float_Sorted_x) =>
  483. chart_point_ex_function_x = chart.point.from_index(index, Biasx=="Bull" and Log_scale_x==false ? array.max(Extension_Float_Sorted_x)
  484. :Biasx=="Bull" and Log_scale_x==true ? math.exp(array.max(Extension_Float_Sorted_x))
  485. :Biasx=="Bear" and Log_scale_x==false ? array.min(Extension_Float_Sorted_x)
  486. :Biasx=="Bear" and Log_scale_x==true ? math.exp(array.min(Extension_Float_Sorted_x))
  487. :na)
  488.  
  489. array.sort(Extension_Float_Sorted, order.ascending)
  490. array.sort(Fib_Extension_Float_Sorted, order.ascending)
  491. var color color_for_label = na
  492.  
  493. extension_fill_line_1A = Bias=="Bull" ? lowest_price : highest_price
  494. extension_fill_line_1B = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  495. label_fib_float1 = array.min(Fib_Extension_Float_Sorted)
  496. ex_fill1A = plot(Log_scale ==true ? math.exp(extension_fill_line_1A) :extension_fill_line_1A,color=color.rgb(255, 255, 255, 100))
  497. ex_fill1B = plot(Log_scale ==true ? math.exp(extension_fill_line_1B) :extension_fill_line_1B,color=color.rgb(255, 255, 255, 100))
  498. fill(ex_fill1A,ex_fill1B, color=Background_color_bool=="Single Color" ? Background_color_color : ex_7th_block_fill)
  499. index_of_extension_fill_line_1B = array.binary_search(Extension_Float_Sorted,extension_fill_line_1B)
  500. fib_index_of_label_fib_float1 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float1)
  501. ex_label_1B_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  502.  
  503. var label ex_label_1B = na
  504. ex_label_1B.delete()
  505. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  506. ex_label_1B := label_function(Labels_toggle,Bias,ex_label_1B_char_point,Label_int_float,label_fib_float1,Label_prices
  507. ,Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted))
  508. ,Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted))
  509. ,Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  510. if array.size(Extension_Float_Sorted) > 0
  511. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_1B)
  512. if array.size(Fib_Extension_Float_Sorted) > 0
  513. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float1)
  514. if array.size(color_array_index_sorted) > 0
  515. array.remove(color_array_index_sorted,0)
  516.  
  517. extension_fill_line_2 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  518. label_fib_float2 = array.min(Fib_Extension_Float_Sorted)
  519. ex_fill12 = plot(Log_scale ==true ? math.exp(extension_fill_line_2) :extension_fill_line_2,color=color.rgb(255, 255, 255, 100))
  520. fill(ex_fill1B,ex_fill12, color=Background_color_bool=="Single Color" ? Background_color_color : ex_8th_block_fill)
  521. ex_label_2_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  522. index_of_extension_fill_line_2 = array.binary_search(Extension_Float_Sorted,extension_fill_line_2)
  523. fib_index_of_label_fib_float2 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float2)
  524. var label ex_label_2 = na
  525. ex_label_2.delete()
  526. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  527. ex_label_2 := label_function(Labels_toggle,Bias,ex_label_2_char_point,Label_int_float,label_fib_float2,Label_prices,
  528. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  529. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  530. if array.size(Extension_Float_Sorted) > 0
  531. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_2)
  532. if array.size(Fib_Extension_Float_Sorted) > 0
  533. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float2)
  534. if array.size(color_array_index_sorted) > 0
  535. array.remove(color_array_index_sorted,0)
  536.  
  537. extension_fill_line_3 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  538. label_fib_float3 = array.min(Fib_Extension_Float_Sorted)
  539. ex_fill13 = plot(Log_scale ==true ? math.exp(extension_fill_line_3): extension_fill_line_3,color=color.rgb(255, 255, 255, 100))
  540. fill(ex_fill12,ex_fill13, color=Background_color_bool=="Single Color" ? Background_color_color : ex_9th_block_fill)
  541. ex_label_3_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  542. fib_index_of_label_fib_float3 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float3)
  543. var label ex_label_3 = na
  544. ex_label_3.delete()
  545. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  546. ex_label_3 := label_function(Labels_toggle,Bias,ex_label_3_char_point,Label_int_float,label_fib_float3,Label_prices,
  547. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  548. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  549. index_of_extension_fill_line_3 = array.binary_search(Extension_Float_Sorted,extension_fill_line_3)
  550. if array.size(Extension_Float_Sorted) > 0
  551. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_3)
  552. if array.size(Fib_Extension_Float_Sorted) > 0
  553. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float3)
  554. if array.size(color_array_index_sorted) > 0
  555. array.remove(color_array_index_sorted,0)
  556.  
  557. extension_fill_line_4 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  558. label_fib_float4 = array.min(Fib_Extension_Float_Sorted)
  559. ex_fill14 = plot(Log_scale ==true ? math.exp(extension_fill_line_4):extension_fill_line_4,color=color.rgb(255, 255, 255, 100))
  560. fill(ex_fill13,ex_fill14, color=Background_color_bool=="Single Color" ? Background_color_color : ex_10th_block_fill)
  561. ex_label_4_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  562. fib_index_of_label_fib_float4 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float4)
  563. var label ex_label_4 = na
  564. ex_label_4.delete()
  565. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  566. ex_label_4 := label_function(Labels_toggle,Bias,ex_label_4_char_point,Label_int_float,label_fib_float4,Label_prices,
  567. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  568. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  569. index_of_extension_fill_line_4 = array.binary_search(Extension_Float_Sorted,extension_fill_line_4)
  570. if array.size(Extension_Float_Sorted) > 0
  571. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_4)
  572. if array.size(Fib_Extension_Float_Sorted) > 0
  573. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float4)
  574. if array.size(color_array_index_sorted) > 0
  575. array.remove(color_array_index_sorted,0)
  576.  
  577. extension_fill_line_5 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  578. label_fib_float5 = array.min(Fib_Extension_Float_Sorted)
  579. ex_fill15 = plot(Log_scale ==true ? math.exp(extension_fill_line_5):extension_fill_line_5,color=color.rgb(255, 255, 255, 100))
  580. fill(ex_fill14, ex_fill15, color=Background_color_bool=="Single Color" ? Background_color_color : ex_11th_block_fill)
  581. ex_label_5_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  582. fib_index_of_label_fib_float5 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float5)
  583. var label ex_label_5 = na
  584. ex_label_5.delete()
  585. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  586. ex_label_5 := label_function(Labels_toggle,Bias,ex_label_5_char_point,Label_int_float,label_fib_float5,Label_prices,
  587. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  588. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  589. index_of_extension_fill_line_5 = array.binary_search(Extension_Float_Sorted,extension_fill_line_5)
  590. if array.size(Extension_Float_Sorted) > 0
  591. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_5)
  592. if array.size(Fib_Extension_Float_Sorted) > 0
  593. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float5)
  594. if array.size(color_array_index_sorted) > 0
  595. array.remove(color_array_index_sorted,0)
  596.  
  597. extension_fill_line_6 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  598. label_fib_float6 = array.min(Fib_Extension_Float_Sorted)
  599. ex_fill16 = plot(Log_scale ==true ? math.exp(extension_fill_line_6):extension_fill_line_6,color=color.rgb(255, 255, 255, 100))
  600. fill(ex_fill15, ex_fill16, color=Background_color_bool=="Single Color" ? Background_color_color : ex_12th_block_fill)
  601. ex_label_6_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  602. fib_index_of_label_fib_float6 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float6)
  603. var label ex_label_6 = na
  604. ex_label_6.delete()
  605. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  606. ex_label_6 := label_function(Labels_toggle,Bias,ex_label_6_char_point,Label_int_float,label_fib_float6,Label_prices,
  607. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  608. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  609. index_of_extension_fill_line_6 = array.binary_search(Extension_Float_Sorted,extension_fill_line_6)
  610. if array.size(Extension_Float_Sorted) > 0
  611. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_6)
  612. if array.size(Fib_Extension_Float_Sorted) > 0
  613. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float6)
  614. if array.size(color_array_index_sorted) > 0
  615. array.remove(color_array_index_sorted,0)
  616.  
  617. extension_fill_line_7 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  618. label_fib_float7 = array.min(Fib_Extension_Float_Sorted)
  619. ex_fill17 = plot(Log_scale ==true ? math.exp(extension_fill_line_7):extension_fill_line_7,color=color.rgb(255, 255, 255, 100))
  620. fill(ex_fill16, ex_fill17, color=Background_color_bool=="Single Color" ? Background_color_color : ex_13th_block_fill)
  621. ex_label_7_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  622. fib_index_of_label_fib_float7 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float7)
  623. var label ex_label_7 = na
  624. ex_label_7.delete()
  625. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  626. ex_label_7 := label_function(Labels_toggle,Bias,ex_label_7_char_point,Label_int_float,label_fib_float7,Label_prices,
  627. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  628. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  629. index_of_extension_fill_line_7 = array.binary_search(Extension_Float_Sorted,extension_fill_line_7)
  630. if array.size(Extension_Float_Sorted) > 0
  631. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_7)
  632. if array.size(Fib_Extension_Float_Sorted) > 0
  633. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float7)
  634. if array.size(color_array_index_sorted) > 0
  635. array.remove(color_array_index_sorted,0)
  636.  
  637. extension_fill_line_8 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  638. label_fib_float8 = array.min(Fib_Extension_Float_Sorted)
  639. ex_fill18 = plot(Log_scale ==true ? math.exp(extension_fill_line_8):extension_fill_line_8,color=color.rgb(255, 255, 255, 100))
  640. fill(ex_fill17, ex_fill18, color=Background_color_bool=="Single Color" ? Background_color_color : ex_14th_block_fill)
  641. ex_label_8_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  642. fib_index_of_label_fib_float8 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float8)
  643. var label ex_label_8 = na
  644. ex_label_8.delete()
  645. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  646. ex_label_8 := label_function(Labels_toggle,Bias,ex_label_8_char_point,Label_int_float,label_fib_float8,Label_prices,
  647. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  648. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  649. index_of_extension_fill_line_8 = array.binary_search(Extension_Float_Sorted,extension_fill_line_8)
  650. if array.size(Extension_Float_Sorted) > 0
  651. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_8)
  652. if array.size(Fib_Extension_Float_Sorted) > 0
  653. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float8)
  654. if array.size(color_array_index_sorted) > 0
  655. array.remove(color_array_index_sorted,0)
  656.  
  657. extension_fill_line_9 = Bias=="Bull" ? array.max(Extension_Float_Sorted) : array.min(Extension_Float_Sorted)
  658. label_fib_float9 = array.min(Fib_Extension_Float_Sorted)
  659. ex_fill19 = plot(Log_scale ==true ? math.exp(extension_fill_line_9):extension_fill_line_9,color=color.rgb(255, 255, 255, 100))
  660. fill(ex_fill18, ex_fill19, color=Background_color_bool=="Single Color" ? Background_color_color : ex_15th_block_fill)
  661. ex_label_9_char_point = chart_point_ex_function(bar_index+2,Bias,Log_scale,Extension_Float_Sorted)
  662. fib_index_of_label_fib_float9 = array.binary_search(Fib_Extension_Float_Sorted,label_fib_float9)
  663. var label ex_label_9 = na
  664. ex_label_9.delete()
  665. color_for_label := array.size(color_array_index_sorted) > 0 ? array.get(color_array,array.first(color_array_index_sorted)) : na
  666. ex_label_9 := label_function(Labels_toggle,Bias,ex_label_9_char_point,Label_int_float,label_fib_float9,Label_prices,
  667. Log_scale==false ? array.max(Extension_Float_Sorted) : math.exp(array.max(Extension_Float_Sorted)),
  668. Log_scale==false ? array.min(Extension_Float_Sorted) : math.exp(array.min(Extension_Float_Sorted)),Background_color_bool=="Multi Color" ? color_for_label : Background_color_color)
  669. index_of_extension_fill_line_9 = array.binary_search(Extension_Float_Sorted,extension_fill_line_9)
  670. if array.size(Extension_Float_Sorted) > 0
  671. array.remove(Extension_Float_Sorted,index_of_extension_fill_line_9)
  672. if array.size(Fib_Extension_Float_Sorted) > 0
  673. array.remove(Fib_Extension_Float_Sorted,fib_index_of_label_fib_float9)
  674. if array.size(color_array_index_sorted) > 0
  675. array.remove(color_array_index_sorted,0)
  676.  
  677. Extension_Float_Sorted := array.new<float>()
  678. Fib_Extension_Float_Sorted := array.new<float>()
  679. color_array_index_sorted := array.new<int>()
  680.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement