Advertisement
xmd79

Gann fan v3

Feb 17th, 2023
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.64 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, our community Telegram - https://t.me/TGann
  3. // Method of calculating 1/1 line was seen on youtube channel "КриптоBoy-Китобой".
  4. // @version=5
  5. indicator("Gann fan v3", overlay = true)
  6.  
  7. first_date = input.time(timestamp("11.11.2022 00:00 GMT+5"), title = "Beginning of impulse", confirm = true)
  8. second_date = input.time(timestamp("12.11.2022 00:00 GMT+5"), title = "End of impulse", confirm = true)
  9. var color [] line_col = array.from(
  10. input(defval = #ff5252, title = "16/1", inline = "a", group = "===== Line colors ====="), //0
  11. input(defval = #ff52d4, title = "8/1", inline = "a", group = "===== Line colors ====="), //1
  12. input(defval = #ff7a52, title = "4/1", inline = "a", group = "===== Line colors ====="), //2
  13. input(defval = #dbe08c, title = "3/1", inline = "a", group = "===== Line colors ====="), //3
  14. input(defval = #f3ff52, title = "2/1", inline = "a", group = "===== Line colors ====="), //4
  15. input(defval = #ffffff, title = "1/1", inline = "a", group = "===== Line colors ====="), //5
  16. input(defval = #5552ff, title = "1/2", inline = "a1", group = "===== Line colors ====="), //6
  17. input(defval = #52a3ff, title = "1/3", inline = "a1", group = "===== Line colors ====="), //7
  18. input(defval = #52ffe8, title = "1/4", inline = "a1", group = "===== Line colors ====="), //8
  19. input(defval = #52ff8c, title = "1/8", inline = "a1", group = "===== Line colors ====="), //9
  20. input(defval = #83ff52, title = "1/16", inline = "a1", group = "===== Line colors =====")) //10
  21. main_fan = input.bool(true, "Main fan")
  22. from_zero = input.bool(false, "Fan from zero")
  23. from_ATH = input.bool(false, "Fan from ATH")
  24. fan_down = input.bool(false, "Downwards fan from price", inline = "b2")
  25. fan_up = input.bool(false, "Upwards fan from price", inline = "b3")
  26. fan_down_p = input.float(0, "", inline = "b2")
  27. fan_up_p = input.float(0, "", inline = "b3")
  28. show_date_labels = input.bool(false, title = "Left & Right points labels")
  29. lines = array.from(16, 8, 4, 3, 2, 1, 2, 3, 4, 8, 16)
  30. var int first_bar_index = 0
  31. var int second_bar_index = 0
  32. var int highs_bar_index = 0
  33. var int lows_bar_index = 0
  34. var float l_ = 0
  35. var float h_ = 0
  36. var float hh_ = 0 //first bars high price
  37. var float ll_ = 0 //first bars low price
  38. var float p_ = 0
  39. var float k_ = 0
  40. var bool up = false
  41. float auto_ath = ta.max(high)
  42.  
  43. // function that check is bar low or high
  44. is_low(f, b, s)=>
  45. if low[b - f] < low[b - s] and high[b - f] < high[b - s]
  46. magic = true
  47. else
  48. magic = false
  49.  
  50. // time to bar index
  51. if time == first_date
  52. first_bar_index := bar_index
  53. ll_ := low
  54. hh_ := high
  55. if show_date_labels
  56. low_label = label.new(bar_index, low, text = "Left (first) point", color = color.yellow, textcolor = color.rgb(0, 0, 0), style = label.style_label_right)
  57. if time == second_date
  58. second_bar_index := bar_index
  59. if show_date_labels
  60. high_label = label.new(bar_index, high, text = "Right (second) point", color = color.yellow, textcolor = color.black, style = label.style_label_left)
  61.  
  62. //after second selected bar processed, checking first selected bar high or low and...
  63. if second_bar_index > 0 and second_bar_index == bar_index
  64. if is_low(first_bar_index, bar_index, second_bar_index)
  65. l_ := low[bar_index - first_bar_index]
  66. lows_bar_index := first_bar_index
  67. h_ := high[bar_index - second_bar_index]
  68. highs_bar_index := second_bar_index
  69. up := true
  70. else
  71. l_ := low[bar_index - second_bar_index]
  72. lows_bar_index := second_bar_index
  73. h_ := high[bar_index - first_bar_index]
  74. highs_bar_index := first_bar_index
  75. up := false
  76.  
  77. // ...calculating 1/1 line
  78. int count = 0
  79. p_ := h_ - l_
  80. while p_ < 100000
  81. p_ := p_ * 10
  82. count := count + 1
  83. p_ := math.round(p_)
  84. p_ := math.sqrt(p_)
  85. k_ := p_ / math.pow(10, count - 1)
  86.  
  87. // plot lines
  88. for i = 0 to 10
  89. if main_fan == true
  90. line.new(x1 = first_bar_index, y1 = up ? ll_ : hh_, x2 = first_bar_index + 1, y2 = i < 6 ? (up ? ll_ + k_ * array.get(lines, i) : hh_ - k_ * array.get(lines, i)) : (up ? ll_ + k_ / array.get(lines, i) : hh_ - k_ / array.get(lines, i)),
  91. extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
  92. if from_zero == true
  93. line.new(x1 = first_bar_index, y1 = 0, x2 = first_bar_index + 1, y2 = i < 6 ? k_ * array.get(lines, i) : k_ / array.get(lines, i),
  94. extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
  95. if from_ATH == true
  96. line.new(x1 = first_bar_index, y1 = auto_ath, x2 = first_bar_index + 1, y2 = i < 6 ? auto_ath - k_ * array.get(lines, i) : auto_ath - k_ / array.get(lines, i),
  97. extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
  98. if fan_down == true
  99. line.new(x1 = first_bar_index, y1 = fan_down_p, x2 = first_bar_index + 1, y2 = i < 6 ? fan_down_p - k_ * array.get(lines, i) : fan_down_p - k_ / array.get(lines, i),
  100. extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
  101. if fan_up == true
  102. line.new(x1 = first_bar_index, y1 = fan_up_p, x2 = first_bar_index + 1, y2 = i < 6 ? fan_up_p + k_ * array.get(lines, i) : fan_up_p + k_ / array.get(lines, i),
  103. extend = extend.right, color = array.get(line_col, i), style = line.style_solid, width = 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement