Advertisement
Guest User

[TT] Pivot Boss

a guest
Mar 28th, 2023
1,887
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 43.87 KB | Source Code | 0 0
  1. //@TeamTaurus Pivots are taken from Tradingview Default app and modified the calculation to my own ....
  2.  
  3. //@version=5
  4. indicator('[TT] Pivot]', 'ॐ', overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=5000)
  5. AUTO = 'Auto'
  6. HOURLY = 'Hourly'
  7. DAILY = 'Daily'
  8. WEEKLY = 'Weekly'
  9. MONTHLY = 'Monthly'
  10. QUARTERLY = 'Quarterly'
  11. YEARLY = 'Yearly'
  12. BIYEARLY = 'Biyearly'
  13. TRIYEARLY = 'Triyearly'
  14. QUINQUENNIAL = 'Quinquennial'
  15.  
  16.  
  17. FIBONACCI = 'Fibonacci'
  18. CAMARILLA = 'Camarilla'
  19. DEMARK = 'OFF'
  20.  
  21.  
  22. kind = input.string(title='Type', defval='Camarilla', options=[DEMARK, FIBONACCI, CAMARILLA], inline='Pi', group='Pivots')
  23. pivot_time_frame = input.string(title='', defval=DAILY, options=[AUTO, HOURLY, DAILY, WEEKLY, MONTHLY, QUARTERLY, YEARLY, BIYEARLY, TRIYEARLY, QUINQUENNIAL], inline='Pi', group='Pivots')
  24. look_back = input.int(title='', defval=1, minval=1, maxval=5000, inline='Pi', group='Pivots', tooltip='No Of previous Levels')
  25. is_daily_based = input.bool(title='Use Daily-based Values', defval=true, tooltip='When this option is unchecked, Pivot Points will use intraday data while calculating on intraday charts. If Extended Hours are displayed on the chart, they will be taken into account during the pivot level calculation. If intraday OHLC values are different from daily-based values (normal for stocks), the pivot levels will also differ.')
  26.  
  27. show_labels = false //input.bool(title="Show Labels", type=input.bool, defval=false, inline = "labels")
  28. position_labels = input.string('Left', '', options=['Left', 'Right'], inline='labels')
  29.  
  30. swing = input.bool(defval=false, title='Swing    ', inline='Swing', group='Settings ॐ', tooltip='Turn On Swing Hi/Lo') //
  31. prd = input.int(defval=10, title='   ', inline='Swing', group='Settings ॐ')
  32. ColorSelector(c_) =>
  33. c_ == 'aqua' ? color.aqua : c_ == 'black' ? color.black : c_ == 'blue' ? color.blue : c_ == 'fuchsia' ? color.fuchsia : c_ == 'gray' ? color.gray : c_ == 'green' ? color.green : c_ == 'lime' ? color.lime : c_ == 'maroon' ? color.maroon : c_ == 'navy' ? color.navy : c_ == 'olive' ? color.olive : c_ == 'orange' ? color.orange : c_ == 'purple' ? color.purple : c_ == 'red' ? color.red : c_ == 'silver' ? color.silver : c_ == 'teal' ? color.teal : c_ == 'white' ? color.white : c_ == 'yellow' ? color.yellow : color.black
  34.  
  35. Hi_color = input.string(title='HH', defval='orange', options=['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple', 'red', 'silver', 'teal', 'white', 'yellow'],inline='Swing',group='Settings ॐ')
  36. Lo_color = input.string(title='LL', defval='black', options=['aqua', 'black', 'blue', 'fuchsia', 'gray', 'green', 'lime', 'maroon', 'navy', 'olive', 'orange', 'purple', 'red', 'silver', 'teal', 'white', 'yellow'],inline='Swing',group='Settings ॐ')
  37. showlast = input.bool(title='Show Only Last Period', defval=true, group='Settings ॐ', tooltip='Shows only Today levels bar by bar')
  38. showlabels = input.bool(title='Show Labels', defval=true, group='Settings ॐ', tooltip='Shows labels on plotted pivots')
  39. ltcol = input.color(color.black,"Target Color",inline='labels')
  40. lbcol = input.color(color.yellow,"Breakout/down Color",inline='labels')
  41. lstyle2 = input.string(title='CPR Style', options=['Solid', 'Circles', 'Cross'], defval='Solid', group='Style', tooltip='Change Line Style for CPR')
  42. cmidon = input.bool(defval=false, title='Cam Mid   ', group='Settings ॐ', tooltip='Turn Camarilla Mid')
  43. cprturnon = input.bool(title='Turn On CPR', defval=false, group='Settings ॐ', tooltip='Turn CPR on')
  44. JP = input.bool(title='Just Pivot', defval=false, group='Settings ॐ', tooltip='Show Only Pivot of the day')
  45. PDHL = input.bool(false, 'Prev HiLo   ', inline='Settings ॐ', group='Settings ॐ')
  46. PColor = input.color(color.orange, '', inline='Settings ॐ', group='Settings ॐ')
  47. Pres = input.timeframe(defval='D', inline='Settings ॐ', group='Settings ॐ')
  48. lvl = input.int(1, title='', inline='Settings ॐ', group='Settings ॐ')
  49. vwaplot = input.bool(false, title='VWAP', inline='vwap', group='Settings ॐ', tooltip='Turn on Vwap')
  50. emaplot = input.bool(false, title='EMA on   ', inline='Settings ॐ', group='Settings ॐ', tooltip='Turns On 3 Ema\'s On Chart, Levels can be Edited')
  51. choice = input.string(title='', defval='EMA', options=['EMA', 'SMA'], inline='Settings ॐ', group='Settings ॐ', tooltip='Select Either EMA or SMA from dropdown menu')
  52. MAa = input.int(9, title='EMA', inline='EMA', minval=1, maxval=500, group='Settings ॐ')
  53. MAb = input.int(27, title=' ', inline='EMA', minval=1, maxval=500, group='Settings ॐ')
  54. MAc = input.int(111, title=' ', inline='EMA', minval=1, maxval=500, group='Settings ॐ')
  55. lw = input.int(1, title='Width', minval=1, maxval=3, inline='EMA', group='Settings ॐ')
  56. HammerInput = input.bool(true, 'Hammer', inline='ham', group='Price Action')
  57. HangingManInput = input.bool(true, 'Hanging Man', group='Price Action')
  58. InvertedHammerInput = input.bool(true, 'Inverted Hammer', inline='ham', group='Price Action')
  59.  
  60. vsr = input.bool(false, title='Show Volume Based S&R', group='Settings ॐ', tooltip='Shows Volume Based Support and Resistance on Stocks and Futures')
  61. ATRTsl = input.bool(false, 'Trailing SL', inline='atr', group='Settings ॐ', tooltip='Trailing SL')
  62.  
  63. //Pivot Settings
  64. var DEF_COLOR = #FB8C00
  65. var S3_COLOR = #000000
  66. var S4_COLOR = #ff9800
  67. var S5_COLOR = #ff0000
  68. var arr_time = array.new_int()
  69. var p = array.new_float()
  70. p_show = input.bool(false, 'P‏ ‏ ‏ ‏ ‏ ‏ ‏ ‏', inline='P')
  71. p_color = input.color(DEF_COLOR, '', inline='P')
  72.  
  73. var r1 = array.new_float()
  74. var s1 = array.new_float()
  75. s1r1_show = input.bool(false, 'S1/R1', inline='S1/R1')
  76. s1r1_color = input.color(DEF_COLOR, '', inline='S1/R1')
  77.  
  78. var r2 = array.new_float()
  79. var s2 = array.new_float()
  80. s2r2_show = input.bool(true, 'S2/R2', inline='S2/R2')
  81. s2r2_color = input.color(S3_COLOR, '', inline='S2/R2')
  82.  
  83. var r3 = array.new_float()
  84. var s3 = array.new_float()
  85. s3r3_show = input.bool(true, 'S3/R3', inline='S3/R3')
  86. s3r3_color = input.color(S4_COLOR, '', inline='S3/R3')
  87.  
  88. var r4 = array.new_float()
  89. var s4 = array.new_float()
  90. s4r4_show = input.bool(true, 'S4/R4', inline='S4/R4')
  91. s4r4_color = input.color(S5_COLOR, '', inline='S4/R4')
  92.  
  93. var r5 = array.new_float()
  94. var s5 = array.new_float()
  95. s5r5_show = input.bool(true, 'S5/R5', inline='S5/R5')
  96. s5r5_color = input.color(S5_COLOR, '', inline='S5/R5')
  97.  
  98. pivotX_open = float(na)
  99. pivotX_open := nz(pivotX_open[1], open)
  100. pivotX_high = float(na)
  101. pivotX_high := nz(pivotX_high[1], high)
  102. pivotX_low = float(na)
  103. pivotX_low := nz(pivotX_low[1], low)
  104. pivotX_prev_open = float(na)
  105. pivotX_prev_open := nz(pivotX_prev_open[1])
  106. pivotX_prev_high = float(na)
  107. pivotX_prev_high := nz(pivotX_prev_high[1])
  108. pivotX_prev_low = float(na)
  109. pivotX_prev_low := nz(pivotX_prev_low[1])
  110. pivotX_prev_close = float(na)
  111. pivotX_prev_close := nz(pivotX_prev_close[1])
  112.  
  113. get_pivot_resolution() =>
  114. resolution = 'M'
  115. if pivot_time_frame == AUTO
  116. if timeframe.isintraday
  117. resolution := timeframe.multiplier <= 15 ? 'D' : 'W'
  118. resolution
  119. else if timeframe.isweekly or timeframe.ismonthly
  120. resolution := '12M'
  121. resolution
  122. else if pivot_time_frame == HOURLY
  123. resolution := '240'
  124. resolution
  125. else if pivot_time_frame == DAILY
  126. resolution := 'D'
  127. resolution
  128. else if pivot_time_frame == WEEKLY
  129. resolution := 'W'
  130. resolution
  131. else if pivot_time_frame == MONTHLY
  132. resolution := 'M'
  133. resolution
  134. else if pivot_time_frame == QUARTERLY
  135. resolution := '3M'
  136. resolution
  137. else if pivot_time_frame == YEARLY or pivot_time_frame == BIYEARLY or pivot_time_frame == TRIYEARLY or pivot_time_frame == QUINQUENNIAL
  138. resolution := '12M'
  139. resolution
  140. resolution
  141.  
  142. var lines = array.new_line()
  143. var labels = array.new_label()
  144.  
  145. draw_line(i, pivot, col) =>
  146. if array.size(arr_time) > 1
  147. array.push(lines, line.new(array.get(arr_time, i), array.get(pivot, i), array.get(arr_time, i + 1), array.get(pivot, i), color=col, xloc=xloc.bar_time))
  148.  
  149. draw_label(i, y, txt, txt_color) =>
  150. if show_labels
  151. offset = '‏ ‏ ‏ ‏ ‏'
  152. labels_align_str_left = position_labels == 'Left' ? txt + offset : offset + txt
  153. x = position_labels == 'Left' ? array.get(arr_time, i) : array.get(arr_time, i + 1)
  154. array.push(labels, label.new(x=x, y=y, text=labels_align_str_left, textcolor=txt_color, style=label.style_label_center, color=#00000000, xloc=xloc.bar_time))
  155.  
  156.  
  157. fibonacci() =>
  158. pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close) / 3
  159. pivot_range = pivotX_prev_high - pivotX_prev_low
  160. array.push(p, pivotX_Median)
  161. array.push(r1, pivotX_Median + 0.382 * pivot_range)
  162. array.push(s1, pivotX_Median - 0.382 * pivot_range)
  163. array.push(r2, pivotX_Median + 0.618 * pivot_range)
  164. array.push(s2, pivotX_Median - 0.618 * pivot_range)
  165. array.push(r3, pivotX_Median + 1 * pivot_range)
  166. array.push(s3, pivotX_Median - 1 * pivot_range)
  167. array.push(r4, pivotX_Median + 1.272 * pivot_range)
  168. array.push(s4, pivotX_Median - 1.272 * pivot_range)
  169. array.push(r5, pivotX_Median + 1.618 * pivot_range)
  170. array.push(s5, pivotX_Median - 1.618 * pivot_range)
  171.  
  172.  
  173. camarilla() =>
  174. pivotX_Median = (pivotX_prev_high + pivotX_prev_low + pivotX_prev_close) / 3
  175. pivot_range = pivotX_prev_high - pivotX_prev_low
  176. H4 = pivotX_prev_close + pivot_range * 1.1 / 2
  177. H3 = pivotX_prev_close + pivot_range * 1.1 / 4
  178. H2 = pivotX_prev_close + pivot_range * 1.1 / 6
  179. H1 = pivotX_prev_close + pivot_range * 1.1 / 12
  180. L1 = pivotX_prev_close - pivot_range * 1.1 / 12
  181. L2 = pivotX_prev_close - pivot_range * 1.1 / 6
  182. L3 = pivotX_prev_close - pivot_range * 1.1 / 4
  183. L4 = pivotX_prev_close - pivot_range * 1.1 / 2
  184. L5 = L4 - 1.168 * (L3 - L4)
  185. H5 = H4 + 1.168 * (H4 - H3)
  186. H6 = pivotX_prev_high / pivotX_prev_low * pivotX_prev_close
  187. L6 = pivotX_prev_close - (H6 - pivotX_prev_close)
  188. array.push(p, pivotX_Median)
  189. array.push(r1, H2)
  190. array.push(s1, L2)
  191. array.push(r2, H3)
  192. array.push(s2, L3)
  193. array.push(r3, H4)
  194. array.push(s3, L4)
  195. array.push(r4, H5)
  196. array.push(s4, L5)
  197. array.push(r5, H6)
  198. array.push(s5, L6)
  199.  
  200. resolution = get_pivot_resolution()
  201.  
  202. [sec_open, sec_high, sec_low, sec_close] = request.security(syminfo.tickerid, resolution, [open, high, low, close], lookahead=barmerge.lookahead_on)
  203. sec_open_gaps_on = request.security(syminfo.tickerid, resolution, open, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on)
  204.  
  205. var number_of_years = 0
  206. is_change_years = false
  207. var custom_years_resolution = pivot_time_frame == BIYEARLY or pivot_time_frame == TRIYEARLY or pivot_time_frame == QUINQUENNIAL
  208. if custom_years_resolution and ta.change(time(resolution))
  209. number_of_years += 1
  210. if pivot_time_frame == BIYEARLY and number_of_years % 2 == 0
  211. is_change_years := true
  212. number_of_years := 0
  213. number_of_years
  214. else if pivot_time_frame == TRIYEARLY and number_of_years % 3 == 0
  215. is_change_years := true
  216. number_of_years := 0
  217. number_of_years
  218. else if pivot_time_frame == QUINQUENNIAL and number_of_years % 5 == 0
  219. is_change_years := true
  220. number_of_years := 0
  221. number_of_years
  222.  
  223. var is_change = false
  224. var uses_current_bar = timeframe.isintraday
  225. var change_time = int(na)
  226. is_time_change = ta.change(time(resolution)) and not custom_years_resolution or is_change_years
  227. if is_time_change
  228. change_time := time
  229. change_time
  230.  
  231.  
  232. if not uses_current_bar and is_time_change or uses_current_bar and not na(sec_open_gaps_on)
  233. if is_daily_based
  234. pivotX_prev_open := sec_open[1]
  235. pivotX_prev_high := sec_high[1]
  236. pivotX_prev_low := sec_low[1]
  237. pivotX_prev_close := sec_close[1]
  238. pivotX_open := sec_open
  239. pivotX_high := sec_high
  240. pivotX_low := sec_low
  241. pivotX_low
  242. else
  243. pivotX_prev_high := pivotX_high
  244. pivotX_prev_low := pivotX_low
  245. pivotX_prev_open := pivotX_open
  246. pivotX_open := open
  247. pivotX_high := high
  248. pivotX_low := low
  249. pivotX_prev_close := close[1]
  250. pivotX_prev_close
  251.  
  252. if barstate.islast and not is_change and array.size(arr_time) > 0
  253. array.set(arr_time, array.size(arr_time) - 1, change_time)
  254. else
  255. array.push(arr_time, change_time)
  256.  
  257. if kind == FIBONACCI
  258. fibonacci()
  259. else if kind == CAMARILLA
  260. camarilla()
  261.  
  262. if array.size(arr_time) > look_back
  263. if array.size(arr_time) > 0
  264. array.shift(arr_time)
  265. if array.size(p) > 0 and p_show
  266. array.shift(p)
  267. if array.size(r1) > 0 and s1r1_show
  268. array.shift(r1)
  269. if array.size(s1) > 0 and s1r1_show
  270. array.shift(s1)
  271. if array.size(r2) > 0 and s2r2_show
  272. array.shift(r2)
  273. if array.size(s2) > 0 and s2r2_show
  274. array.shift(s2)
  275. if array.size(r3) > 0 and s3r3_show
  276. array.shift(r3)
  277. if array.size(s3) > 0 and s3r3_show
  278. array.shift(s3)
  279. if array.size(r4) > 0 and s4r4_show
  280. array.shift(r4)
  281. if array.size(s4) > 0 and s4r4_show
  282. array.shift(s4)
  283. if array.size(r5) > 0 and s5r5_show
  284. array.shift(r5)
  285. if array.size(s5) > 0 and s5r5_show
  286. array.shift(s5)
  287. is_change := true
  288. is_change
  289. else
  290. if is_daily_based
  291. pivotX_high := math.max(pivotX_high, sec_high)
  292. pivotX_low := math.min(pivotX_low, sec_low)
  293. pivotX_low
  294. else
  295. pivotX_high := math.max(pivotX_high, high)
  296. pivotX_low := math.min(pivotX_low, low)
  297. pivotX_low
  298.  
  299. if barstate.islast and array.size(arr_time) > 0 and is_change
  300. is_change := false
  301. if array.size(arr_time) > 2 and custom_years_resolution
  302. last_pivot_time = array.get(arr_time, array.size(arr_time) - 1)
  303. prev_pivot_time = array.get(arr_time, array.size(arr_time) - 2)
  304. estimate_pivot_time = last_pivot_time - prev_pivot_time
  305. array.push(arr_time, last_pivot_time + estimate_pivot_time)
  306. else
  307. array.push(arr_time, time_close(resolution))
  308.  
  309. for i = 0 to array.size(lines) - 1 by 1
  310. if array.size(lines) > 0
  311. line.delete(array.shift(lines))
  312. if array.size(lines) > 0
  313. label.delete(array.shift(labels))
  314.  
  315. for i = 0 to array.size(arr_time) - 2 by 1
  316. if array.size(p) > 0 and p_show
  317. draw_line(i, p, p_color)
  318. draw_label(i, array.get(p, i), 'P', p_color)
  319. if array.size(r1) > 0 and s1r1_show
  320. draw_line(i, r1, s1r1_color)
  321. draw_label(i, array.get(r1, i), 'R1', s1r1_color)
  322. if array.size(s1) > 0 and s1r1_show
  323. draw_line(i, s1, s1r1_color)
  324. draw_label(i, array.get(s1, i), 'S1', s1r1_color)
  325. if array.size(r2) > 0 and s2r2_show
  326. draw_line(i, r2, s2r2_color)
  327. draw_label(i, array.get(r2, i), 'R2', s2r2_color)
  328. if array.size(s2) > 0 and s2r2_show
  329. draw_line(i, s2, s2r2_color)
  330. draw_label(i, array.get(s2, i), 'S2', s2r2_color)
  331. if array.size(r3) > 0 and s3r3_show
  332. draw_line(i, r3, s3r3_color)
  333. draw_label(i, array.get(r3, i), 'R3', s3r3_color)
  334. if array.size(s3) > 0 and s3r3_show
  335. draw_line(i, s3, s3r3_color)
  336. draw_label(i, array.get(s3, i), 'S3', s3r3_color)
  337. if array.size(r4) > 0 and s4r4_show
  338. draw_line(i, r4, s4r4_color)
  339. draw_label(i, array.get(r4, i), 'R4', s4r4_color)
  340. if array.size(s4) > 0 and s4r4_show
  341. draw_line(i, s4, s4r4_color)
  342. draw_label(i, array.get(s4, i), 'S4', s4r4_color)
  343. if array.size(r5) > 0 and s5r5_show
  344. draw_line(i, r5, s5r5_color)
  345. draw_label(i, array.get(r5, i), 'R5', s5r5_color)
  346. if array.size(s5) > 0 and s5r5_show
  347. draw_line(i, s5, s5r5_color)
  348. draw_label(i, array.get(s5, i), 'S5', s5r5_color)
  349.  
  350.  
  351.  
  352. ////////////////////////////////
  353. //float ph = na, float pl = na
  354. //ph := pivothigh(prd, prd)
  355. //pl := pivotlow(prd, prd)
  356.  
  357. //plotshape(ph and swing, text="H", style=shape.labeldown, color=na, textcolor=color.red, location=location.abovebar , offset = -prd)
  358. //plotshape(pl and swing, text="L", style=shape.labeldown, color=na, textcolor=color.green, location=location.belowbar , offset = -prd)
  359.  
  360. //lft = input.int(30, 'Swing Hi', group='Settings ॐ'')
  361. //rght = input.int(30, 'Swing Lo', group='Settings ॐ'')
  362.  
  363. hih = ta.pivothigh(high, prd, prd)
  364. lol = ta.pivotlow(low, prd, prd)
  365.  
  366. top = ta.valuewhen(hih, high[prd], 0)
  367. bot = ta.valuewhen(lol, low[prd], 0)
  368.  
  369. plot(swing ? top : na, color=top != top[1] ? na : ColorSelector(Hi_color), offset=-prd, editable=false)
  370. plot(swing ? bot : na, color=bot != bot[1] ? na : ColorSelector(Lo_color), offset=-prd, editable=false)
  371. ////////ORB {
  372. sess = input.session('0915-0945', title='ORB Period', inline='orb', group='Settings ॐ')
  373.  
  374. t = time(timeframe.period, sess + ':1234567')
  375. hide = timeframe.isintraday and timeframe.multiplier <= 10
  376.  
  377.  
  378. is_newbar(res) =>
  379. ta.change(time(res)) != 0
  380. in_session = not na(t)
  381. is_first = in_session and not in_session[1]
  382.  
  383. orb_high = float(na)
  384. orb_low = float(na)
  385.  
  386. if is_first
  387. orb_high := high
  388. orb_low := low
  389. orb_low
  390. else
  391. orb_high := orb_high[1]
  392. orb_low := orb_low[1]
  393. orb_low
  394. if high > orb_high and in_session
  395. orb_high := high
  396. orb_high
  397. if low < orb_low and in_session
  398. orb_low := low
  399. orb_low
  400.  
  401. show15highlow = input.bool(title='ORB ', defval=false, inline='orb', group='Settings ॐ')
  402.  
  403. plot(show15highlow ? orb_high : na, style=plot.style_circles, color=orb_high[1] != orb_high ? na : color.purple, title='IB High', linewidth=1, show_last=75)
  404. plot(show15highlow ? orb_low : na, style=plot.style_circles, color=orb_low[1] != orb_low ? na : color.purple, title='IB Low', linewidth=1, show_last=75)
  405.  
  406. //}
  407.  
  408.  
  409. hhtf = request.security(syminfo.tickerid, resolution, high[1], lookahead=barmerge.lookahead_on)
  410. lhtf = request.security(syminfo.tickerid, resolution, low[1], lookahead=barmerge.lookahead_on)
  411. chtf = request.security(syminfo.tickerid, resolution, close[1], lookahead=barmerge.lookahead_on)
  412.  
  413. rng = hhtf - lhtf
  414.  
  415. // is this last bar for HTF?
  416. islast = showlast ? request.security(syminfo.tickerid, resolution, barstate.islast, lookahead=barmerge.lookahead_on) : true
  417.  
  418. // Line Style
  419.  
  420. linestyleL = plot.style_circles
  421. ///////Calculation Camarilla
  422. H4 = chtf + rng * 1.1 / 2
  423. H3 = chtf + rng * 1.1 / 4
  424. H2 = chtf + rng * 1.1 / 6
  425. H1 = chtf + rng * 1.1 / 12
  426. L1 = chtf - rng * 1.1 / 12
  427. L2 = chtf - rng * 1.1 / 6
  428. L3 = chtf - rng * 1.1 / 4
  429. L4 = chtf - rng * 1.1 / 2
  430. L5 = L4 - 1.168 * (L3 - L4) //L5 = chtf - (H5 - chtf)
  431. H5 = H4 + 1.168 * (H4 - H3) //H5 = (hhtf / lhtf) * chtf
  432. H6 = hhtf / lhtf * chtf //H6 = H5 + 1.168 * (H5 - H4)
  433. L6 = chtf - (H6 - chtf) //L6 = chtf - (H6 - chtf)
  434. SLbull = (H4 + H3) / 2
  435. SLbear = (L4 + L3) / 2
  436. mid = (H3 + L3) / 2
  437. ////////Color Settings
  438.  
  439. plot(islast and kind == CAMARILLA and cmidon ? mid : na, 'Mid-H3-L3', color=color.new(#000000, 60), linewidth=1, style=linestyleL, editable=false)
  440. plot(islast and kind == CAMARILLA and cmidon ? SLbull : na, 'SLBull H3-H4', color=color.new(#ff0000, 60), linewidth=1, style=linestyleL, editable=false)
  441. plot(islast and kind == CAMARILLA and cmidon ? SLbear : na, 'SLBear L3-L4', color=color.new(#388e3c, 60), linewidth=1, style=linestyleL, editable=false)
  442.  
  443. // Label for S/R
  444. mndr = time - time[1]
  445. mndr := ta.change(mndr) > 0 ? mndr[1] : mndr
  446.  
  447. Round_it(valu) =>
  448. a = 0
  449. num = syminfo.mintick
  450. s = valu
  451. if na(s)
  452. s := syminfo.mintick
  453. s
  454. if num < 1
  455. for i = 1 to 20 by 1
  456. num *= 10
  457. if num > 1
  458. break
  459. a += 1
  460. a
  461.  
  462. for x = 1 to a by 1
  463. s *= 10
  464. s
  465. s := math.round(s)
  466. for x = 1 to a by 1
  467. s /= 10
  468. s
  469. s := s < syminfo.mintick ? syminfo.mintick : s
  470. s
  471.  
  472. // Labels
  473. if showlabels and kind == CAMARILLA
  474. var label s3label = na
  475. var label s4label = na
  476. var label s5label = na
  477. var label s6label = na
  478. var label r3label = na
  479. var label r4label = na
  480. var label r5label = na
  481. var label r6label = na
  482.  
  483. label.delete(s3label)
  484. label.delete(s4label)
  485. label.delete(s5label)
  486. label.delete(s6label)
  487. label.delete(r3label)
  488. label.delete(r4label)
  489. label.delete(r5label)
  490. label.delete(r6label)
  491. s3label := label.new(x=time + mndr * 20, y=L3, text='Buy Reversal •' + str.tostring(Round_it(L3)), color=color.new(#000000, 100), textcolor=color.green, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  492. s4label := label.new(x=time + mndr * 20, y=L4, text='Break Down •' + str.tostring(Round_it(L4)), color=color.new(#000000, 100), textcolor=lbcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  493. s5label := label.new(x=time + mndr * 20, y=L5, text='Target •' + str.tostring(Round_it(L5)), color=color.new(#000000, 100), textcolor=ltcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  494. s6label := label.new(x=time + mndr * 20, y=L6, text='Target •' + str.tostring(Round_it(L6)), color=color.new(#000000, 100), textcolor=ltcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  495. r3label := label.new(x=time + mndr * 20, y=H3, text='Sell reversal •' + str.tostring(Round_it(H3)), color=color.new(#000000, 100), textcolor=color.red, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  496. r4label := label.new(x=time + mndr * 20, y=H4, text='Breakout •' + str.tostring(Round_it(H4)), color=color.new(#000000, 100), textcolor=lbcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  497. r5label := label.new(x=time + mndr * 20, y=H5, text='Target •' + str.tostring(Round_it(H5)), color=color.new(#000000, 100), textcolor=ltcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  498. r6label := label.new(x=time + mndr * 20, y=H6, text='Target •' + str.tostring(Round_it(H6)), color=color.new(#000000, 100), textcolor=ltcol, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  499. r6label
  500.  
  501. //////Central Pivot
  502. Pivot = (hhtf + lhtf + chtf) / 3
  503. BC = (hhtf + lhtf) / 2
  504. TC = Pivot - BC + Pivot
  505. //LineStyle CPR
  506. linestylee = lstyle2 == 'Solid' ? plot.style_line : lstyle2 == 'Circles' ? plot.style_circles : lstyle2 == 'Cross' ? plot.style_cross : na
  507.  
  508.  
  509. plot(islast and cprturnon ? TC : na, title='TC', color=color.new(color.blue, 0), linewidth=1, style=linestylee)
  510. plot(islast and cprturnon ? Pivot : na, title='Pivot', color=color.new(color.red, 0), linewidth=1, style=linestylee)
  511. plot(islast and cprturnon ? BC : na, title='BC', color=color.new(color.blue, 0), linewidth=1, style=linestylee)
  512. plot(islast and JP ? Pivot : na, title='JPivot', color=color.new(color.red, 0), linewidth=2, style=linestylee)
  513. if showlabels and JP
  514. var label jplabel = na
  515.  
  516. label.delete(jplabel)
  517. jplabel := label.new(x=time + mndr * 20, y=Pivot, text='Pivot •' + str.tostring(Round_it(Pivot)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  518. chtf
  519. ///////Day High Low//////
  520. phhtf = request.security(syminfo.tickerid, Pres, high[lvl], lookahead=barmerge.lookahead_on)
  521. plhtf = request.security(syminfo.tickerid, Pres, low[lvl], lookahead=barmerge.lookahead_on)
  522. pchtf = request.security(syminfo.tickerid, Pres, close[lvl], lookahead=barmerge.lookahead_on)
  523. islast2 = showlast ? request.security(syminfo.tickerid, Pres, barstate.islast, lookahead=barmerge.lookahead_on) : true
  524. plot(islast2 and PDHL ? phhtf : na, title='Day High', color=PColor, linewidth=2, style=linestylee)
  525. plot(islast2 and PDHL ? plhtf : na, title='Day Low', color=PColor, linewidth=2, style=linestylee)
  526. plot(islast2 and PDHL ? pchtf : na, title='Day Close', color=PColor, linewidth=2, style=linestylee)
  527. if showlabels and PDHL
  528. var label pdhlabel = na
  529. var label pdllabel = na
  530. var label pdclabel = na
  531.  
  532. label.delete(pdhlabel)
  533. label.delete(pdllabel)
  534. label.delete(pdclabel)
  535. pdhlabel := label.new(x=time + mndr * 20, y=phhtf, text='PDH •' + str.tostring(Round_it(phhtf)), color=color.new(#000000, 100), textcolor=PColor, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  536. pdllabel := label.new(x=time + mndr * 20, y=plhtf, text='PDL •' + str.tostring(Round_it(plhtf)), color=color.new(#000000, 100), textcolor=PColor, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  537. pdclabel := label.new(x=time + mndr * 20, y=pchtf, text='PDC •' + str.tostring(Round_it(pchtf)), color=color.new(#000000, 100), textcolor=PColor, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  538. pdclabel
  539. //////Fibo Pivot
  540.  
  541. pivot = (hhtf + lhtf + chtf) / 3.0
  542. R1 = pivot + 0.382 * rng
  543. S1 = pivot - 0.382 * rng
  544. R2 = pivot + 0.618 * rng
  545. S2 = pivot - 0.618 * rng
  546. R3 = pivot + rng
  547. S3 = pivot - rng
  548. R4 = pivot + 1.272 * rng
  549. S4 = pivot - 1.272 * rng
  550. R5 = pivot + 1.618 * rng
  551. S5 = pivot - 1.618 * rng
  552. R6 = pivot + 2.058 * rng
  553. S6 = pivot - 2.058 * rng
  554. R7 = pivot + 2.618 * rng
  555. S7 = pivot - 2.618 * rng
  556.  
  557. if showlabels and kind == FIBONACCI
  558. var label fs1label = na
  559. var label fs2label = na
  560. var label fs3label = na
  561. var label fs4label = na
  562. var label plabel = na
  563. var label fr1label = na
  564. var label fr2label = na
  565. var label fr3label = na
  566. var label fr4label = na
  567.  
  568. label.delete(fs1label)
  569. label.delete(fs2label)
  570. label.delete(fs3label)
  571. label.delete(fs4label)
  572. label.delete(plabel)
  573. label.delete(fr1label)
  574. label.delete(fr2label)
  575. label.delete(fr3label)
  576. label.delete(fr4label)
  577. fs1label := label.new(x=time + mndr * 20, y=S1, text='0.382 ' + str.tostring(Round_it(S1)), color=color.new(#000000, 100), textcolor=color.green, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  578. fs2label := label.new(x=time + mndr * 20, y=S2, text='0.618 ' + str.tostring(Round_it(S2)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  579. fs3label := label.new(x=time + mndr * 20, y=S3, text='100 ' + str.tostring(Round_it(S3)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  580. fs4label := label.new(x=time + mndr * 20, y=S4, text='1.272 ' + str.tostring(Round_it(S4)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  581. plabel := label.new(x=time + mndr * 20, y=pivot, text='Pivot ' + str.tostring(Round_it(pivot)), color=color.new(#000000, 100), textcolor=color.silver, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  582. fr1label := label.new(x=time + mndr * 20, y=R1, text='0.382 ' + str.tostring(Round_it(R1)), color=color.new(#000000, 100), textcolor=color.red, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  583. fr2label := label.new(x=time + mndr * 20, y=R2, text='0.618 ' + str.tostring(Round_it(R2)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  584. fr3label := label.new(x=time + mndr * 20, y=R3, text='100 ' + str.tostring(Round_it(R3)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  585. fr4label := label.new(x=time + mndr * 20, y=R4, text='1.272 ' + str.tostring(Round_it(R4)), color=color.new(#000000, 100), textcolor=color.black, style=label.style_label_left, xloc=xloc.bar_time, yloc=yloc.price)
  586. fr4label
  587.  
  588. PAB = input.bool(true, 'Price Action Bars', group='Settings ॐ')
  589. //Dark Cloud
  590. DRKC = open[1] < close[1] ? open > high[1] ? close < close[1] - (close[1] - open[1]) / 2 ? close > open[1] ? #dbff01 : na : na : na : na
  591. barcolor(PAB ? DRKC : na, title='Dark Cloud')
  592.  
  593. //Bearish Engulfing
  594. BrEng = close < open[1] ? low < low[1] ? high > high[1] ? open >= open[1] ? #ff0000 : na : na : na : na
  595. barcolor(PAB ? BrEng : na, title='Bearish Engulf')
  596.  
  597.  
  598. //Bullish Engulfing
  599. BuEng = low < low[1] ? high > high[1] ? open <= open[1] ? close > open[1] ? #00ff0a : na : na : na : na
  600. barcolor(PAB ? BuEng : na, title='Bullish Engulf')
  601.  
  602. BearishENG = open[1] < close[1] ? close < open[1] ? open > close[1] ? #ff0000 : na : na : na
  603. barcolor(PAB ? BearishENG : na, title='Bearish 2 Engulf')
  604. BullishENG = open[1] > close[1] ? close > open[1] ? open < close[1] ? #00ff0a : na : na : na
  605. barcolor(PAB ? BullishENG : na, title='Bullish 2 Engulf')
  606.  
  607. //Three White Soldiers
  608. //TWS = close > open ? close[1] > open[1] ? close[2] > open[2] ? close > high[1] ? close[1] > high[2] ? open < close[1] ? open[1] < close[2] ? (high - close ) * 3 < close - open ? (high[1] - close[1]) * 3 < close[1] - open[1] ? (high[2] - close[2]) * 3 < close[2] - open[2] ? #66ff00 : na : na : na : na : na : na:na : na : na : na
  609. //barcolor(PAB ? TWS : na, title="Three white soliders")
  610. //TBC = close < open ? close[1] < open[1] ? close[2] < open[2] ? close < low[1] ? close[1] < low[2] ? open > close[1] ? open[1] > close[2] ? (close - low) * 3 < open - close ? (close[1] - low[1]) * 3 < open[1] - close[1] ? (close[2] - low[2]) * 3 < open[2] - close[2] ? #ff6600 : na : na : na : na : na : na:na : na : na : na
  611. //barcolor (PAB ? TBC : na, title = "Three Black Crows")
  612. /////VWAP////MVWAP
  613. Length = input.int(50, title='MVWAP', inline='vwap', group='Settings ॐ')
  614. mvwap = ta.ema(ta.vwap, Length)
  615. plot(vwaplot ? mvwap : na, linewidth=2, title='MVWAP', style=plot.style_line, color=color.new(color.purple, 0))
  616.  
  617. plot(ta.vwap and vwaplot ? ta.vwap : na, linewidth=lw, title='VWAP', color=color.new(#FF7000, 0))
  618.  
  619. //////EMA
  620. plot(emaplot and choice == 'EMA' ? ta.ema(close, MAa) : emaplot and choice == 'SMA' ? ta.sma(close, MAa) : na, title='Fast MA', color=color.new(color.green, 0), linewidth=lw)
  621. plot(emaplot and choice == 'EMA' ? ta.ema(close, MAb) : emaplot and choice == 'SMA' ? ta.sma(close, MAb) : na, title='Mid MA', color=color.new(color.black, 0), linewidth=lw)
  622. plot(emaplot and choice == 'EMA' ? ta.ema(close, MAc) : emaplot and choice == 'SMA' ? ta.sma(close, MAc) : na, title='Slow MA', color=color.new(color.red, 0), linewidth=lw)
  623.  
  624.  
  625. ////////////Volume Based Support Resistance
  626. Vlength = input.int(20, minval=1, group='Volume S/R Settings')
  627. Vchange = volume / volume[1] - 1
  628. stdev = ta.stdev(Vchange, Vlength)
  629. difference = Vchange / stdev[1]
  630. Treshold = input(5)
  631. zero = 0
  632. signal = math.abs(difference)
  633. vstylee = plot.style_circles
  634.  
  635. leveluphi = ta.valuewhen(signal > Treshold, high[1], 0)
  636. leveluplo = ta.valuewhen(signal > Treshold, low[1], 0)
  637.  
  638. //plot(UpperTreshold, color=black)
  639. pv1 = plot(vsr and leveluphi ? leveluphi : na, title='LevelHi', style=vstylee, color=color.new(color.blue, 0))
  640. pv2 = plot(vsr and leveluplo ? leveluplo : na, title='Levello', style=vstylee, color=color.new(color.blue, 0))
  641. fill(pv1, pv2, color=color.new(color.black, 50), title='Fill')
  642. ////////////////////////
  643. Ecandle = input.bool(false, 'Indecisive-Candle', group='Settings ॐ', tooltip='Shows 50% Candles')
  644.  
  645. cand = high - low
  646. bodyr = open - close
  647.  
  648. candle = bodyr * 100 / cand
  649.  
  650. barcolor(Ecandle and candle > -50 and candle < 50 ? #0b00ff : na)
  651. /////
  652.  
  653. ///////// Day Range
  654. On = input.bool(false, 'Day Range', group='Settings ॐ')
  655.  
  656. fill(plot1=plot(On and islast ? H4 : na, color=color.new(#ff7700, 80), editable=false), plot2=plot(On and islast ? R2 : na, color=color.new(#ff7700, 100), editable=false), color=color.new(#ff7700, 75))
  657. fill(plot1=plot(On and islast ? L4 : na, color=color.new(#000000, 80), editable=false), plot2=plot(On and islast ? S2 : na, color=color.new(#000000, 100), editable=false), color=color.new(#000000, 75))
  658.  
  659. //Price Action {
  660. TR1 = input.int(27, title='SMA to determine Trend', minval=1, maxval=500)
  661. TR2 = input.int(111, title='SMA to determine Trend', minval=1, maxval=500)
  662. CS = input.int(14, title='Candle Strength', minval=14, maxval=50)
  663. confirm = barstate.isconfirmed
  664. C_DownTrend = true
  665. C_UpTrend = true
  666. var trendRule1 = 'EMA50'
  667. var trendRule2 = 'EMA50, EMA200'
  668. var trendRule = input.string(trendRule1, '', options=[trendRule1, trendRule2, 'No detection'], inline='RT', group='Price Action')
  669.  
  670. if trendRule == trendRule1
  671. priceAvg = ta.ema(close, TR1)
  672. C_DownTrend := close < priceAvg
  673. C_UpTrend := close > priceAvg
  674. C_UpTrend
  675.  
  676. if trendRule == trendRule2
  677. sma200 = ta.ema(close, TR2)
  678. sma50 = ta.ema(close, TR1)
  679. C_DownTrend := close < sma50 and sma50 < sma200
  680. C_UpTrend := close > sma50 and sma50 > sma200
  681. C_UpTrend
  682. C_Len = CS // ema depth for bodyAvg
  683. C_ShadowPercent = 5.0 // size of shadows
  684. C_ShadowEqualsPercent = 100.0
  685. C_DojiBodyPercent = 5.0
  686. C_Factor = 2.0 // shows the number of times the shadow dominates the candlestick body
  687.  
  688. C_BodyHi = math.max(close, open)
  689. C_BodyLo = math.min(close, open)
  690. C_Body = C_BodyHi - C_BodyLo
  691. C_BodyAvg = ta.ema(C_Body, C_Len)
  692. C_SmallBody = C_Body < C_BodyAvg
  693. C_LongBody = C_Body > C_BodyAvg
  694. C_UpShadow = high - C_BodyHi
  695. C_DnShadow = C_BodyLo - low
  696. C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
  697. C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
  698. C_WhiteBody = open < close
  699. C_BlackBody = open > close
  700. C_Range = high - low
  701. C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
  702. C_BodyMiddle = C_Body / 2 + C_BodyLo
  703. C_ShadowEquals = C_UpShadow == C_DnShadow or math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100 < C_ShadowEqualsPercent and math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100 < C_ShadowEqualsPercent
  704. C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
  705. C_Doji = C_IsDojiBody and C_ShadowEquals
  706.  
  707. patternLabelPosLow = low - ta.atr(30) * 0.99
  708. patternLabelPosHigh = high + ta.atr(30) * 0.99
  709.  
  710.  
  711. text_color_bullish = input(color.green, 'Text Color Bull')
  712. text_color_bearish = input(color.red, 'Text color Bear')
  713. CandleType = input.string(title='Pattern Type', defval='Both', options=['Bullish', 'Bearish', 'Both'])
  714.  
  715.  
  716. C_HammerBullishNumberOfCandles = 1
  717. C_HammerBullish = false
  718. if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow and confirm
  719. if C_DownTrend
  720. C_HammerBullish := true
  721. C_HammerBullish
  722. alertcondition(C_HammerBullish, title='Hammer – Bullish', message='New Hammer – Bullish pattern detected')
  723. if C_HammerBullish and HammerInput and ('Bullish' == CandleType or CandleType == 'Both')
  724.  
  725. var ttBullishHammer = 'Hammer\nHammer candlesticks form when a security moves lower after the open, but continues to rally into close above the intraday low. The candlestick that you are left with will look like a square attached to a long stick-like figure. This candlestick is called a Hammer if it happens to form during a decline.'
  726. label.new(bar_index, patternLabelPosLow, text='H', style=label.style_none, textcolor=text_color_bullish, tooltip=ttBullishHammer)
  727.  
  728.  
  729. C_HangingManBearishNumberOfCandles = 1
  730. C_HangingManBearish = false
  731. if C_SmallBody and C_Body > 0 and C_BodyLo > hl2 and C_DnShadow >= C_Factor * C_Body and not C_HasUpShadow and confirm
  732. if C_UpTrend
  733. C_HangingManBearish := true
  734. C_HangingManBearish
  735. alertcondition(C_HangingManBearish, title='Hanging Man – Bearish', message='New Hanging Man – Bearish pattern detected')
  736. if C_HangingManBearish and HangingManInput and ('Bearish' == CandleType or CandleType == 'Both')
  737.  
  738. var ttBearishHangingMan = 'Hanging Man\nWhen a specified security notably moves lower after the open, but continues to rally to close above the intraday low, a Hanging Man candlestick will form. The candlestick will resemble a square, attached to a long stick-like figure. It is referred to as a Hanging Man if the candlestick forms during an advance.'
  739. label.new(bar_index, patternLabelPosHigh, text='HM', style=label.style_none, textcolor=text_color_bearish, tooltip=ttBearishHangingMan)
  740.  
  741.  
  742. C_InvertedHammerBullishNumberOfCandles = 1
  743. C_InvertedHammerBullish = false
  744. if C_SmallBody and C_Body > 0 and C_BodyHi < hl2 and C_UpShadow >= C_Factor * C_Body and not C_HasDnShadow and confirm
  745. if C_DownTrend
  746. C_InvertedHammerBullish := true
  747. C_InvertedHammerBullish
  748. alertcondition(C_InvertedHammerBullish, title='Inverted Hammer – Bullish', message='New Inverted Hammer – Bullish pattern detected')
  749. if C_InvertedHammerBullish and InvertedHammerInput and ('Bullish' == CandleType or CandleType == 'Both')
  750.  
  751. var ttBullishInvertedHammer = 'Inverted Hammer\nIf in a downtrend, then the open is lower. When it eventually trades higher, but closes near its open, it will look like an inverted version of the Hammer Candlestick. This is a one-day bullish reversal pattern.'
  752. label.new(bar_index, patternLabelPosLow, text='IH', style=label.style_none, textcolor=text_color_bullish, tooltip=ttBullishInvertedHammer)
  753.  
  754.  
  755.  
  756. // ATR Trailing SL {
  757. nATRPeriod = input.int(5, 'Period', inline='atr', group='Settings ॐ')
  758. nATRMultip = input.float(3.5, 'Multi', inline='atr', group='Settings ॐ')
  759. xATR = ta.atr(nATRPeriod)
  760. nLoss = nATRMultip * xATR
  761. xATRTrailingStop = 0.0
  762. iff_1 = close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
  763. iff_2 = close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) : iff_1
  764. xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) : iff_2
  765. col = close < xATRTrailingStop[1] ? color.silver : color.black
  766. plot(ATRTsl ? xATRTrailingStop[1] : na, color=col, title='ATR Trailing Stop') //}
  767.  
  768. //Table {
  769. var table info = table.new(position.top_center, 1, 1)
  770. var table logo = table.new(position.bottom_right, 1, 1)
  771. if barstate.islast
  772. table.cell(logo, 0, 0, 'ॐ ', text_size=size.normal, text_color=color.orange)
  773. table.cell(info, 0, 0, 't.me/TeamTaurus', text_size=size.small, text_color=color.black)
  774. //}
  775. //{RSI col
  776. rsicol = input.bool(false, title='Show RSI colors?', group='Settings ॐ', tooltip='Show RSI Levels On Bars')
  777.  
  778. srcRSI = close
  779. lenRSI = input.int(14, minval=1, title='RSI Length', group='RSI Settings')
  780. up = ta.rma(math.max(ta.change(srcRSI), 0), lenRSI)
  781. down = ta.rma(-math.min(ta.change(srcRSI), 0), lenRSI)
  782. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - 100 / (1 + up / down)
  783. //coloring method below
  784. srcRSI1 = close
  785. lenRSI1 = input.int(60, minval=1, title='Over Bought', group='RSI Settings')
  786. srcRSI2 = close
  787. lenRSI2 = input.int(40, minval=1, title='Over Sold', group='RSI Settings')
  788. isup() =>
  789. rsi > lenRSI1
  790. isdown() =>
  791. rsi < lenRSI2
  792. barcolor(rsicol and isup() ? color.green : rsicol and isdown() ? color.red : na) // }
  793. //Mid Point {
  794. Mid = input.bool(true, 'Mid Point', group='Settings ॐ')
  795. plotchar(Mid ? hl2 : na, char='•', color=color.new(color.red, 0), location=location.absolute, size=size.tiny, offset=1, show_last=5) //}
  796. //BollingerBands {
  797. bbon = input.bool(false, title='BollingerBands', inline='BB', group='Settings ॐ')
  798. bblength = input.int(27, '', minval=1, inline='BB', group='Settings ॐ')
  799. bbsrc = input.source(close, title='', inline='BB', group='Settings ॐ')
  800. mult = input.float(2.0, minval=0.001, maxval=50, title='', inline='BB', group='Settings ॐ')
  801. basis = ta.sma(bbsrc, bblength)
  802. dev = mult * ta.stdev(bbsrc, bblength)
  803. upper = basis + dev
  804. lower = basis - dev
  805. offset = input.int(0, 'BB Offset', minval=-500, maxval=500)
  806. plot(bbon ? basis : na, 'Basis', color=color.new(#872323, 0), offset=offset)
  807. b1 = plot(bbon ? upper : na, 'Upper', color=color.new(color.teal, 0), offset=offset)
  808. b2 = plot(bbon ? lower : na, 'Lower', color=color.new(color.teal, 0), offset=offset)
  809. fill(b1, b2, title='Background', color=color.new(#198787, 95)) //}
  810.  
  811. ////////////Trendlines Taken from Lonesomeblue
  812. startyear = input(defval=2020, title='Start Year',group='Trendline')
  813. startmonth = input(defval=1, title='Start Month',group='Trendline')
  814. startday = input(defval=1, title='Start day',group='Trendline')
  815. prdl = input.int(defval=10, title='Pivot Period', minval=10, maxval=50,group='Trendline')
  816. PPnum = input.int(defval=3, title='Number of Pivot Points to check', minval=2, maxval=8,group='Trendline')
  817. utcol = input.color(defval=color.lime, title='Colors', inline='tcol',group='Trendline')
  818. dtcol = input.color(defval=color.red, title='', inline='tcol',group='Trendline')
  819.  
  820. float ph = ta.pivothigh(prdl, prdl)
  821. float pl = ta.pivotlow(prdl, prdl)
  822.  
  823. var tval = array.new_float(PPnum)
  824. var tpos = array.new_int(PPnum)
  825. var bval = array.new_float(PPnum)
  826. var bpos = array.new_int(PPnum)
  827.  
  828. add_to_array(apointer1, apointer2, val) =>
  829. array.unshift(apointer1, val)
  830. array.unshift(apointer2, bar_index)
  831. array.pop(apointer1)
  832. array.pop(apointer2)
  833.  
  834. if ph
  835. add_to_array(tval, tpos, ph)
  836.  
  837. if pl
  838. add_to_array(bval, bpos, pl)
  839.  
  840. // line definitions
  841. maxline = 3
  842. var bln = array.new_line(maxline, na)
  843. var tln = array.new_line(maxline, na)
  844.  
  845. // loop for pivot points to check if there is possible trend line
  846. countlinelo = 0
  847. countlinehi = 0
  848.  
  849. starttime = timestamp(startyear, startmonth, startday, 0, 0, 0)
  850.  
  851. if time >= starttime
  852. for x = 0 to maxline - 1 by 1
  853. line.delete(array.get(bln, x))
  854. line.delete(array.get(tln, x))
  855. for p1 = 0 to PPnum - 2 by 1
  856. uv1 = 0.0
  857. uv2 = 0.0
  858. up1 = 0
  859. up2 = 0
  860. if countlinelo <= maxline
  861. for p2 = PPnum - 1 to p1 + 1 by 1
  862. val1 = array.get(bval, p1)
  863. val2 = array.get(bval, p2)
  864. pos1 = array.get(bpos, p1)
  865. pos2 = array.get(bpos, p2)
  866. if val1 > val2
  867. diff = (val1 - val2) / (pos1 - pos2)
  868. hline = val2 + diff
  869. lloc = bar_index
  870. lval = low
  871. valid = true
  872. for x = pos2 + 1 - prd to bar_index by 1
  873. if close[bar_index - x] < hline
  874. valid := false
  875. break
  876. lloc := x
  877. lval := hline
  878. hline += diff
  879. hline
  880.  
  881.  
  882. if valid
  883. uv1 := hline - diff
  884. uv2 := val2
  885. up1 := lloc
  886. up2 := pos2
  887. break
  888.  
  889. dv1 = 0.0
  890. dv2 = 0.0
  891. dp1 = 0
  892. dp2 = 0
  893. if countlinehi <= maxline
  894. for p2 = PPnum - 1 to p1 + 1 by 1
  895. val1 = array.get(tval, p1)
  896. val2 = array.get(tval, p2)
  897. pos1 = array.get(tpos, p1)
  898. pos2 = array.get(tpos, p2)
  899. if val1 < val2
  900. diff = (val2 - val1) / float(pos1 - pos2)
  901. hline = val2 - diff
  902. lloc = bar_index
  903. lval = high
  904. valid = true
  905. for x = pos2 + 1 - prd to bar_index by 1
  906. if close[bar_index - x] > hline
  907. valid := false
  908. break
  909. lloc := x
  910. lval := hline
  911. hline -= diff
  912. hline
  913.  
  914. if valid
  915. dv1 := hline + diff
  916. dv2 := val2
  917. dp1 := lloc
  918. dp2 := pos2
  919. break
  920.  
  921. // if there is continues uptrend line then draw it
  922. if up1 != 0 and up2 != 0 and countlinelo < maxline
  923. countlinelo += 1
  924. array.set(bln, countlinelo - 1, line.new(up2 - prd, uv2, up1, uv1, color=utcol))
  925.  
  926. // if there is continues downtrend line then draw it
  927. if dp1 != 0 and dp2 != 0 and countlinehi < maxline
  928. countlinehi += 1
  929. array.set(tln, countlinehi - 1, line.new(dp2 - prd, dv2, dp1, dv1, color=dtcol))
  930.  
  931.  
  932.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement