dusun1

CC INDICATOR 2

Dec 10th, 2022
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.50 KB | None | 0 0
  1. https://www.tradingview.com/script/dkGe7rmo-Chart-Champions-Part-2-CCV-IBs-POCs/
  2. // Super Special Indicator for Detecting Daily nPOC Coding CCV nPOC
  3.  
  4. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  5. // To ensure you get the correct output values use Standard Candles
  6. // Thanks go to
  7. //ahancock for allow usage of his script
  8. //AnyDozer and Bjorn Mistiaen on Stack Overflow for all their assistance
  9.  
  10.  
  11. //@version=4
  12. study(title="Chart Champions - Part 2 - CCV IBs POCs", shorttitle="CC - Pt2 - CCV IBs POC", overlay=true)
  13.  
  14. NoLabel = input(false, title="No Label Option ", tooltip="Option to have no Label Box")
  15. //Generic
  16. NoLabelOption = NoLabel ? label.style_none : label.style_label_left
  17. PriceLocation = NoLabel ? " " : ""
  18. LabelSize = NoLabel ? size.normal : size.small
  19.  
  20. //Daily Open
  21. DLabelColor = NoLabel ? color.blue : color.white
  22. IBLabelColor = NoLabel ? color.orange : color.white
  23. POCLabelColor = NoLabel ? color.red : color.white
  24. dPOCLabelColor = NoLabel ? color.red : color.white
  25.  
  26. //USer configurations
  27. va_percent = input(0.68, title = "Value Area (Igor 0.7 / Daniel 0.68)", group = "CCV Settings", type = input.float,
  28. minval = 0.1, maxval = 1, step = 0.1)
  29.  
  30. dtf = input("D", title = "Volume Capture Time Frame Period", type = input.resolution, group = "Resolution Settings")
  31. vauto = input(true, title="Auto uses mintick data", group = "Resolution Settings", tooltip="If errors untick auto and tick manual")
  32. vresolution = input(false, title="Manual Resolution", group = "Resolution Settings")
  33.  
  34. resolution = input(1, title = "Resolution (Change to decimal of pair for example 0.00001 for XRP)", group = "Resolution Settings", type = input.float)
  35. auto = syminfo.mintick
  36. auto := vauto ? auto : vresolution ? resolution : auto
  37.  
  38.  
  39. show_ccv = input(true, title = "First check if CCV is in play", group = "CCV Settings", type = input.bool)
  40. show_ccv_fill = input(true, title = "CCV Background Fill", group = "CCV Settings", type = input.bool)
  41. show_IB = input(false, title = "Show Initial Balance", type = input.bool)
  42. show_DevPOC = input(false, title = "Show Developing Day POCs (dPOC)", group = "Optional Points of Contact", type = input.bool)
  43. show_PrevPOC = input(false, title = "Show Previous Day POCs (pdPOC)", group = "Optional Points of Contact", type = input.bool)
  44. show_dbyPOC = input(false, title = "Show Day Before Yesterday POCs (dbyPOC)", group = "Optional Points of Contact", type = input.bool)
  45.  
  46.  
  47. //CCV color/txt hide
  48. ccvtxt_color = show_ccv ? color.white : na
  49. ccvdopen_color = show_ccv ? color.blue : na
  50. IBtxt_color = show_IB ? IBLabelColor : na
  51. IB_color = show_IB ? color.orange : na
  52. pdPOC_txt_color = show_PrevPOC ? POCLabelColor : na
  53. dbyPOC_txt_color = show_dbyPOC ? POCLabelColor : na
  54. devPOC_txt_color = show_DevPOC ? POCLabelColor : na
  55.  
  56. pdPOC_color = show_PrevPOC ? #B22222 : na
  57. dbyPOC_color = show_dbyPOC ? #8B0000 : na
  58. devPOC_color = show_DevPOC ? color.red : na
  59.  
  60.  
  61.  
  62.  
  63. //Session Rules
  64. bartimeSess = time('D')
  65. newbarSess = bartimeSess != bartimeSess[1]
  66. //offset_val = input(title="Label Offset", type=input.integer, defval=6)
  67. high_range = valuewhen(newbarSess,high,0)
  68. low_range = valuewhen(newbarSess,low,0)
  69.  
  70. //Daily Open
  71. dOpen = security(syminfo.tickerid, "D", open, lookahead = barmerge.lookahead_on)
  72. plot(dOpen, " dOpen", change(dOpen) ? na : color.blue, offset = 0)
  73. dOpenLabel = label.new(timenow, dOpen, xloc = xloc.bar_time, text = PriceLocation+"dOpen - "+tostring(dOpen), color = color.blue, textcolor = DLabelColor, style = NoLabelOption, size=LabelSize)
  74. label.delete(dOpenLabel[1])
  75.  
  76.  
  77.  
  78. //Calcul For OpendOpening Range
  79. locHigh = security(syminfo.tickerid, "60", high_range)
  80. locLow = security(syminfo.tickerid, "60", low_range)
  81. range = locHigh - locLow
  82.  
  83. plot(locHigh, "IB High", change(locHigh) ? na : IB_color, offset = 0)
  84. locHighLabel = label.new(timenow, locHigh, xloc = xloc.bar_time, text = PriceLocation+"IB High - "+tostring(locHigh), color = IB_color, textcolor = IBtxt_color, style = NoLabelOption, size=LabelSize)
  85. label.delete(locHighLabel[1])
  86.  
  87. plot(locLow, "IB Low", change(locLow) ? na : IB_color, offset = 0)
  88. locLowLabel = label.new(timenow, locLow, xloc = xloc.bar_time, text = PriceLocation+"IB Low - "+tostring(locLow), color = IB_color, textcolor = IBtxt_color, style = NoLabelOption, size=LabelSize)
  89. label.delete(locLowLabel[1])
  90.  
  91. locMid = locLow + range/2
  92. plot(locMid, "IB Mid", change(locMid) ? na : IB_color, offset = 0)
  93. locMidLabel = label.new(timenow, locMid, xloc = xloc.bar_time, text = PriceLocation+"IB Mid - "+tostring(locMid), color = IB_color, textcolor = IBtxt_color, style = NoLabelOption, size=LabelSize)
  94. label.delete(locMidLabel[1])
  95.  
  96.  
  97. is_new_bar(t) =>
  98. change(time(t)) != 0
  99.  
  100. round_to_nearest(v, x) =>
  101. round(v / x) * x
  102.  
  103.  
  104. tick_size = max(syminfo.mintick, auto)
  105.  
  106. var a = array.new_float(0)
  107.  
  108. a_min = 0.0, a_min := nz(a_min[1], round_to_nearest(low, tick_size))
  109. a_max = 0.0, a_max := nz(a_max[1], round_to_nearest(high, tick_size))
  110.  
  111. d_switch = is_new_bar(dtf)
  112.  
  113. if d_switch
  114. a_min := low
  115. a_max := high
  116. array.clear(a)
  117.  
  118. // Scaled min max
  119. v_min = int(round_to_nearest(low - a_min, tick_size) / tick_size)
  120. v_max = int(round_to_nearest(high - a_min, tick_size) / tick_size)
  121.  
  122. // Scaled candle range
  123. ticks = v_max - v_min
  124.  
  125. vol = volume / (ticks == 0 ? 1 : ticks)
  126.  
  127. for i = v_min to max(v_max - 1, v_min)
  128.  
  129. // Insert new low value
  130. if i < 0
  131. array.insert(a, i - v_min, vol)
  132. continue
  133.  
  134. // Adjust index
  135. offset = v_min < 0 ? abs(v_min) : 0
  136. index = int(i + offset)
  137.  
  138. // Push new high value
  139. if index >= array.size(a)
  140. array.push(a, vol)
  141. continue
  142.  
  143. // Update existing value
  144. v = array.get(a, index)
  145. array.set(a, index, v + vol)
  146.  
  147. // Array bounds
  148. a_min := min(a_min, round_to_nearest(low, tick_size))
  149. a_max := max(a_max, round_to_nearest(high, tick_size))
  150. a_size = array.size(a)
  151.  
  152. // { POC
  153.  
  154. poc_index = -1
  155. poc_prev = -1.0
  156. sum_vol = 0.0
  157.  
  158. for i = 0 to a_size - 1
  159.  
  160. poc_current = array.get(a, i)
  161. sum_vol := sum_vol + poc_current
  162.  
  163. if poc_current > poc_prev
  164. poc_prev := poc_current
  165. poc_index := i
  166.  
  167. // }
  168.  
  169. // { VA
  170.  
  171. va_high_index = poc_index
  172. va_low_index = poc_index
  173.  
  174. va_vol_cap = sum_vol * va_percent
  175. sum_va_vol = array.get(a, poc_index)
  176.  
  177. for i = 1 to a_size - 1
  178.  
  179. above = 0.0
  180. if va_high_index + 1 < a_size - 1
  181. above := above + nz(array.get(a, (va_high_index + 1)), 0.0)
  182. if va_high_index + 2 < a_size - 1
  183. above := above + nz(array.get(a, (va_high_index + 2)), 0.0)
  184.  
  185. below = 0.0
  186. if va_low_index - 1 > 0
  187. below := below + nz(array.get(a, (va_low_index - 1)), 0.0)
  188. if va_low_index - 2 > 0
  189. below := below + nz(array.get(a, (va_low_index - 2)), 0.0)
  190.  
  191. if above > below
  192. va_high_index := min(va_high_index + 2, a_size - 1)
  193. sum_va_vol := sum_va_vol + above
  194. else
  195. va_low_index := max(va_low_index - 2, 0)
  196. sum_va_vol := sum_va_vol + below
  197.  
  198. if sum_va_vol >= va_vol_cap or (va_low_index <= 0 and va_high_index >= a_size - 1)
  199. break
  200.  
  201. // }
  202.  
  203. float p_poc = 0.0
  204. float p_va_h = 0.0
  205. float p_va_l = 0.0
  206.  
  207. float d_poc = 0.0
  208. float b_poc = 0.0
  209.  
  210. float d_va_h = 0.0
  211. float d_va_l = 0.0
  212.  
  213. d_poc := poc_index * tick_size + a_min
  214. d_va_h := va_high_index * tick_size + a_min
  215. d_va_l := va_low_index * tick_size + a_min
  216.  
  217.  
  218.  
  219. if is_new_bar(dtf)
  220. p_poc := d_poc[1]
  221. p_va_h := d_va_h[1]
  222. p_va_l := d_va_l[1]
  223. b_poc := p_poc[1]
  224. else
  225. p_poc := p_poc[1]
  226. p_va_h := p_va_h[1]
  227. p_va_l := p_va_l[1]
  228. b_poc := b_poc[1]
  229.  
  230.  
  231. plot(d_poc, color = devPOC_color, title = "dPOC")
  232. d_poclabel = label.new(timenow, d_poc, xloc = xloc.bar_time, text = PriceLocation+"dPOC - "+tostring(d_poc), color = devPOC_color, textcolor = devPOC_txt_color, style = NoLabelOption, size=LabelSize)
  233. label.delete(d_poclabel[1])
  234.  
  235.  
  236.  
  237. plot(b_poc, "dby_POC", change(b_poc) ? na : dbyPOC_color, offset = 0)
  238. b_poclabel = label.new(timenow, b_poc, xloc = xloc.bar_time, text = PriceLocation+"dby_POC - "+tostring(b_poc), color = dbyPOC_color, textcolor = dbyPOC_txt_color, style = NoLabelOption, size=LabelSize)
  239. label.delete(b_poclabel[1])
  240.  
  241.  
  242.  
  243.  
  244. ccv_color = show_ccv ?
  245. dOpen > p_va_h ? color.green :
  246. dOpen < p_va_l ? color.green :
  247. color.red :
  248. na
  249. ccv_fill_color = ccv_color
  250.  
  251. ccv_fill_test = show_ccv_fill ? ccv_fill_color : na
  252.  
  253. CCVTxtLabelColor = NoLabel ? ccv_color : color.white
  254.  
  255.  
  256. plot(p_poc, " pd_POC", change(p_poc) ? na : pdPOC_color, offset = 0)
  257. p_poclabel = label.new(timenow, p_poc, xloc = xloc.bar_time, text = PriceLocation+"pdPOC - "+tostring(p_poc), color = pdPOC_color, textcolor = pdPOC_txt_color, style = NoLabelOption, size=LabelSize)
  258. label.delete(p_poclabel[1])
  259.  
  260.  
  261.  
  262. ccvplot_p_va_h = plot(p_va_h, " pdVAH", change(p_va_h) ? na : ccv_color, offset = 0)
  263. ccvplot_p_va_hlabel = label.new(timenow, p_va_h, xloc = xloc.bar_time, text = PriceLocation+"pdVAH - "+tostring(p_va_h), color = ccv_color, textcolor = CCVTxtLabelColor, style = NoLabelOption, size=LabelSize)
  264. label.delete(ccvplot_p_va_hlabel[1])
  265.  
  266. ccvplot_p_va_l = plot(p_va_l, " pdVAL", change(p_va_l) ? na : ccv_color, offset = 0)
  267. ccvplot_p_va_llabel = label.new(timenow, p_va_l, xloc = xloc.bar_time, text = PriceLocation+"pdVAL - "+tostring(p_va_l), color = ccv_color, textcolor = CCVTxtLabelColor, style = NoLabelOption, size=LabelSize)
  268. label.delete(ccvplot_p_va_llabel[1])
  269.  
  270. fill(ccvplot_p_va_h, ccvplot_p_va_l, ccv_fill_test)
  271.  
  272.  
Advertisement
Add Comment
Please, Sign In to add comment