Advertisement
xmd79

Dynamic GANN Square Of 9 Bands

Sep 3rd, 2023
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.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. // © Arun_K_Bhaskar
  3.  
  4. //@version=5
  5. indicator(title='Dynamic GANN Square Of 9 Bands', shorttitle='Dynamic GANN', overlay=true, format=format.price)
  6.  
  7. ////////////////////////////////////////////////////////////// Quick Menu
  8.  
  9. gpQ = 'Quick Menu'
  10. // Increment
  11. // 0 / 360 = 0
  12. // 45 / 360 = 0.125
  13. // 90 / 360 = 0.25
  14. // 135 / 360 = 0.375
  15. // 180 / 360 = 0.5
  16. // 225 / 360 = 0.625
  17. // 270 / 360 = 0.75
  18. // 315 / 360 = 0.875
  19. // 360 / 360 = 1
  20.  
  21. ttI = 'Increment Values for Various Markets:\n\n' +
  22.  
  23. 'For Intraday:\n\n' +
  24.  
  25. 'India NSE BSE: 0.125 / 0.0625 / 0.03125\n' +
  26. 'NIFTY: 0.375, 0.25 / 0.125 / 0.0625\n' +
  27. 'BANKNIFTY: 0.375 / 0.25 / 0.125\n' +
  28. 'FINNIFTY: 0.25 / 0.125\n' +
  29. 'MIDCPNIFTY: 0.25 / 0.125\n\n' +
  30.  
  31. 'USDINR: 0.0078125 / 0.00390625\n' +
  32. 'EURUSD: 0.001953125 / 0.0009765625\n\n' +
  33.  
  34. 'BTCUSD: 0.125 / 0.0625\n' +
  35. 'ETHUSD: 0.03125 / 0.015625\n\n' +
  36.  
  37. 'Note: The increment values are subjected to change over time & volatility'
  38.  
  39. i_increment = input.string(defval='0.125', title='Increment ' , options=['0.0009765625',
  40. '0.001953125',
  41. '0.00390625',
  42. '0.0078125',
  43. '0.015625',
  44. '0.03125',
  45. '0.0625',
  46. '0.125',
  47. '0.25',
  48. '0.375',
  49. '0.5',
  50. '0.625',
  51. '0.75',
  52. '0.875',
  53. '1'], tooltip=ttI, inline='01', group=gpQ)
  54.  
  55. increment = i_increment == '0.0009765625' ? 0.0009765625 :
  56. i_increment == '0.001953125' ? 0.001953125 :
  57. i_increment == '0.00390625' ? 0.00390625 :
  58. i_increment == '0.0078125' ? 0.0078125 :
  59. i_increment == '0.015625' ? 0.015625 :
  60. i_increment == '0.03125' ? 0.03125 :
  61. i_increment == '0.0625' ? 0.0625 :
  62. i_increment == '0.125' ? 0.125 :
  63. i_increment == '0.25' ? 0.25 :
  64. i_increment == '0.375' ? 0.375 :
  65. i_increment == '0.5' ? 0.5 :
  66. i_increment == '0.625' ? 0.625 :
  67. i_increment == '0.75' ? 0.75 :
  68. i_increment == '0.875' ? 0.875 : 1
  69.  
  70. ////////////////////////////////////////////////////////////// Moving Average Menu
  71.  
  72. gpMA = 'Moving Average'
  73. i_ma_type = input.string(defval="EMA", title='',
  74. options=["█ EMA Based:", "EMA", "DEMA", "TEMA", "ETMA", "ZLEMA",
  75. "█ SMA Based:", "SMA", "TMA", "SMMA (RMA)",
  76. "█ Volume Based:", "VWMA", "MVWAP",
  77. "█ Others:", "ALMA", "HMA", "LSMA", "WMA"], inline='1', group=gpMA)
  78. i_ma_length = input.int(defval=200, title="", inline='1', group=gpMA)
  79. i_ma_source = input.source(defval=close, title="", inline='1', group=gpMA)
  80. i_ma_timeframe = input.timeframe(defval='', title='', inline='1', group=gpMA)
  81. i_ma_color = input.color(defval=#00FF00, title="", inline='2', group=gpMA)
  82. i_offset = input.int(defval=0, minval=0, title='Offset', inline='2', group=gpMA)
  83.  
  84. ////////////////////////////////////////////////////////////// Support & Resistance Menu
  85.  
  86. gpG = "Support & Resistance"
  87. i_show_r_01 = input.bool(defval=true, title="R01", group=gpG, inline="R1")
  88. i_show_r_02 = input.bool(defval=true, title="R02", group=gpG, inline="R1")
  89. i_show_r_03 = input.bool(defval=true, title="R03", group=gpG, inline="R1")
  90. i_show_r_04 = input.bool(defval=true, title="R04", group=gpG, inline="R1")
  91. i_show_r_05 = input.bool(defval=true, title="R05", group=gpG, inline="R1")
  92. i_r_05_color = input.color(defval=#FF0000, title="", group=gpG, inline="R1")
  93. i_show_r_06 = input.bool(defval=false, title="R06", group=gpG, inline="R2")
  94. i_show_r_07 = input.bool(defval=false, title="R07", group=gpG, inline="R2")
  95. i_show_r_08 = input.bool(defval=false, title="R08", group=gpG, inline="R2")
  96. i_show_r_09 = input.bool(defval=false, title="R09", group=gpG, inline="R2")
  97. i_show_r_10 = input.bool(defval=false, title="R10", group=gpG, inline="R2")
  98. i_r_10_color = input.color(defval=#FF0000, title="", group=gpG, inline="R2")
  99. i_r_color = input.color(defval=#505050, title="", group=gpG, inline="R2")
  100.  
  101. i_show_s_01 = input.bool(defval=true, title="S01", group=gpG, inline="S1")
  102. i_show_s_02 = input.bool(defval=true, title="S02", group=gpG, inline="S1")
  103. i_show_s_03 = input.bool(defval=true, title="S03", group=gpG, inline="S1")
  104. i_show_s_04 = input.bool(defval=true, title="S04", group=gpG, inline="S1")
  105. i_show_s_05 = input.bool(defval=true, title="S05", group=gpG, inline="S1")
  106. i_s_05_color = input.color(defval=#FF0000, title="", group=gpG, inline="S1")
  107. i_show_s_06 = input.bool(defval=false, title="S06", group=gpG, inline="S2")
  108. i_show_s_07 = input.bool(defval=false, title="S07", group=gpG, inline="S2")
  109. i_show_s_08 = input.bool(defval=false, title="S08", group=gpG, inline="S2")
  110. i_show_s_09 = input.bool(defval=false, title="S09", group=gpG, inline="S2")
  111. i_show_s_10 = input.bool(defval=false, title="S10", group=gpG, inline="S2")
  112. i_s_10_color = input.color(defval=#FF0000, title="", group=gpG, inline="S2")
  113. i_s_color = input.color(defval=#505050, title="", group=gpG, inline="S2")
  114.  
  115. ////////////////////////////////////////////////////////////// Get OHLCV
  116.  
  117. get_ohlcv(timeframe, source, prev_value) =>
  118. request.security(symbol=syminfo.tickerid, timeframe=timeframe, expression=source[prev_value], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  119.  
  120. ////////////////////////////////////////////////////////////// Moving Average Calculation
  121.  
  122. moving_average(source, length, ma_type, timeframe, prev_value) =>
  123. float result = na
  124. float source_ohlcv = get_ohlcv(timeframe, source, prev_value)
  125. //Exponential Moving Average
  126. if ma_type == "EMA"
  127. result := ta.ema(source_ohlcv, length)
  128. //Double Exponential Moving Average
  129. if ma_type == "DEMA"
  130. result := 2 * (ta.ema(source_ohlcv, length)) - (ta.ema((ta.ema(source_ohlcv, length)), length))
  131. result
  132. //Triple Exponential Moving Average
  133. if ma_type == "TEMA"
  134. result := 3 * ((ta.ema(source_ohlcv, length)) - (ta.ema((ta.ema(source_ohlcv, length)), length))) + ta.ema((ta.ema((ta.ema(source_ohlcv, length)), length)), length)
  135. result
  136. //Zero Lag Exponential Moving Average
  137. if ma_type == "ZLEMA"
  138. result := ta.ema(source_ohlcv + source_ohlcv - source_ohlcv[(length - 1) / 2], length)
  139. result
  140.  
  141. //Simple Moving Average
  142. if ma_type == "SMA"
  143. result := ta.sma(source_ohlcv, length)
  144. result
  145. //Triangular Simple Moving Average
  146. if ma_type == "TMA"
  147. result := ta.sma(ta.sma(source_ohlcv, length), length)
  148. result
  149. //Smoothed Moving Average (SMMA)
  150. if ma_type == "SMMA (RMA)"
  151. result := ta.rma(source_ohlcv, length)
  152. result
  153. //Weighted Moving Average
  154. if ma_type == "WMA"
  155. result := ta.wma(source_ohlcv, length)
  156. result
  157. //Volume Weighted Moving Average
  158. if ma_type == "VWMA"
  159. result := ta.vwma(source_ohlcv, length)
  160. result
  161. // EMA VWAP
  162. if ma_type == "MVWAP"
  163. result := ta.ema(ta.vwap, length)
  164. result
  165.  
  166. //Hull Moving Average
  167. if ma_type == "HMA"
  168. result := ta.hma(source_ohlcv, length)
  169. result
  170. //Arnaud Legoux Moving Average
  171. if ma_type == "ALMA"
  172. result := ta.alma(source_ohlcv, length, 0.85, 6)
  173. result
  174. //Triangular Exponential Moving Average
  175. if ma_type == "ETMA"
  176. result := ta.ema(ta.ema(source_ohlcv, length), length)
  177. result
  178. //Least Squares Moving Average
  179. if ma_type == "LSMA"
  180. result := ta.linreg(source_ohlcv, length, i_offset)
  181. result
  182. result
  183.  
  184. // Get Moving Average
  185. ma = moving_average(i_ma_source, i_ma_length, i_ma_type, i_ma_timeframe, 0)
  186.  
  187. ////////////////////////////////////////////////////////////// Dynamic Gann Square of 9 Calculation
  188.  
  189. gann_square_of_9(price, multiplier) =>
  190. upper = math.pow((math.sqrt(price) + (multiplier * increment)), 2)
  191. lower = math.pow((math.sqrt(price) - (multiplier * increment)), 2)
  192. [upper, lower]
  193.  
  194. [r_01, s_01] = gann_square_of_9(ma, 1)
  195. [r_02, s_02] = gann_square_of_9(ma, 2)
  196. [r_03, s_03] = gann_square_of_9(ma, 3)
  197. [r_04, s_04] = gann_square_of_9(ma, 4)
  198. [r_05, s_05] = gann_square_of_9(ma, 5)
  199. [r_06, s_06] = gann_square_of_9(ma, 6)
  200. [r_07, s_07] = gann_square_of_9(ma, 7)
  201. [r_08, s_08] = gann_square_of_9(ma, 8)
  202. [r_09, s_09] = gann_square_of_9(ma, 9)
  203. [r_10, s_10] = gann_square_of_9(ma, 10)
  204.  
  205. ////////////////////////////////////////////////////////////// Plot
  206.  
  207. plot(series= ma, title='Moving Average', color=i_ma_color, offset=i_offset)
  208.  
  209. plot(series=i_show_r_01 ? r_01 : na, title='R01', color=i_r_color, offset=i_offset)
  210. plot(series=i_show_r_02 ? r_02 : na, title='R02', color=i_r_color, offset=i_offset)
  211. plot(series=i_show_r_03 ? r_03 : na, title='R03', color=i_r_color, offset=i_offset)
  212. plot(series=i_show_r_04 ? r_04 : na, title='R04', color=i_r_color, offset=i_offset)
  213. plot(series=i_show_r_05 ? r_05 : na, title='R05', color=i_r_05_color, offset=i_offset)
  214. plot(series=i_show_r_06 ? r_06 : na, title='R06', color=i_r_color, offset=i_offset)
  215. plot(series=i_show_r_07 ? r_07 : na, title='R07', color=i_r_color, offset=i_offset)
  216. plot(series=i_show_r_08 ? r_08 : na, title='R08', color=i_r_color, offset=i_offset)
  217. plot(series=i_show_r_09 ? r_09 : na, title='R09', color=i_r_color, offset=i_offset)
  218. plot(series=i_show_r_10 ? r_10 : na, title='R10', color=i_r_10_color, offset=i_offset)
  219.  
  220. plot(series=i_show_s_01 ? s_01 : na, title='S01', color=i_s_color, offset=i_offset)
  221. plot(series=i_show_s_02 ? s_02 : na, title='S02', color=i_s_color, offset=i_offset)
  222. plot(series=i_show_s_03 ? s_03 : na, title='S03', color=i_s_color, offset=i_offset)
  223. plot(series=i_show_s_04 ? s_04 : na, title='S04', color=i_s_color, offset=i_offset)
  224. plot(series=i_show_s_05 ? s_05 : na, title='S05', color=i_s_05_color, offset=i_offset)
  225. plot(series=i_show_s_06 ? s_06 : na, title='S06', color=i_s_color, offset=i_offset)
  226. plot(series=i_show_s_07 ? s_07 : na, title='S07', color=i_s_color, offset=i_offset)
  227. plot(series=i_show_s_08 ? s_08 : na, title='S08', color=i_s_color, offset=i_offset)
  228. plot(series=i_show_s_09 ? s_09 : na, title='S09', color=i_s_color, offset=i_offset)
  229. plot(series=i_show_s_10 ? s_10 : na, title='S10', color=i_s_10_color, offset=i_offset)
  230.  
  231. //////////////////////////////////////////////////////////// CODE END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement