xmd79

Gann Circle Intraday Levels

Jun 28th, 2022 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.17 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. // © PriceTimeSquare
  3.  
  4. //@version=5
  5. indicator('Gann Circle Intraday Levels', shorttitle='Gann_Circle_Intraday', overlay=true)
  6.  
  7. srLineCount = input.int(title='Number of Gann Levels', minval=1, maxval=24, defval=8)
  8.  
  9. supportLineColor = input.color(color.red, 'Support', group='SETTINGS', inline='COLOR')
  10. resistanceLineColor = input.color(color.lime, 'Resistance', group='SETTINGS', inline='COLOR')
  11. posX_label = input.int(1, title='Pos. Label x-axis', minval=0, group='SETTINGS')
  12.  
  13. // Milliseconds in a day
  14. msec_day = 1000 * 60 * 60 * 24
  15.  
  16. t = time('1440', session.regular)
  17. is_first = na(t[1]) and not na(t) or t[1] < t
  18.  
  19. // Truncates a given number to a certain number of decimals
  20. truncate(number, decimals) =>
  21. factor = math.pow(10, decimals)
  22. int(number * factor) / factor
  23.  
  24. // Decimal approximation
  25. dec(number) =>
  26. var int decLen = 0
  27. if number <= 10
  28. decLen := 5
  29. decLen
  30. else if number <= 999
  31. decLen := 2
  32. decLen
  33. else if number <= 9999
  34. decLen := 1
  35. decLen
  36. else
  37. decLen := 0
  38. decLen
  39.  
  40. // Variable declaration
  41. var line refLine = na
  42.  
  43. var line supportLine = na
  44. var label supportLabel = na
  45.  
  46. var line resistanceLine = na
  47. var label resistanceLabel = na
  48.  
  49. var lineArray = array.new_line()
  50. var labelArray = array.new_label()
  51.  
  52. // Plot only for TODAY
  53. if timenow - time <= msec_day
  54.  
  55. // Opening bar of the day
  56. if is_first
  57.  
  58. // Delete previous lines
  59. lineArraySize = array.size(lineArray)
  60. for i = 0 to lineArraySize by 1
  61. if array.size(lineArray) > 0
  62. ln = array.shift(lineArray)
  63. line.delete(ln)
  64. array.clear(lineArray)
  65.  
  66. // Delete previous labels
  67. labelArraySize = array.size(labelArray)
  68. for i = 0 to labelArraySize by 1
  69. if array.size(labelArray) > 0
  70. lbl = array.shift(labelArray)
  71. label.delete(lbl)
  72. array.clear(labelArray)
  73.  
  74. // Calculate Gann circle intraday levels on confirmation of the opening bar
  75. if barstate.isconfirmed
  76.  
  77. supportLevel = 0.0
  78. resistanceLevel = 0.0
  79. firstSupport = 0.0
  80. firstResistance = 0.0
  81.  
  82. // Decimal length to be displayed
  83. decimalLength = dec(low)
  84.  
  85. // Handle smaller prices
  86. var int div = 1
  87. if low <= 10
  88. div := 10000
  89. div
  90. else
  91. div := 1
  92. div
  93.  
  94. // High and Low of the opening bar
  95. refLine := line.new(x1=bar_index[1], y1=high, x2=bar_index, y2=high, style=line.style_dashed, extend=extend.right, color=color.blue)
  96. array.push(lineArray, refLine)
  97.  
  98. refLine := line.new(x1=bar_index[1], y1=low, x2=bar_index, y2=low, style=line.style_dashed, extend=extend.right, color=color.blue)
  99. array.push(lineArray, refLine)
  100.  
  101. // Calculate Gann Circle Intraday levels
  102. sqrt_low = math.sqrt(low * div)
  103. sqrt_high = math.sqrt(high * div)
  104.  
  105. for i = 1 to srLineCount by 1
  106.  
  107. supportLevel := (sqrt_high - 0.25) * (sqrt_high - 0.25) / div
  108. resistanceLevel := (sqrt_low + 0.25) * (sqrt_low + 0.25) / div
  109.  
  110. // Keep track of the support and resistance levels generated in the first iteration of the loop
  111. if i == 1
  112. firstSupport := supportLevel
  113. firstResistance := resistanceLevel
  114. firstResistance
  115.  
  116. // Plot only those support levels which are lower than the first resistance level
  117. if supportLevel < firstResistance
  118. supportLine := line.new(x1=bar_index[1], y1=supportLevel, x2=bar_index, y2=supportLevel, style=line.style_solid, extend=extend.right, color=supportLineColor)
  119. array.push(lineArray, supportLine)
  120. supportLabel := label.new(time + (time - time[1]) * posX_label, supportLevel, xloc=xloc.bar_time, text='(' + str.tostring(truncate(supportLevel, decimalLength)) + ')', style=label.style_none, textcolor=color.gray)
  121. array.push(labelArray, supportLabel)
  122.  
  123. // Plot only those resistance levels which are higher than the first support level
  124. if resistanceLevel > firstSupport
  125. resistanceLine := line.new(x1=bar_index[1], y1=resistanceLevel, x2=bar_index, y2=resistanceLevel, style=line.style_solid, extend=extend.right, color=resistanceLineColor)
  126. array.push(lineArray, resistanceLine)
  127. resistanceLabel := label.new(time + (time - time[1]) * posX_label, resistanceLevel, xloc=xloc.bar_time, text='(' + str.tostring(truncate(resistanceLevel, decimalLength)) + ')', style=label.style_none, textcolor=color.gray)
  128. array.push(labelArray, resistanceLabel)
  129.  
  130. sqrt_high := math.sqrt(supportLevel * div)
  131. sqrt_low := math.sqrt(resistanceLevel * div)
  132. sqrt_low
  133. // END
  134.  
  135.  
Add Comment
Please, Sign In to add comment