Advertisement
xmd79

Gann Square of 9

Feb 12th, 2023
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 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. // © layartrader
  3.  
  4. //@version=5
  5. indicator('Gann Square of 9', overlay=true)
  6. RedGan = input(title='On/Off Red line', defval=true)
  7. GreenGan = input(title='On/Off Green line', defval=true)
  8. labelOn = input(title='On/Off Label ', defval=true)
  9. LabelColor = input(title='Label color', defval=color.black)
  10. Extend = input(title='Extend line', defval=true)
  11. PriceLevel = input.int(title='Price Level', defval=3, options=[3, 5])
  12.  
  13.  
  14. var label rl1 = na
  15. var label rl2 = na
  16. var label sl1 = na
  17. var label bl1 = na
  18. var label bl2 = na
  19. label.delete(rl1)
  20. label.delete(rl2)
  21. label.delete(sl1)
  22. label.delete(bl1)
  23. label.delete(bl2)
  24.  
  25. drawLine(resistance, start, end, extend, linecolor) =>
  26. gannLine = line.new(x1=start, y1=resistance, x2=end, y2=resistance)
  27. line.set_color(gannLine, linecolor)
  28. if extend
  29. line.set_extend(id=gannLine, extend=extend.left)
  30. gannLine
  31.  
  32. drawLabel(x, y, text_1) =>
  33. GannLabel = label.new(x, y, text_1, xloc=xloc.bar_time, style=label.style_none)
  34. GannLabel
  35.  
  36. max = 20
  37. rangeMin = 0
  38. var GannNum = array.new_float(0)
  39. dt = time - time[1]
  40. labelPosition = time + 3 * dt
  41.  
  42. if barstate.islast
  43. for min = rangeMin to max by 1
  44. for i = 0 to 3 by 1
  45. gNum = 0
  46. if min == rangeMin and i == 0
  47. gNum := min + min + 2
  48. gNum
  49. else if min > rangeMin and i == 0
  50. gNum := math.round(array.get(GannNum, array.size(GannNum) - 1)) + min + 1 + min
  51. gNum
  52. else
  53. gNum := math.round(array.get(GannNum, array.size(GannNum) - 1)) + min + 2 + min
  54. gNum
  55. array.push(GannNum, gNum)
  56.  
  57. maxItem = array.size(GannNum) - 1
  58. next = 0
  59. denomenator = 0.0
  60. if close[0] >= 10000
  61. denomenator := 0.01
  62. denomenator
  63. else if close[0] >= 1000
  64. denomenator := 0.1
  65. denomenator
  66. else if close[0] >= 100
  67. denomenator := 1
  68. denomenator
  69. else if close[0] >= 10
  70. denomenator := 10
  71. denomenator
  72. else if close[0] >= 0.05
  73. denomenator := 100
  74. denomenator
  75. else
  76. denomenator := 1000
  77. denomenator
  78.  
  79. price = close[0] * denomenator
  80. resistance = 0.0
  81. support = 0.0
  82. greenGannPrice1 = 0.0
  83. GannPos = 0
  84. for i = 0 to array.size(GannNum) - 1 by 1
  85. if i == maxItem
  86. next := i
  87. next
  88. else
  89. next := i + 1
  90. next
  91.  
  92. if array.get(GannNum, i) <= price and array.get(GannNum, next) > price
  93. resistance := array.get(GannNum, next) / denomenator
  94. support := array.get(GannNum, i) / denomenator
  95. greenGannPrice1 := (support + resistance) / 2
  96. GannPos := i
  97. break
  98.  
  99.  
  100. // label.new(bar_index, 0, "\nArrayWork = " + tostring(text), size = size.small)
  101. //Print lines
  102.  
  103. startLine = bar_index[0]
  104. endLine = bar_index[10]
  105. GannWeightPosition = close[0] >= greenGannPrice1 ? 2 : -1
  106.  
  107. if RedGan
  108. resistance1 = drawLine(resistance, startLine, endLine, Extend, color.red)
  109. support1 = drawLine(support, startLine, endLine, Extend, color.red)
  110. if labelOn
  111. rl1 := drawLabel(labelPosition, resistance, 'Sell 1 = ' + str.tostring(resistance))
  112. label.set_textcolor(rl1, LabelColor)
  113. sl1 := drawLabel(labelPosition, support, 'Buy 1 = ' + str.tostring(support))
  114. label.set_textcolor(sl1, LabelColor)
  115. if PriceLevel == 5
  116. resistancePrice2 = array.get(GannNum, GannPos + GannWeightPosition) / denomenator
  117. resistance2 = drawLine(resistancePrice2, startLine, endLine, Extend, color.red)
  118. if labelOn
  119. resistanceText2 = GannWeightPosition > 0 ? 'Buy 2 = ' : 'Sell 2 = '
  120. rl2 := drawLabel(labelPosition, resistancePrice2, resistanceText2 + str.tostring(resistancePrice2))
  121. label.set_textcolor(rl2, LabelColor)
  122.  
  123. if GreenGan
  124. greenGann1 = drawLine(greenGannPrice1, startLine, endLine, Extend, color.green)
  125. if labelOn
  126. GreenText1 = close[0] >= greenGannPrice1 ? 'Buy 1 = ' : 'Sell 1 = '
  127. bl1 := drawLabel(labelPosition, greenGannPrice1, GreenText1 + str.tostring(greenGannPrice1))
  128. label.set_textcolor(bl1, LabelColor)
  129. if PriceLevel == 5
  130. GreenGannPrice2 = GannWeightPosition > 0 ? (array.get(GannNum, GannPos + 1) + array.get(GannNum, GannPos + 2)) / 2 : (array.get(GannNum, GannPos - 1) + array.get(GannNum, GannPos)) / 2
  131. GreenGannPrice2 /= denomenator
  132. greenGann2 = drawLine(GreenGannPrice2, startLine, endLine, Extend, color.green)
  133. if labelOn
  134. GreenText2 = GannWeightPosition > 0 ? 'Sell 1 = ' : 'Buy 1 = '
  135. bl2 := drawLabel(labelPosition, GreenGannPrice2, GreenText2 + str.tostring(GreenGannPrice2))
  136. label.set_textcolor(bl2, LabelColor)
  137.  
  138.  
  139.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement