xmd79

Intraday Buy/Sell using Gann Angles - RiTz

Jan 5th, 2023
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.10 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. // © Keanu_ritz
  3.  
  4. //@version=5
  5. indicator("Intraday Buy/Sell using Gann Angles - RiTz", overlay=true)
  6.  
  7. Cal = input.string(title="Calculate Buy/Sell Levels based on :", defval='Todays Open', options=['Todays Open', 'Previous Days High','Previous Days Low','Previous Days Close'])
  8. ShowTable = input(title="Show Buy/Sell Levels in a Table", defval=true , group="Table Settings")
  9. ShowBlvl = input(title="Show Buy Levels on Chart", defval=true, group="Style Settings")
  10. ShowSlvl = input(title="Show Sell Levels on Chart", defval=true, group="Style Settings")
  11. BlvlColor = input.color(color.new(#78fa04,45),"Color for Buy Levels", group="Style Settings")
  12. SlvlColor = input.color(color.new(#fa2f04,45),"Color for Sell Levels", group="Style Settings")
  13. BTxtColor = input.color(color.new(#78fa04,35),"Color for Buy Levels Text", group="Style Settings")
  14. STxtColor = input.color(color.new(#fa2f04,35),"Color for Sell Levels Text", group="Style Settings")
  15. line_style = input.string("Dotted", options=["Dotted", "Dashed" , "Solid"], title="Line Style", group="Style Settings")
  16. label_size = input.string("small", options=["auto", "tiny", "small", "normal", "large", "huge"], title="Label size", group="Style Settings")
  17. l_size = label_size == "auto" ? size.auto : label_size == "tiny" ? size.tiny : label_size == "small" ? size.small : label_size == "normal" ? size.normal : label_size == "large" ? size.large : size.huge
  18. position_labels = input.string("Left", "Labels Position", options=["Left", "Right"], group="Style Settings")
  19. TDO = request.security(syminfo.tickerid, 'D', open)
  20. PDH = request.security(syminfo.tickerid, 'D', high[1])
  21. PDL = request.security(syminfo.tickerid, 'D', low[1])
  22. PDC = request.security(syminfo.tickerid, 'D', close[1])
  23. Do = request.security(syminfo.tickerid, "D", time)
  24. Dc = request.security(syminfo.tickerid, "D", time_close)
  25.  
  26. var lstyle = ""
  27. var l_pos = 0
  28.  
  29. if line_style == "Dotted"
  30. lstyle := line.style_dotted
  31. else if line_style == "Dashed"
  32. lstyle := line.style_dashed
  33. else if line_style == "Solid"
  34. lstyle := line.style_solid
  35.  
  36. if position_labels == "Left"
  37. l_pos := Do
  38. else if position_labels == "Right"
  39. l_pos := Dc
  40.  
  41. float sqCal = 0.00
  42.  
  43. if Cal == 'Todays Open'
  44. sqCal := math.sqrt(TDO)
  45. else if Cal == 'Previous Days High'
  46. sqCal := math.sqrt(PDH)
  47. else if Cal == 'Previous Days Low'
  48. sqCal := math.sqrt(PDL)
  49. else if Cal == 'Previous Days Close'
  50. sqCal := math.sqrt(PDC)
  51.  
  52. Bsl=(sqCal-0.0625)*(sqCal-0.0625)
  53. Bat=(sqCal+0.125)*(sqCal+0.125)
  54. Bt1=(sqCal+0.25)*(sqCal+0.25)
  55. Bt2=(sqCal+0.5)*(sqCal+0.5)
  56. Bt3=(sqCal+0.75)*(sqCal+0.75)
  57. Bt4=(sqCal+1)*(sqCal+1)
  58. Bt5=(sqCal+1.25)*(sqCal+1.25)
  59. Bt6=(sqCal+1.5)*(sqCal+1.5)
  60. Bt7=(sqCal+1.75)*(sqCal+1.75)
  61. Bt8=(sqCal+2)*(sqCal+2)
  62.  
  63. Ssl=(sqCal+0.0625)*(sqCal+0.0625)
  64. Sat=(sqCal-0.125)*(sqCal-0.125)
  65. St1=(sqCal-0.25)*(sqCal-0.25)
  66. St2=(sqCal-0.5)*(sqCal-0.5)
  67. St3=(sqCal-0.75)*(sqCal-0.75)
  68. St4=(sqCal-1)*(sqCal-1)
  69. St5=(sqCal-1.25)*(sqCal-1.25)
  70. St6=(sqCal-1.5)*(sqCal-1.5)
  71. St7=(sqCal-1.75)*(sqCal-1.75)
  72. St8=(sqCal-2)*(sqCal-2)
  73.  
  74.  
  75. if ShowBlvl and timeframe.isintraday
  76. pBsl = line.new(Do, Bsl, Dc, Bsl, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  77. line.delete(pBsl[1])
  78. lpBsl = label.new(l_pos, Bsl, text="SL for Buy Side : " + str.tostring(math.round(Bsl,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  79. label.delete(lpBsl[1])
  80. pBat = line.new(Do, Bat, Dc, Bat, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  81. line.delete(pBat[1])
  82. lpBat = label.new(l_pos, Bat, text="Buy At or Above : " + str.tostring(math.round(Bat,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  83. label.delete(lpBat[1])
  84. pBt1 = line.new(Do, Bt1, Dc, Bt1, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  85. line.delete(pBt1[1])
  86. lpBt1 = label.new(l_pos, Bt1, text="Target 1 : " + str.tostring(math.round(Bt1,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  87. label.delete(lpBt1[1])
  88. pBt2 = line.new(Do, Bt2, Dc, Bt2, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  89. line.delete(pBt2[1])
  90. lpBt2 = label.new(l_pos, Bt2, text="Target 2 : " + str.tostring(math.round(Bt2,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  91. label.delete(lpBt2[1])
  92. pBt3 = line.new(Do, Bt3, Dc, Bt3, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  93. line.delete(pBt3[1])
  94. lpBt3 = label.new(l_pos, Bt3, text="Target 3 : " + str.tostring(math.round(Bt3,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  95. label.delete(lpBt3[1])
  96. pBt4 = line.new(Do, Bt4, Dc, Bt4, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  97. line.delete(pBt4[1])
  98. lpBt4 = label.new(l_pos, Bt4, text="Target 4 : " + str.tostring(math.round(Bt4,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  99. label.delete(lpBt4[1])
  100. pBt5 = line.new(Do, Bt5, Dc, Bt5, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  101. line.delete(pBt5[1])
  102. lpBt5 = label.new(l_pos, Bt5, text="Target 5 : " + str.tostring(math.round(Bt5,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  103. label.delete(lpBt5[1])
  104. pBt6 = line.new(Do, Bt6, Dc, Bt6, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  105. line.delete(pBt6[1])
  106. lpBt6 = label.new(l_pos, Bt6, text="Target 6 : " + str.tostring(math.round(Bt6,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  107. label.delete(lpBt6[1])
  108. pBt7 = line.new(Do, Bt7, Dc, Bt7, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  109. line.delete(pBt7[1])
  110. lpBt7 = label.new(l_pos, Bt7, text="Target 7 : " + str.tostring(math.round(Bt7,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  111. label.delete(lpBt7[1])
  112. pBt8 = line.new(Do, Bt8, Dc, Bt8, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  113. line.delete(pBt8[1])
  114. lpBt8 = label.new(l_pos, Bt8, text="Target 8 : " + str.tostring(math.round(Bt8,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  115. label.delete(lpBt8[1])
  116.  
  117. if ShowSlvl and timeframe.isintraday
  118. pSsl = line.new(Do, Ssl, Dc, Ssl, xloc.bar_time, color=BlvlColor, style=lstyle, width=2)
  119. line.delete(pSsl[1])
  120. lpSsl = label.new(l_pos, Ssl, text="SL for Sell Side : " + str.tostring(math.round(Ssl,2)), xloc=xloc.bar_time, textcolor=BTxtColor, style=label.style_none, size=l_size)
  121. label.delete(lpSsl[1])
  122. pSat = line.new(Do, Sat, Dc, Sat, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  123. line.delete(pSat[1])
  124. lpSat = label.new(l_pos, Sat, text="Sell At or Below : " + str.tostring(math.round(Sat,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  125. label.delete(lpSat[1])
  126. pSt1 = line.new(Do, St1, Dc, St1, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  127. line.delete(pSt1[1])
  128. lpSt1 = label.new(l_pos, St1, text="Target 1 : " + str.tostring(math.round(St1,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  129. label.delete(lpSt1[1])
  130. pSt2 = line.new(Do, St2, Dc, St2, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  131. line.delete(pSt2[1])
  132. lpSt2 = label.new(l_pos, St2, text="Target 2 : " + str.tostring(math.round(St2,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  133. label.delete(lpSt2[1])
  134. pSt3 = line.new(Do, St3, Dc, St3, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  135. line.delete(pSt3[1])
  136. lpSt3 = label.new(l_pos, St3, text="Target 3 : " + str.tostring(math.round(St3,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  137. label.delete(lpSt3[1])
  138. pSt4 = line.new(Do, St4, Dc, St4, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  139. line.delete(pSt4[1])
  140. lpSt4 = label.new(l_pos, St4, text="Target 4 : " + str.tostring(math.round(St4,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  141. label.delete(lpSt4[1])
  142. pSt5 = line.new(Do, St5, Dc, St5, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  143. line.delete(pSt5[1])
  144. lpSt5 = label.new(l_pos, St5, text="Target 5 : " + str.tostring(math.round(St5,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  145. label.delete(lpSt5[1])
  146. pSt6 = line.new(Do, St6, Dc, St6, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  147. line.delete(pSt6[1])
  148. lpSt6 = label.new(l_pos, St6, text="Target 6 : " + str.tostring(math.round(St6,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  149. label.delete(lpSt6[1])
  150. pSt7 = line.new(Do, St7, Dc, St7, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  151. line.delete(pSt7[1])
  152. lpSt7 = label.new(l_pos, St7, text="Target 7 : " + str.tostring(math.round(St7,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  153. label.delete(lpSt7[1])
  154. pSt8 = line.new(Do, St8, Dc, St8, xloc.bar_time, color=SlvlColor, style=lstyle, width=2)
  155. line.delete(pSt8[1])
  156. lpSt8 = label.new(l_pos, St8, text="Target 8 : " + str.tostring(math.round(St8,2)), xloc=xloc.bar_time, textcolor=STxtColor, style=label.style_none, size=l_size)
  157. label.delete(lpSt8[1])
  158.  
  159.  
  160. // ---- Table Settings Start {----//
  161. max = 120 //Maximum Length
  162. min = 10 //Minimum Length
  163. dash_loc = input.session("Top Right","Table Location" ,options=["Top Right","Bottom Right","Top Left","Bottom Left", "Middle Right","Bottom Center"] ,group='Table Settings')
  164.  
  165. text_size = input.session('Normal',"Table Size" ,options=["Tiny","Small","Normal","Large"] ,group='Table Settings')
  166. row_col = color.blue
  167. col_col = color.blue
  168. txt_col = color.white
  169.  
  170.  
  171. // ---- Table Settings End ----}//
  172. //-------------- Table code Start {-------------------//
  173.  
  174. //---- Table Position & Size code start {----//
  175. var table_position = dash_loc == 'Top Left' ? position.top_left :
  176. dash_loc == 'Bottom Left' ? position.bottom_left :
  177. dash_loc == 'Middle Right' ? position.middle_right :
  178. dash_loc == 'Bottom Center' ? position.bottom_center :
  179. dash_loc == 'Top Right' ? position.top_right : position.bottom_right
  180.  
  181. var table_text_size = text_size == 'Tiny' ? size.tiny :
  182. text_size == 'Small' ? size.small :
  183. text_size == 'Normal' ? size.normal : size.large
  184.  
  185. var t = table.new(table_position,14,math.abs(max-min)+2,
  186. frame_color=color.new(#000000,0),
  187. frame_width=1,
  188. border_color=color.new(#000000,0),
  189. border_width=1)
  190. //---- Table Position & Size code end ----}//
  191.  
  192. //---- Table Column & Rows code start {----//
  193. if ShowTable and (barstate.islast) and timeframe.isintraday
  194. //---- Table Main Column Headers code start {----//
  195. table.cell(t,1,0,'Intraday',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  196. table.cell(t,2,0,'Buy/Sell',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  197. table.cell(t,3,0,'Levels',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  198. table.cell(t,4,0,'using',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  199. table.cell(t,5,0,'Gann Angles',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  200. table.cell(t,6,0,'based on',text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  201. table.cell(t,7,0,str.tostring(Cal),text_color=color.new(#339cff,15),text_size=table_text_size,bgcolor=color.new(#339cff,80))
  202. table.cell(t,1,1,str.replace_all(syminfo.tickerid, 'NSE:', ''),text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  203. table.cell(t,2,1,'Entry level',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  204. table.cell(t,3,1,'Stop Loss',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  205. table.cell(t,4,1,'Target 1',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  206. table.cell(t,5,1,'Target 2',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  207. table.cell(t,6,1,'Target 3',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  208. table.cell(t,7,1,'Target 4',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  209. table.cell(t,8,1,'Target 5',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  210. table.cell(t,9,1,'Target 6',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  211. table.cell(t,10,1,'Target 7',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  212. table.cell(t,11,1,'Target 8',text_color=color.new(color.blue,40),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  213.  
  214. //---- Table Main Column Headers code end ----}//
  215.  
  216. //---- Display Buying data code start {----//
  217. table.cell(t,1,2, 'Buying',text_color=color.new(#78fa04,25),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  218. table.cell(t,2,2, str.tostring(Bat, '#.##'),text_color=color.new(#78fa04,25),text_size=table_text_size, bgcolor=color.new(close >= Bat and close < Bt1 ? #000000 : #78fa04,85))
  219. table.cell(t,3,2, str.tostring(Bsl, '#.##'),text_color=color.new(#fa2f04,35),text_size=table_text_size, bgcolor=color.new(close >= Bsl and close < Bat ? #000000 : #fa2f04,85))
  220. table.cell(t,4,2, str.tostring(Bt1, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt1 and close < Bt2 ? #000000 : #78fa04,85))
  221. table.cell(t,5,2, str.tostring(Bt2, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt2 and close < Bt3 ? #000000 : #78fa04,85))
  222. table.cell(t,6,2, str.tostring(Bt3, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt3 and close < Bt4 ? #000000 : #78fa04,85))
  223. table.cell(t,7,2, str.tostring(Bt4, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt4 and close < Bt5 ? #000000 : #78fa04,85))
  224. table.cell(t,8,2, str.tostring(Bt5, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt5 and close < Bt6 ? #000000 : #78fa04,85))
  225. table.cell(t,9,2, str.tostring(Bt6, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt6 and close < Bt7 ? #000000 : #78fa04,85))
  226. table.cell(t,10,2, str.tostring(Bt7, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt7 and close < Bt8 ? #000000 : #78fa04,85))
  227. table.cell(t,11,2, str.tostring(Bt8, '#.##'),text_color=color.new(#78fa04,45),text_size=table_text_size, bgcolor=color.new(close >= Bt8 ? #000000 : #78fa04,85))
  228. //---- Display Buying data code end ----}//
  229.  
  230. //---- Display Selling data code start {----//
  231. table.cell(t,1,3, 'Selling',text_color=color.new(#fa2f04,25),text_size=table_text_size,bgcolor=color.new(color.blue,80))
  232. table.cell(t,2,3, str.tostring(Sat, '#.##'),text_color=color.new(#fa2f04,25),text_size=table_text_size, bgcolor=color.new(close <= Sat and close > St1 ? #000000 : #fa2f04,85))
  233. table.cell(t,3,3, str.tostring(Ssl, '#.##'),text_color=color.new(#78fa04,35),text_size=table_text_size, bgcolor=color.new(close <= Ssl and close > Sat ? #000000 : #78fa04,85))
  234. table.cell(t,4,3, str.tostring(St1, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St1 and close > St2 ? #000000 : #fa2f04,85))
  235. table.cell(t,5,3, str.tostring(St2, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St2 and close > St3 ? #000000 : #fa2f04,85))
  236. table.cell(t,6,3, str.tostring(St3, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St3 and close > St4 ? #000000 : #fa2f04,85))
  237. table.cell(t,7,3, str.tostring(St4, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St4 and close > St5 ? #000000 : #fa2f04,85))
  238. table.cell(t,8,3, str.tostring(St5, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St5 and close > St6 ? #000000: #fa2f04,85))
  239. table.cell(t,9,3, str.tostring(St6, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St6 and close > St7 ? #000000 : #fa2f04,85))
  240. table.cell(t,10,3, str.tostring(St7, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St7 and close > St8 ? #000000 : #fa2f04,85))
  241. table.cell(t,11,3, str.tostring(St8, '#.##'),text_color=color.new(#fa2f04,45),text_size=table_text_size, bgcolor=color.new(close <= St8 ? #000000 : #fa2f04,85))
  242. //---- Display Selling data code end ----}//
  243.  
  244. //---- Table Column & Rows code end ----}//
  245.  
  246. //-------------- Table code end -------------------}//
Add Comment
Please, Sign In to add comment