Advertisement
xmd79

ICT IPDA Daily Range

Aug 27th, 2023
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.55 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. // © Catered
  3.  
  4. //@version=5
  5. indicator("ICT IPDA Daily Range", "ICT IPDA Daily Range", true, max_boxes_count = 500, max_labels_count = 500)
  6.  
  7. // ---------------------------------------- Inputs --------------------------------------------------
  8. var g_SETTINGS = "Settings"
  9. max_days = input.int(5, "Session Drawing Limit", 1, tooltip = "Only this many drawings will be kept on the chart, for each selected drawing type (killzone boxes, pivot lines, open lines, etc.)", group = g_SETTINGS)
  10. tf_limit = input.timeframe("60", "Timeframe Limit", tooltip = "Drawings will not appear on timeframes greater than or equal to this", group = g_SETTINGS)
  11. gmt_tz = input.string('GMT+3', "Timezone", options = ['GMT-12','GMT-11','GMT-10','GMT-9','GMT-8','GMT-7','GMT-6','GMT-5','GMT-4','GMT-3','GMT-2','GMT-1','GMT+0','GMT+1','GMT+2','GMT+3','GMT+4','GMT+5','GMT+6','GMT+7','GMT+8','GMT+9','GMT+10','GMT+11','GMT+12','GMT+13','GMT+14'], tooltip = "Note GMT is not adjusted to reflect Daylight Saving Time changes", group = g_SETTINGS)
  12. lb_size = input.string('Normal', "Label Size", options = ['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = g_SETTINGS)
  13. lb_color = input.color(color.black, "Label Text Color", group = g_SETTINGS)
  14. use_cutoff = input.bool(true, "Drawing Cutoff Time", inline = "CO", tooltip = "When enabled, all highs and lows will stop extending after this time", group = g_SETTINGS)
  15. cutoff = input.session("0000-0000", "", inline = "CO", group = g_SETTINGS)
  16.  
  17. var g_KZ = "IPDA boxes"
  18. show_kz = input.bool(true, "Show IPDA boxes", inline = "KZ", group = g_KZ)
  19. show_kz_text = input.bool(true, "Display Text", inline = "KZ", group = g_KZ)
  20. box_transparency = input.int(70, "Box Transparency", 0, 100, group = g_KZ)
  21. text_transparency = input.int(50, "Text Transparency", 0, 100, group = g_KZ)
  22.  
  23. var g_OPEN = "Opening Price"
  24. h_style = input.string(defval = 'Dotted', title = "Style", options = ['Solid', 'Dotted', 'Dashed'], inline = "H0", group = g_OPEN)
  25. h_width = input.int(1, "", inline = "H0", group = g_OPEN)
  26.  
  27. use_h1 = input.bool(true, "", inline = "H1", group = g_OPEN)
  28. h1_text = input.string("Opening Price", "", inline = "H1", group = g_OPEN)
  29. h1 = input.session("0700-2200", "", inline = "H1", group = g_OPEN)
  30. h1_color = input.color(color.black, "", inline = "H1", group = g_OPEN)
  31.  
  32. use_h2 = input.bool(false, "", inline = "H2", group = g_OPEN)
  33. h2_text = input.string("06:00", "", inline = "H2", group = g_OPEN)
  34. h2 = input.session("0600-0601", "", inline = "H2", group = g_OPEN)
  35. h2_color = input.color(color.black, "", inline = "H2", group = g_OPEN)
  36.  
  37. var g_VERTICAL = "Timestamps"
  38. v_style = input.string(defval = 'Dotted', title = "Style", options = ['Solid', 'Dotted', 'Dashed'], inline = "V0", group = g_VERTICAL)
  39. v_width = input.int(1, "", inline = "V0", group = g_VERTICAL)
  40.  
  41. use_v1 = input.bool(true, "", inline = "V1", group = g_VERTICAL)
  42. v1 = input.session("0700-0701", "IPDA_Start", inline = "V1", group = g_VERTICAL)
  43. v1_color = input.color(color.black, "", inline = "V1", group = g_VERTICAL)
  44.  
  45. use_v2 = input.bool(true, "", inline = "V2", group = g_VERTICAL)
  46. v2 = input.session("2200-2201", "IPDA_End", inline = "V2", group = g_VERTICAL)
  47. v2_color = input.color(color.black, "", inline = "V2", group = g_VERTICAL)
  48.  
  49. // ---------------------------------------- Inputs --------------------------------------------------
  50.  
  51. box_info = input.bool(true, "info over box", "this will show the range of the session in pips (make sense only on forex)", "", "session in box")
  52. spec = input.int(70, "Transparency", 0, 100, 1, "from 0 to 100, how much you want the color transparent?", "", "Visual Features")
  53.  
  54. // London Open session
  55. lno_ = input.bool(true, "London Open Killzone", "0800-1200 London", "", "Session")
  56. lno_b = input.bool(true, "London Open box", "", "", "session in box")
  57. lno_c = input.color(color.blue, "London Open Killzone", "", "", "Visual Features")
  58.  
  59. // New York Open session
  60. nyo_ = input.bool(true, "New York Open Killzone", "1300-1600 London", "", "Session")
  61. nyo_b = input.bool(true, "New York Open box", "", "", "session in box")
  62. nyo_c = input.color(color.orange, "New York Open Killzone", "", "", "Visual Features")
  63.  
  64. // London Close session
  65. lnc_ = input.bool(true, "London Close Killzone", "1700-1900 London", "", "Session")
  66. lnc_b = input.bool(true, "London Close box", "", "", "session in box")
  67. lnc_c = input.color(color.green, "London Close Killzone", "", "", "Visual Features")
  68.  
  69. // Asian Range session
  70. asb_ = input.bool(true, "Asian Range", "0300-0700 London", "", "Session")
  71. asb_b = input.bool(true, "Asian Range box", "", "", "session in box")
  72. asb_c = input.color(color.yellow, "Asian Range", "", "", "Visual Features")
  73.  
  74. // CBDR Range session
  75. cbdr_ = input.bool(true, "CBDR Range", "2100-0300 London", "", "Session")
  76. cbdr_b = input.bool(true, "CBDR Range box", "", "", "session in box")
  77. cbdr_c = input.color(color.purple, "CBDR Range", "", "", "Visual Features")
  78.  
  79. // -------------------------------------------------- Inputs --------------------------------------------------
  80. cbdr_session = input.session("2100-0300", "Session", inline = "X", tooltip = "The time window whose range will be utilized for projections", group = g_SETTINGS)
  81. range_type = input.string('Wick', "Range Type", options = ['Wick', 'Body'], tooltip = "Wick will consider the range from high to low, whereas Body will ignore the wicks (on the current chart timeframe)", group = g_SETTINGS)
  82. sd_limit = input.float(1.5, "Standard Deviation Filter", tooltip = "Ranges will be filtered out/ignored if their size exceeds this number of standard deviations (measured from a history of all prior range sizes)", group = g_SETTINGS)
  83.  
  84. var g_SD = "Standard Deviations"
  85. use_sd_1 = input.bool(true, "SD 1", inline = "SD1", tooltip = "The difference between the range high and low will be multiplied by this factor, added to the range high for the upper projection, and subtracted from the range low for the lower projection", group = g_SD)
  86. sd_1 = input.float(1, "", 0, inline = "SD1", group = g_SD)
  87. use_sd_2 = input.bool(true, "SD 2", inline = "SD2", tooltip = "The difference between the range high and low will be multiplied by this factor, added to the range high for the upper projection, and subtracted from the range low for the lower projection", group = g_SD)
  88. sd_2 = input.float(2, "", 0, inline = "SD2", group = g_SD)
  89. use_sd_3 = input.bool(true, "SD 3", inline = "SD3", tooltip = "The difference between the range high and low will be multiplied by this factor, added to the range high for the upper projection, and subtracted from the range low for the lower projection", group = g_SD)
  90. sd_3 = input.float(3, "", 0, inline = "SD3", group = g_SD)
  91. use_sd_4 = input.bool(true, "SD 4", inline = "SD4", tooltip = "The difference between the range high and low will be multiplied by this factor, added to the range high for the upper projection, and subtracted from the range low for the lower projection", group = g_SD)
  92. sd_4 = input.float(4, "", 0, inline = "SD4", group = g_SD)
  93.  
  94. var g_DRW = "Drawings"
  95. show_data = input.bool(false, "Data Table", tooltip = "Shows statistics on how often price exceeds X number of standard deviations from the range", group = g_DRW)
  96. vert_lines = input.bool(false, "Session Delineations", tooltip = "Draws vertical lines delineating the session beginning and ending times", group = g_DRW)
  97. show_labels = input.bool(true, "SD Labels", tooltip = "Shows the numerical value of each projection level", group = g_DRW)
  98. horiz_lines = input.bool(true, "SD Projection Lines", tooltip = "Extends the projections out in time", group = g_DRW)
  99. show_exceed = input.bool(false, "SD Projections Exceeded", tooltip = "Shows when price exceeds any of the projection levels", group = g_DRW)
  100.  
  101. var g_STY = "Style"
  102. range_box_color = input.color(color.new(color.blue, 70), "Range Box Color", group = g_STY)
  103. range_line_color = input.color(color.black, "Range Delineation Color", group = g_STY)
  104. label_color = input.color(#ffffff00, "SD Label Color", group = g_STY)
  105. label_text = input.color(color.black, "SD Label Text", group = g_STY)
  106. proj_color = input.color(color.new(color.gray, 70), "SD Projection Box Color", group = g_STY)
  107. proj_style = input.string('Dotted', "SD Projection Line Style", options = ['Solid', 'Dotted', 'Dashed'], group = g_STY)
  108. line_color = input.color(color.black, "SD Projection Line Color", group = g_STY)
  109. exceed_color = input.color(color.blue, "SD Exceeded Color", group = g_STY)
  110.  
  111. // -------------------------------------------------- Inputs --------------------------------------------------
  112.  
  113. // ---------------------------------------- Variables & Constants --------------------------------------------------
  114. t_co = not na(time("", cutoff, gmt_tz))
  115.  
  116. t_h1 = not na(time("", h1, gmt_tz))
  117. t_h2 = not na(time("", h2, gmt_tz))
  118.  
  119. t_v1 = not na(time("", v1, gmt_tz))
  120. t_v2 = not na(time("", v2, gmt_tz))
  121.  
  122. var as_hi_line = array.new_line()
  123. var as_lo_line = array.new_line()
  124. var lo_hi_line = array.new_line()
  125. var lo_lo_line = array.new_line()
  126. var na_hi_line = array.new_line()
  127. var na_lo_line = array.new_line()
  128. var nl_hi_line = array.new_line()
  129. var nl_lo_line = array.new_line()
  130. var np_hi_line = array.new_line()
  131. var np_lo_line = array.new_line()
  132.  
  133. var d_sep_line = array.new_line()
  134. var w_sep_line = array.new_line()
  135. var m_sep_line = array.new_line()
  136.  
  137. var d_line = array.new_line()
  138. var w_line = array.new_line()
  139. var m_line = array.new_line()
  140.  
  141. var h1_line = array.new_line()
  142. var h2_line = array.new_line()
  143. var h3_line = array.new_line()
  144. var h4_line = array.new_line()
  145.  
  146. var v1_line = array.new_line()
  147. var v2_line = array.new_line()
  148. var v3_line = array.new_line()
  149. var v4_line = array.new_line()
  150.  
  151. var d_label = array.new_label()
  152. var w_label = array.new_label()
  153. var m_label = array.new_label()
  154.  
  155. var h1_label = array.new_label()
  156. var h2_label = array.new_label()
  157. var h3_label = array.new_label()
  158. var h4_label = array.new_label()
  159.  
  160. var as_hi_label = array.new_label()
  161. var as_lo_label = array.new_label()
  162. var lo_hi_label = array.new_label()
  163. var lo_lo_label = array.new_label()
  164. var na_hi_label = array.new_label()
  165. var na_lo_label = array.new_label()
  166. var nl_hi_label = array.new_label()
  167. var nl_lo_label = array.new_label()
  168. var np_hi_label = array.new_label()
  169. var np_lo_label = array.new_label()
  170.  
  171. var as_box = array.new_box()
  172. var lo_box = array.new_box()
  173. var na_box = array.new_box()
  174. var nl_box = array.new_box()
  175. var np_box = array.new_box()
  176.  
  177. transparent = #ffffff00
  178.  
  179. d_o = request.security(syminfo.tickerid, "D", open, barmerge.gaps_off, barmerge.lookahead_on)
  180. w_o = request.security(syminfo.tickerid, "W", open, barmerge.gaps_off, barmerge.lookahead_on)
  181. m_o = request.security(syminfo.tickerid, "M", open, barmerge.gaps_off, barmerge.lookahead_on)
  182. // ---------------------------------------- Variables & Constants --------------------------------------------------
  183.  
  184. b_color = color.new(#000000,50)
  185.  
  186. lno = time('', '0800-1201', gmt_tz) and lno_ and timeframe.isintraday and timeframe.multiplier <= 60
  187. nyo = time('', '1300-1601', gmt_tz) and nyo_ and timeframe.isintraday and timeframe.multiplier <= 60
  188. lnc = time('', '1700-1901', gmt_tz) and lnc_ and timeframe.isintraday and timeframe.multiplier <= 60
  189. asb = time('', '0300-0701', gmt_tz) and asb_ and timeframe.isintraday and timeframe.multiplier <= 60
  190. cbdr = time('', '2100-0301', gmt_tz) and cbdr_ and timeframe.isintraday and timeframe.multiplier <= 60
  191.  
  192. bgcolor(lno and not lno_b and lno_? color.new(lno_c, spec) : na)
  193. bgcolor(nyo and not nyo_b and nyo_? color.new(nyo_c, spec) : na)
  194. bgcolor(lnc and not lnc_b and lnc_? color.new(lnc_c, spec) : na)
  195. bgcolor(asb and not asb_b and asb_? color.new(asb_c, spec) : na)
  196. bgcolor(cbdr and not cbdr_b and cbdr_? color.new(cbdr_c, spec) : na)
  197.  
  198. var box lno_box = na
  199. var box nyo_box = na
  200. var box lnc_box = na
  201. var box asb_box = na
  202. var box cbdr_box = na
  203. var box upper_cbdr_box =na
  204. var box lower_cbdr_box =na
  205.  
  206. var label lno_l = na
  207. var label nyo_l = na
  208. var label lnc_l = na
  209. var label asb_l = na
  210. var label cbdr_l = na
  211. var label upper_cbdr_l = na
  212. var label lower_cbdr_l = na
  213. // -------------------------------------------------- Constants & Variables --------------------------------------------------
  214. t = not na(time("", cbdr_session, gmt_tz))
  215. range_wick = range_type == 'Wick'
  216. range_high = (range_wick ? high : math.max(open, close))
  217. range_low = (range_wick ? low : math.min(open, close))
  218.  
  219. var range_size = array.new_float()
  220. var box range_box = na
  221. var box proj_p1 = na
  222. var box proj_m1 = na
  223. var box proj_p2 = na
  224. var box proj_m2 = na
  225. var box proj_p3 = na
  226. var box proj_m3 = na
  227. var box proj_p4 = na
  228. var box proj_m4 = na
  229. var int start = 0
  230. var int sessions = 0
  231. var bool valid_range = false
  232. var bool passed_p1 = false
  233. var bool passed_p2 = false
  234. var bool passed_p3 = false
  235. var bool passed_p4 = false
  236. var bool passed_m1 = false
  237. var bool passed_m2 = false
  238. var bool passed_m3 = false
  239. var bool passed_m4 = false
  240. var int count_p1 = 0
  241. var int count_p2 = 0
  242. var int count_p3 = 0
  243. var int count_p4 = 0
  244. var int count_m1 = 0
  245. var int count_m2 = 0
  246. var int count_m3 = 0
  247. var int count_m4 = 0
  248. var int count_a1 = 0
  249. var int count_a2 = 0
  250. var int count_a3 = 0
  251. var int count_a4 = 0
  252. var line line_p1 = na
  253. var line line_p2 = na
  254. var line line_p3 = na
  255. var line line_p4 = na
  256. var line line_m1 = na
  257. var line line_m2 = na
  258. var line line_m3 = na
  259. var line line_m4 = na
  260. // -------------------------------------------------- Constants & Variables --------------------------------------------------
  261. // ---------------------------------------- Functions --------------------------------------------------
  262. get_label_size(_size) =>
  263. result = switch _size
  264. 'Tiny' => size.tiny
  265. 'Small' => size.small
  266. 'Normal' => size.normal
  267. 'Large' => size.large
  268. 'Huge' => size.huge
  269. 'Auto' => size.auto
  270. result
  271.  
  272. get_line_type(_style) =>
  273. result = switch _style
  274. 'Solid' => line.style_solid
  275. 'Dotted' => line.style_dotted
  276. 'Dashed' => line.style_dashed
  277. result
  278.  
  279. get_box_color(_color, _transparency) =>
  280. result = color.new(_color, _transparency)
  281.  
  282. adjust(_hline, _lline, _hlabel, _llabel, _ulabel, _box) =>
  283. _hline.set_x2(bar_index)
  284. _lline.set_x2(bar_index)
  285. _box.set_right(bar_index)
  286.  
  287. if high > _hline.get_y1()
  288. _hline.set_xy1(bar_index, high)
  289. _hline.set_y2(high)
  290. _box.set_top(high)
  291.  
  292. _hlabel.set_x(bar_index)
  293. _hlabel.set_y(high)
  294. if low < _lline.get_y1()
  295. _lline.set_xy1(bar_index, low)
  296. _lline.set_y2(low)
  297. _box.set_bottom(low)
  298.  
  299. _llabel.set_x(bar_index)
  300. _llabel.set_y(low)
  301.  
  302. check_high(_line) =>
  303. result = false
  304. broke = false
  305. _line.set_x2(bar_index)
  306. if high > _line.get_y1()
  307. result := true
  308. broke := true
  309. else if (use_cutoff ? t_co : false)
  310. result := true
  311. [result, broke]
  312.  
  313. check_low(_line) =>
  314. result = false
  315. broke = false
  316. _line.set_x2(bar_index)
  317. if low < _line.get_y1()
  318. result := true
  319. broke := true
  320. else if (use_cutoff ? t_co : false)
  321. result := true
  322. [result, broke]
  323.  
  324. check_open(_line, _label) =>
  325. result = false
  326. _line.set_x2(bar_index)
  327. _label.set_x(bar_index)
  328. if (use_cutoff ? t_co : false)
  329. result := true
  330. result
  331.  
  332. check_array(_arr) =>
  333. if _arr.size() > max_days
  334. _arr.pop().delete()
  335. // ---------------------------------------- Functions --------------------------------------------------
  336. // -------------------------------------------------- Functions --------------------------------------------------
  337. manual_stdev() =>
  338. mean = range_size.avg()
  339. accum = 0.0
  340. size = range_size.size()
  341. if size > 0
  342. for i = 0 to size - 1
  343. accum += math.pow((range_size.get(i) - mean), 2)
  344. sd = math.sqrt(accum / size)
  345.  
  346. get_line_style(i) =>
  347. result = switch i
  348. 'Solid' => line.style_solid
  349. 'Dashed' => line.style_dashed
  350. 'Dotted' => line.style_dotted
  351. proj_style := get_line_style(proj_style)
  352.  
  353. // -------------------------------------------------- Functions --------------------------------------------------
  354. // ---------------------------------------- Core Logic --------------------------------------------------
  355. h_style := get_line_type(h_style)
  356. v_style := get_line_type(v_style)
  357. lb_size := get_label_size(lb_size)
  358.  
  359. var h1_co = false
  360. var h2_co = false
  361.  
  362. if lno_ and lno_b and timeframe.multiplier<=60 and timeframe.isintraday
  363. if lno and not lno[1]
  364. lno_box := box.new(bar_index,high,bar_index+1,low,b_color,bgcolor = color.new(lno_c,spec))
  365. if box_info
  366. lno_l := label.new(bar_index,high,str.tostring((high-low)/10/syminfo.mintick)+" pip",textcolor = #000000, size = size.small,style = label.style_none)
  367. if lno and lno[1]
  368. if high > box.get_top(lno_box)
  369. box.set_top(lno_box,high)
  370. if low < box.get_bottom(lno_box)
  371. box.set_bottom(lno_box,low)
  372. box.set_right(lno_box,bar_index+1)
  373. if box_info
  374. label.set_text(lno_l,str.tostring((box.get_top(lno_box)-box.get_bottom(lno_box))/10/syminfo.mintick)+" pip")
  375. label.set_x(lno_l,(box.get_left(lno_box)+box.get_right(lno_box))/2)
  376. label.set_y(lno_l,box.get_top(lno_box))
  377. if not lno and lno[1]
  378. box.set_right(lno_box,bar_index-1)
  379.  
  380. if nyo_ and nyo_b and timeframe.multiplier<=60 and timeframe.isintraday
  381. if nyo and not nyo[1]
  382. nyo_box := box.new(bar_index,high,bar_index+1,low,b_color,bgcolor = color.new(nyo_c,spec))
  383. if box_info
  384. nyo_l := label.new(bar_index,high,str.tostring((high-low)/10/syminfo.mintick)+" pip",textcolor = #000000, size = size.small,style = label.style_none)
  385. if nyo and nyo[1]
  386. if high > box.get_top(nyo_box)
  387. box.set_top(nyo_box,high)
  388. if low < box.get_bottom(nyo_box)
  389. box.set_bottom(nyo_box,low)
  390. box.set_right(nyo_box,bar_index+1)
  391. if box_info
  392. label.set_text(nyo_l,str.tostring((box.get_top(nyo_box)-box.get_bottom(nyo_box))/10/syminfo.mintick)+" pip")
  393. label.set_x(nyo_l,(box.get_left(nyo_box)+box.get_right(nyo_box))/2)
  394. label.set_y(nyo_l,box.get_top(nyo_box))
  395. if not nyo and nyo[1]
  396. box.set_right(nyo_box,bar_index-1)
  397.  
  398. if lnc_ and lnc_b and timeframe.multiplier<=60 and timeframe.isintraday
  399. if lnc and not lnc[1]
  400. lnc_box := box.new(bar_index,high,bar_index+1,low,b_color,bgcolor = color.new(lnc_c,spec))
  401. if box_info
  402. lnc_l := label.new(bar_index,high,str.tostring((high-low)/10/syminfo.mintick)+" pip",textcolor = #000000, size = size.small,style = label.style_none)
  403. if lnc and lnc[1]
  404. if high > box.get_top(lnc_box)
  405. box.set_top(lnc_box,high)
  406. if low < box.get_bottom(lnc_box)
  407. box.set_bottom(lnc_box,low)
  408. box.set_right(lnc_box,bar_index+1)
  409. if box_info
  410. label.set_text(lnc_l,str.tostring((box.get_top(lnc_box)-box.get_bottom(lnc_box))/10/syminfo.mintick)+" pip")
  411. label.set_x(lnc_l,(box.get_left(lnc_box)+box.get_right(lnc_box))/2)
  412. label.set_y(lnc_l,box.get_top(lnc_box))
  413. if not lnc and lnc[1]
  414. box.set_right(lnc_box,bar_index-1)
  415.  
  416. if asb_ and asb_b and timeframe.multiplier<=60 and timeframe.isintraday
  417. if asb and not asb[1]
  418. asb_box := box.new(bar_index,high,bar_index+1,low,b_color,bgcolor = color.new(asb_c,spec))
  419. if box_info
  420. asb_l := label.new(bar_index,high,str.tostring((high-low)/10/syminfo.mintick)+" pip",textcolor = #000000, size = size.small,style = label.style_none)
  421. if asb and asb[1]
  422. if high > box.get_top(asb_box)
  423. box.set_top(asb_box,high)
  424. if low < box.get_bottom(asb_box)
  425. box.set_bottom(asb_box,low)
  426. box.set_right(asb_box,bar_index+1)
  427. if box_info
  428. label.set_text(asb_l,str.tostring((box.get_top(asb_box)-box.get_bottom(asb_box))/10/syminfo.mintick)+" pip")
  429. label.set_x(asb_l,(box.get_left(asb_box)+box.get_right(asb_box))/2)
  430. label.set_y(asb_l,box.get_top(asb_box))
  431. if not asb and asb[1]
  432. box.set_right(asb_box,bar_index-1)
  433.  
  434. if cbdr_ and cbdr_b and timeframe.multiplier<=60 and timeframe.isintraday
  435. if cbdr and not cbdr[1]
  436. cbdr_box := box.new(bar_index,high,bar_index+1,low,b_color,bgcolor = color.new(cbdr_c,spec))
  437. if box_info
  438. cbdr_l := label.new(bar_index,high,str.tostring((high-low)/10/syminfo.mintick)+" pip",textcolor = #000000, size = size.small,style = label.style_none)
  439.  
  440. if cbdr and cbdr[1]
  441. if high > box.get_top(cbdr_box)
  442. box.set_top(cbdr_box,high)
  443.  
  444. if low < box.get_bottom(cbdr_box)
  445. box.set_bottom(cbdr_box,low)
  446.  
  447. box.set_right(cbdr_box,bar_index+1)
  448.  
  449. if box_info
  450. label.set_text(cbdr_l,str.tostring((box.get_top(cbdr_box)-box.get_bottom(cbdr_box))/10/syminfo.mintick)+" pip")
  451. label.set_x(cbdr_l,(box.get_left(cbdr_box)+box.get_right(cbdr_box))/2)
  452. label.set_y(cbdr_l,box.get_top(cbdr_box))
  453.  
  454. if not cbdr and cbdr[1]
  455. box.set_right(cbdr_box,bar_index-1)
  456.  
  457. // Vertical Lines
  458. if use_v1
  459. if t_v1 and not t_v1[1]
  460. v1_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v1_color))
  461. if use_v2
  462. if t_v2 and not t_v2[1]
  463. v2_line.unshift(line.new(bar_index, high, bar_index, low, style = v_style, width = v_width, extend = extend.both, color = v2_color))
  464.  
  465. // Horizontal Lines
  466. if use_h1 and timeframe.multiplier<=60
  467. if t_h1 and not t_h1[1]
  468. h1_co := false
  469. h1_line.unshift(line.new(bar_index, open, bar_index, open, style = h_style, width = h_width, color = h1_color))
  470. h1_label.unshift(label.new(bar_index, open, h1_text, style = label.style_label_left, color = transparent, textcolor = lb_color, size = lb_size))
  471. else if not t_h1 and h1_line.size() > 0
  472. if not h1_co
  473. if not check_open(h1_line.get(0), h1_label.get(0))
  474. h1_label.get(0).set_x(bar_index)
  475. else
  476. h1_co := true
  477. // -------------------------------------------------- CBDR projection logic --------------------------------------------------
  478. if t and not t[1]
  479. range_box := box.new(bar_index, range_high, bar_index+1, range_low, border_color = range_box_color, bgcolor = range_box_color)
  480. start := bar_index
  481. valid_range := false
  482. if vert_lines
  483. line.new(bar_index, high, bar_index, low, extend = extend.both, color = range_line_color)
  484. else if t
  485. range_box.set_right(bar_index+1)
  486. if range_high > range_box.get_top()
  487. range_box.set_top(range_high)
  488. if range_low < range_box.get_bottom()
  489. range_box.set_bottom(range_low)
  490. else if not t and t[1]
  491. top = range_box.get_top()
  492. bot = range_box.get_bottom()
  493. dif = top - bot
  494. range_size.push(dif)
  495. range_box := na
  496. line_p1 := na
  497. if vert_lines
  498. line.new(bar_index - 1, high, bar_index - 1, low, extend = extend.both, color = range_line_color)
  499.  
  500. if dif <= manual_stdev() * sd_limit
  501. valid_range := true
  502. sessions += 1
  503. if use_sd_1
  504. proj_p1 := box.new(start, top + dif * sd_1, bar_index , top, border_color = proj_color, bgcolor = proj_color)
  505. if show_labels
  506. label.new(bar_index, top + dif * sd_1, str.tostring(sd_1), textcolor = label_text, color = label_color, style = label.style_label_lower_left)
  507. if horiz_lines
  508. line_p1 := line.new(bar_index - 1, top + dif * sd_1, bar_index + 1, top + dif * sd_1, color = line_color, style = proj_style)
  509. if use_sd_2
  510. proj_p2 := box.new(start, top + dif * sd_2, bar_index , top + dif * sd_1, border_color = proj_color, bgcolor = proj_color)
  511. if show_labels
  512. label.new(bar_index, top + dif * sd_2, str.tostring(sd_2), textcolor = label_text, color = label_color, style = label.style_label_lower_left)
  513. if horiz_lines
  514. line_p2 := line.new(bar_index - 1, top + dif * sd_2, bar_index + 1, top + dif * sd_2, color = line_color, style = proj_style)
  515. if use_sd_3
  516. proj_p3 := box.new(start, top + dif * sd_3, bar_index, top + dif * sd_2, border_color = proj_color, bgcolor = proj_color)
  517. if show_labels
  518. label.new(bar_index, top + dif * sd_3, str.tostring(sd_3), textcolor = label_text, color = label_color, style = label.style_label_lower_left)
  519. if horiz_lines
  520. line_p3 := line.new(bar_index - 1, top + dif * sd_3, bar_index + 1, top + dif * sd_3, color = line_color, style = proj_style)
  521. if use_sd_4
  522. proj_p4 := box.new(start, top + dif * sd_4, bar_index, top + dif * sd_3, border_color = proj_color, bgcolor = proj_color)
  523. if show_labels
  524. label.new(bar_index, top + dif * sd_4, str.tostring(sd_4), textcolor = label_text, color = label_color, style = label.style_label_lower_left)
  525. if horiz_lines
  526. line_p4 := line.new(bar_index - 1, top + dif * sd_4, bar_index + 1, top + dif * sd_4, color = line_color, style = proj_style)
  527.  
  528. if use_sd_1
  529. proj_m1 := box.new(start, bot, bar_index, bot - dif * sd_1, border_color = proj_color, bgcolor = proj_color)
  530. if show_labels
  531. label.new(bar_index, bot - dif * sd_1, "-" + str.tostring(sd_1), textcolor = label_text, color = label_color, style = label.style_label_upper_left)
  532. if horiz_lines
  533. line_m1 := line.new(bar_index - 1, bot - dif * sd_1, bar_index + 1, bot - dif * sd_1, color = line_color, style = proj_style)
  534. if use_sd_2
  535. proj_m2 := box.new(start, bot - dif * sd_1, bar_index, bot - dif * sd_2, border_color = proj_color, bgcolor = proj_color)
  536. if show_labels
  537. label.new(bar_index, bot - dif * sd_2, "-" + str.tostring(sd_2), textcolor = label_text, color = label_color, style = label.style_label_upper_left)
  538. if horiz_lines
  539. line_m2 := line.new(bar_index - 1, bot - dif * sd_2, bar_index + 1, bot - dif * sd_2, color = line_color, style = proj_style)
  540. if use_sd_3
  541. proj_m3 := box.new(start, bot - dif * sd_2, bar_index, bot - dif * sd_3, border_color = proj_color, bgcolor = proj_color)
  542. if show_labels
  543. label.new(bar_index, bot - dif * sd_3, "-" + str.tostring(sd_3), textcolor = label_text, color = label_color, style = label.style_label_upper_left)
  544. if horiz_lines
  545. line_m3 := line.new(bar_index - 1, bot - dif * sd_3, bar_index + 1, bot - dif * sd_3, color = line_color, style = proj_style)
  546. if use_sd_4
  547. proj_m4 := box.new(start, bot - dif * sd_3, bar_index, bot - dif * sd_4, border_color = proj_color, bgcolor = proj_color)
  548. if show_labels
  549. label.new(bar_index, bot - dif * sd_4, "-" + str.tostring(sd_4), textcolor = label_text, color = label_color, style = label.style_label_upper_left)
  550. if horiz_lines
  551. line_m4 := line.new(bar_index - 1, bot - dif * sd_4, bar_index + 1, bot - dif * sd_4, color = line_color, style = proj_style)
  552. else if not t
  553. if horiz_lines and not na(line_p1)
  554. line_p1.set_x2(bar_index + 1)
  555. line_p2.set_x2(bar_index + 1)
  556. line_p3.set_x2(bar_index + 1)
  557. line_p4.set_x2(bar_index + 1)
  558.  
  559. line_m1.set_x2(bar_index + 1)
  560. line_m2.set_x2(bar_index + 1)
  561. line_m3.set_x2(bar_index + 1)
  562. line_m4.set_x2(bar_index + 1)
  563.  
  564. if not t and valid_range
  565. if high > proj_p1.get_top() and not passed_p1
  566. passed_p1 := true
  567. if show_exceed
  568. label.new(bar_index, proj_p1.get_top(), str.tostring(sd_1), style = label.style_label_down, color = exceed_color, textcolor = label_text)
  569. if high > proj_p2.get_top() and not passed_p2
  570. passed_p2 := true
  571. if show_exceed
  572. label.new(bar_index, proj_p2.get_top(), str.tostring(sd_2), style = label.style_label_down, color = exceed_color, textcolor = label_text)
  573. if high > proj_p3.get_top() and not passed_p3
  574. passed_p3 := true
  575. if show_exceed
  576. label.new(bar_index, proj_p3.get_top(), str.tostring(sd_3), style = label.style_label_down, color = exceed_color, textcolor = label_text)
  577. if high > proj_p4.get_top() and not passed_p4
  578. passed_p4 := true
  579. if show_exceed
  580. label.new(bar_index, proj_p4.get_top(), str.tostring(sd_4), style = label.style_label_down, color = exceed_color, textcolor = label_text)
  581.  
  582. if low < proj_m1.get_bottom() and not passed_m1
  583. passed_m1 := true
  584. if show_exceed
  585. label.new(bar_index, proj_m1.get_bottom(), "-" + str.tostring(sd_1), style = label.style_label_up, color = exceed_color, textcolor = label_text)
  586. if low < proj_m2.get_bottom() and not passed_m2
  587. passed_m2 := true
  588. if show_exceed
  589. label.new(bar_index, proj_m2.get_bottom(), "-" + str.tostring(sd_2), style = label.style_label_up, color = exceed_color, textcolor = label_text)
  590. if low < proj_m3.get_bottom() and not passed_m3
  591. passed_m3 := true
  592. if show_exceed
  593. label.new(bar_index, proj_m3.get_bottom(), "-" + str.tostring(sd_3), style = label.style_label_up, color = exceed_color, textcolor = label_text)
  594. if low < proj_m4.get_bottom() and not passed_m4
  595. passed_m4 := true
  596. if show_exceed
  597. label.new(bar_index, proj_m4.get_bottom(), "-" + str.tostring(sd_4), style = label.style_label_up, color = exceed_color, textcolor = label_text)
  598.  
  599. else if t and not t[1]
  600. if passed_p1 or passed_m1
  601. count_a1 += 1
  602. if passed_p2 or passed_m2
  603. count_a2 += 1
  604. if passed_p3 or passed_m3
  605. count_a3 += 1
  606. if passed_p4 or passed_m4
  607. count_a4 += 1
  608.  
  609. passed_p1 := false
  610. passed_p2 := false
  611. passed_p3 := false
  612. passed_p4 := false
  613.  
  614. passed_m1 := false
  615. passed_m2 := false
  616. passed_m3 := false
  617. passed_m4 := false
  618. // -------------------------------------------------- Core Logic --------------------------------------------------
  619.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement