Advertisement
xmd79

Gann fan by nemo

Jan 4th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.40 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. // © nemo_tman
  3. // Method of calculating 1/1 line and getting bar index for labels was taken from © LonesomeTheBlue`s "Gann Fan" indicator
  4.  
  5. //@version=5
  6. indicator("Gann fan by nemo", overlay = true)
  7.  
  8. first_date = input.time(timestamp("11.11.2022 00:00 GMT+5"), confirm = true)
  9. second_date = input.time(timestamp("12.11.2022 00:00 GMT+5"), confirm = true)
  10. downLineColor = input.color(color.new(color.orange, 30))
  11. upLineColor = input.color(color.new(color.green, 30))
  12. label_pos = input.int(50, "Label position", 10, 200)
  13. show_date_labels = input.bool(false, title = "Left & Right points labels")
  14. var int first_bar_index = 0
  15. var int second_bar_index = 0
  16. var int highs_bar_index = 0
  17. var int lows_bar_index = 0
  18. var float l_ = 0
  19. var float h_ = 0
  20. var divs = array.from(2.0, 3.0, 4.0, 8.0)
  21. var line downL16to1 = na
  22.  
  23. // for horisontal labels (16/1 - 2/1) positioning
  24. line_get_bar_index(gline, x_bar_index, yloc, mult)=>
  25. ystart = line.get_price(gline, x_bar_index)
  26. slope = math.abs(ystart - line.get_price(gline, x_bar_index + 1))
  27. int ret = x_bar_index + math.floor((yloc - ystart) / slope) * mult
  28.  
  29. //
  30. is_low(f, b, s)=>
  31. if low[b - f] < low[b - s] and high[b - f] < high[b - s]
  32. bool isLow = true
  33.  
  34. // time to bar index
  35. if time == first_date
  36. first_bar_index := bar_index
  37. if show_date_labels
  38. low_label = label.new(bar_index, low, text = "Left point", color = color.yellow, textcolor = color.rgb(0, 0, 0), style = label.style_label_right)
  39. if time == second_date
  40. second_bar_index := bar_index
  41. if show_date_labels
  42. high_label = label.new(bar_index, high, text = "Right point", color = color.yellow, textcolor = color.black, style = label.style_label_left)
  43.  
  44. //after second selected bar processed (we not need more) - checking first selected bar high or low and...
  45. //после того как дошли и обработали бар второй даты/точки (нам дальше не надо), - определяем первая дата хай или лой и...
  46. if second_bar_index > 0 and second_bar_index == bar_index
  47. if is_low(first_bar_index, bar_index, second_bar_index)
  48. l_ := low[bar_index - first_bar_index]
  49. lows_bar_index := first_bar_index
  50. h_ := high[bar_index - second_bar_index]
  51. highs_bar_index := second_bar_index
  52. else
  53. l_ := low[bar_index - second_bar_index]
  54. lows_bar_index := second_bar_index
  55. h_ := high[bar_index - first_bar_index]
  56. highs_bar_index := first_bar_index
  57.  
  58. // ...calculating 1/1 line
  59. // ...делаем расчет линии 1/1
  60. float perc = (h_ - l_) /82
  61. float hh = h_ + perc * 10
  62. float ll = l_ - perc * 8
  63. float middle = (hh - ll) / 131.0
  64.  
  65.  
  66. // uplines from lows
  67. upLine16to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 16, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  68. upLine8to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 8, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  69. upLine4to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 4, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  70. upLine3to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 3, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  71. upLine2to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle * 2, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  72. upLine1to1 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  73. upLine1to2 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 2, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  74. upLine1to3 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 3, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  75. upLine1to4 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 4, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  76. upLine1to8 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 8, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  77. upLine1to16 = line.new(x1 = lows_bar_index, y1 = l_, x2 = lows_bar_index + 1, y2 = l_ + middle / 16, extend = extend.right, color = upLineColor, style = line.style_solid, width = 1)
  78.  
  79. label.new(x = line_get_bar_index(upLine16to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "16/1", textcolor = upLineColor, style = label.style_none)
  80. label.new(x = line_get_bar_index(upLine8to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "8/1", textcolor = upLineColor, style = label.style_none)
  81. label.new(x = line_get_bar_index(upLine4to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "4/1", textcolor = upLineColor, style = label.style_none)
  82. label.new(x = line_get_bar_index(upLine3to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "3/1", textcolor = upLineColor, style = label.style_none)
  83. label.new(x = line_get_bar_index(upLine2to1, lows_bar_index, line.get_price(upLine1to1, lows_bar_index + label_pos), 1), y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "2/1", textcolor = upLineColor, style = label.style_none)
  84. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to1, lows_bar_index + label_pos), text = "1/1", textcolor = upLineColor, style = label.style_none)
  85. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to2, lows_bar_index + label_pos), text = "1/2", textcolor = upLineColor, style = label.style_none)
  86. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to3, lows_bar_index + label_pos), text = "1/3", textcolor = upLineColor, style = label.style_none)
  87. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to4, lows_bar_index + label_pos), text = "1/4", textcolor = upLineColor, style = label.style_none)
  88. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to8, lows_bar_index + label_pos), text = "1/8", textcolor = upLineColor, style = label.style_none)
  89. label.new(x = lows_bar_index + label_pos, y = line.get_price(upLine1to16, lows_bar_index + label_pos), text = "1/16", textcolor = upLineColor, style = label.style_none)
  90.  
  91. // downlines from highs
  92. downL16to1 := line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 16, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  93. downL8to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 8, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  94. downL4to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 4, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  95. downL3to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 3, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  96. downL2to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle * 2, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  97. downL1to1 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  98. downL1to2 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 2, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  99. downL1to3 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 3, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  100. downL1to4 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 4, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  101. downL1to8 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 8, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  102. downL1to16 = line.new(x1 = highs_bar_index, y1 = h_, x2 = highs_bar_index + 1, y2 = h_ - middle / 16, extend = extend.right, color = downLineColor, style = line.style_solid, width = 1)
  103.  
  104. label.new(x = line_get_bar_index(downL16to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "16/1", textcolor = downLineColor, style = label.style_none)
  105. label.new(x = line_get_bar_index(downL8to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "8/1", textcolor = downLineColor, style = label.style_none)
  106. label.new(x = line_get_bar_index(downL4to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "4/1", textcolor = downLineColor, style = label.style_none)
  107. label.new(x = line_get_bar_index(downL3to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "3/1", textcolor = downLineColor, style = label.style_none)
  108. label.new(x = line_get_bar_index(downL2to1, highs_bar_index, line.get_price(downL1to1, highs_bar_index + label_pos), -1), y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "2/1", textcolor = downLineColor, style = label.style_none)
  109. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to1, highs_bar_index + label_pos), text = "1/1", textcolor = downLineColor, style = label.style_none)
  110. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to2, highs_bar_index + label_pos), text = "1/2", textcolor = downLineColor, style = label.style_none)
  111. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to3, highs_bar_index + label_pos), text = "1/3", textcolor = downLineColor, style = label.style_none)
  112. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to4, highs_bar_index + label_pos), text = "1/4", textcolor = downLineColor, style = label.style_none)
  113. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to8, highs_bar_index + label_pos), text = "1/8", textcolor = downLineColor, style = label.style_none)
  114. label.new(x = highs_bar_index + label_pos, y = line.get_price(downL1to16, highs_bar_index + label_pos), text = "1/16", textcolor = downLineColor, style = label.style_none)
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement