Advertisement
xmd79

ICT Session Killzone Boxes & Deviations

Jan 12th, 2023
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.77 KB | None | 0 0
  1. //@version=5
  2. //@Shanxia
  3. // NOTE: Only works on 1HR and below and exchange timezones differ so change the session times accordingly.
  4. //
  5. indicator("ICT Session Killzone Boxes & Deviations", "ICT KZs", true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
  6.  
  7. // INPUTS
  8. i_time = input.session ('0000-0001:1234567', "New York", tooltip="Different exchanges will have difference time zones so change accordingly.")
  9. i_maxtf = input.int (15, "Max TF", 1, 240)
  10. i_vline = input.bool (true, "VLine", inline="in3")
  11. i_vcol = input.color (#01de93, "", inline="in3")
  12. i_vstyle = input.string ("Solid", "", options=["Solid", "Dotted", "Dashed"], inline="in3")
  13. i_txtcol = input.color (#0098ff, " Text Col", inline="in3")
  14.  
  15.  
  16. i_hline = input.bool (true, "HLine", inline="in1")
  17. i_linecol = input.color (#0064ff, "", inline="in1")
  18. i_linestyle = input.string ("Dotted", "", options=["Solid", "Dotted", "Dashed"], inline="in1")
  19. i_ex = input.string ("None", "", options=["None", "+1 Day", "Right", "Both"], inline="in1")
  20.  
  21. i_shf = input.bool (true, "Upcoming Sessions", inline="in4")
  22. i_lonstyle = input.string ("Dotted", " ", options=["Solid", "Dotted", "Dashed"], inline="in4")
  23.  
  24.  
  25. i_rshow = input.bool (true, title='Boxes', inline='x1')
  26. i_dev = input.bool (false, 'Deviations', inline='x1')
  27. i_devno = input.int (2 , "", minval=1, inline='x1')
  28.  
  29. i_pips = input.bool (true, "Box Info")
  30.  
  31. i_bool1 = input.bool (true, "", inline='x2', group="Sessions")
  32. i_bool2 = input.bool (true, "", inline='x3', group="Sessions")
  33. i_bool3 = input.bool (true, "", inline='x4', group="Sessions")
  34. i_bool4 = input.bool (true, "", inline='x5', group="Sessions")
  35. i_bool5 = input.bool (true, "", inline='x6', group="Sessions")
  36.  
  37.  
  38. cbdr = input.session ('1400-2001:1234567', "" , inline='x2', tooltip="CBDR", group="Sessions")
  39. asia = input.session ('2000-2201:1234567', "", inline='x3', tooltip="Asia", group="Sessions")
  40. london = input.session ('0200-0501:1234567', "", inline='x4', tooltip="London", group="Sessions")
  41. nysesh = input.session ('0700-1001:1234567', "", inline='x5', tooltip="New York", group="Sessions")
  42. lcsesh = input.session ('1100-1301:1234567', "", inline='x6', tooltip="London Close", group="Sessions")
  43. i_vcbdr = input.color (color.new(#0064ff, 0), "", inline='x2', group="Sessions")
  44. i_vasia = input.color (color.new(#7622ff, 0), "", inline='x3', group="Sessions")
  45. i_vlon = input.color (color.new(#e90000, 0), "", inline='x4', group="Sessions")
  46. i_vny = input.color (color.new(#00cbff, 0), "", inline='x5', group="Sessions")
  47. i_lc = input.color (color.new(color.silver, 0),"", inline='x6', group="Sessions")
  48.  
  49. i_btc = input.bool (true, "Box Text", inline="x7", group="Sessions")
  50. i_tcb = input.color (color.new(color.gray, 80), "", inline="x7", group="Sessions")
  51.  
  52. i_d1 = input.bool ( false, "Day of week labels", inline="in14", tooltip="The timezone(TZ) can be adjusted below", group="Labels")
  53. i_d2 = input.color ( #d1d4dc, "|", inline="in14", group="Labels")
  54. i_d3 = input.int ( 3, "  Offset", inline="in15", group="Labels")
  55. i_d4 = input.string ( "GMT+10", "TZ", options=["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-1", "GMT-2", "GMT-3","GMT-4","GMT","GMT-6","GMT-7","GMT-8","GMT-9","GMT-10","GMT-11","GMT-12"], inline="in15", group="Labels")
  56.  
  57.  
  58. //INPUTS END
  59.  
  60. // MISC
  61. nymid = time ("1", i_time, 'GMT-4')
  62. linestyle = i_linestyle == "Solid" ? line.style_solid : i_linestyle == "Dotted" ? line.style_dotted : line.style_dashed
  63. lonstyle = i_lonstyle == "Solid" ? line.style_solid : i_lonstyle == "Dotted" ? line.style_dotted : line.style_dashed
  64. vstyle = i_vstyle == "Solid" ? line.style_solid : i_vstyle == "Dotted" ? line.style_dotted : line.style_dashed
  65. ex = i_ex == "None" ? extend.none : i_ex == "+1 Day" ? extend.none : i_ex == "Right" ? extend.right : extend.both
  66. htime = i_ex == "+1 Day" ? 172800000 : 86400000
  67. dow = dayofweek == dayofweek.friday ? 259200000 : 86400000
  68. dow2 = dayofweek == dayofweek.friday ? 172800000 : 86400000 //this is for asia coming out of weekend
  69. dow3 = dayofweek == dayofweek.friday ? 172800000 : 0
  70.  
  71.  
  72. disp = timeframe.isintraday and timeframe.multiplier <= i_maxtf
  73. // CALC
  74. var openprice = 0.0
  75. if nymid
  76. if not nymid[1]
  77. openprice := open
  78. else
  79. openprice := math.max(open, openprice)
  80.  
  81.  
  82.  
  83. // FUNCTIONS
  84.  
  85. in_session(sess) =>
  86. not na(time(timeframe.period, sess, 'GMT-4'))
  87.  
  88. start_time(sess) =>
  89. int startTime = na
  90. startTime := in_session(sess) and not in_session(sess)[1] ? time : startTime[1]
  91. startTime
  92.  
  93. is_new_session(res, sess) =>
  94. t = time(res, sess, "GMT-4")
  95. na(t[1]) and not na(t) or t[1] < t
  96.  
  97. BarInSession(sess) =>
  98. time(timeframe.period, sess, 'GMT-4') != 0
  99.  
  100. _hline(StartTime, EndTime, Price, Color, Style, Width) =>
  101. return_1 = line.new(StartTime, Price, EndTime, Price, xloc=xloc.bar_time, extend=extend.none, color=Color, style=Style, width=Width)
  102.  
  103.  
  104. pip(x) =>
  105. forex = syminfo.type == "forex" ? syminfo.mintick * 10 : na
  106. x / forex
  107.  
  108. forex = syminfo.type == "forex"
  109.  
  110. // OBJECTS
  111. var label lb = na
  112. if openprice != openprice[1] and i_hline and disp
  113. var line lne = na
  114. line.set_x2(lne, nymid)
  115. line.set_extend(lne, extend.none)
  116. lne := line.new(nymid, openprice, nymid + htime + dow3, openprice, xloc.bar_time, ex, i_linecol, linestyle, 2)
  117. lb := label.new(nymid + htime + dow3, openprice, "NY Midnight Open | " + str.tostring(math.round_to_mintick(openprice)), xloc.bar_time, yloc.price, na, label.style_none, i_txtcol)
  118. label.delete(lb[1])
  119.  
  120.  
  121. f_vline(a, b, d, e, sess) =>
  122. var line fl1 = na
  123. var line fl2 = na
  124. var linefill lf1 = na
  125. st_vl = timestamp("GMT-4", year, month, sess, a, 00, 00)
  126. en_vl = timestamp("GMT-4", year, month, sess, b, e, 00)
  127. fl1 := line.new(st_vl, high, st_vl, low, xloc.bar_time, extend.both, d, lonstyle, 1)
  128. line.delete(fl1[1])
  129. fl2 := line.new(en_vl, high, en_vl, low, xloc.bar_time, extend.both, d, lonstyle, 1)
  130. line.delete(fl2[1])
  131. lf1 := linefill.new(fl1, fl2, color.new(d, 90))
  132. linefill.delete(lf1[1])
  133. for i = 0 to 100
  134. if time > line.get_x1(fl2[i])
  135. line.delete(fl2[i])
  136. line.delete(fl1[i])
  137.  
  138. if i_shf and disp
  139. f_vline(02, 05, i_vlon, 00, dayofmonth)
  140. f_vline(07, 10, i_vny, 00, dayofmonth)
  141. f_vline(11, 13, i_lc, 00, dayofmonth)
  142. f_vline(14, 20, i_vcbdr, 00, dayofmonth)
  143. f_vline(20, 22, i_vasia, 00, dayofmonth)
  144. f_vline(02, 05, i_vlon, 00, dayofmonth + 1)
  145. f_vline(07, 10, i_vny, 00, dayofmonth + 1)
  146. f_vline(11, 13, i_lc, 00, dayofmonth + 1)
  147. f_vline(14, 20, i_vcbdr, 00, dayofmonth + 1)
  148. f_vline(20, 22, i_vasia, 00, dayofmonth + 1)
  149.  
  150. //BOXes
  151.  
  152. isnewday = time("D") != time("D")[1]
  153. ictbox(kz, bdcol,txt, x)=>
  154. sesh = is_new_session('1440', kz)
  155. float kzlow = na
  156. float kzhigh = na
  157. float kzbodlow = na
  158. float kzbodhigh = na
  159.  
  160. kzbox = box(na)
  161. bline = line(na)
  162. bline2 = line(na)
  163. _lbl = label(na)
  164. kzstart = start_time(kz)
  165. dow4 = dayofweek(kzstart, i_d4)
  166. kzlow := sesh ? low : in_session(kz) ? math.min(low, kzlow[1]) : na
  167. kzhigh := sesh ? high : in_session(kz) ? math.max(high, kzhigh[1]) : na
  168. kzbodlow := sesh ? open : in_session(kz) ? math.min(open, kzbodlow[1]) : na
  169. kzbodhigh := sesh ? open : in_session(kz) ? math.max(open, kzbodhigh[1]) : na
  170. devdiff = kzbodhigh[1] - kzbodlow[1]
  171. tgdist = kzhigh - kzlow
  172. dol = (time - kzstart) / 2
  173.  
  174.  
  175. if in_session(kz)
  176. if in_session(kz)[1]
  177. box.delete(kzbox[1])
  178. line.delete(bline[1])
  179. line.delete(bline2[1])
  180. label.delete(_lbl[1])
  181. if low < kzlow
  182. kzlow := low
  183. kzlow
  184. if high > kzhigh
  185. kzhigh := high
  186. kzhigh
  187.  
  188. if x
  189. kzbox := box.new(kzstart, kzbodhigh, time, kzbodlow, color.new(bdcol, 50), 1, line.style_solid, extend.none, xloc.bar_time, color.new(bdcol,85), i_btc ? txt : na, size.auto, i_tcb, text_wrap=text.wrap_auto)
  190. kzbox
  191. bline := line.new(kzstart, kzhigh, time, kzhigh, xloc.bar_time, extend.none, bdcol, line.style_dashed, 1)
  192. bline
  193. bline2 := line.new(kzstart, kzlow, time, kzlow, xloc.bar_time, extend.none, bdcol, line.style_dashed, 1)
  194. bline2
  195. dtext = dow4 == 1 ? "Sun • " : dow4 == 2 ? "Mon • " : dow4 == 3 ? "Tue • " : dow4 == 4 ? "Wed • " : dow4 == 5 ? "Thu • " : dow4 == 6 ? "Fri • " : dow4 == 7 ? "Sat • " : na
  196. rtext = dtext + str.tostring(forex ? math.round(pip(tgdist)) : math.round_to_mintick(tgdist)) + (forex ? " pips" : " pts")
  197. if i_pips
  198. _lbl := label.new(kzstart + dol, kzhigh, rtext, xloc.bar_time, yloc.price, na, textcolor = i_txtcol, size = size.normal,textalign = text.align_right, style=label.style_none)
  199.  
  200. tz = time - time[1]
  201. if i_dev and not in_session(kz) and in_session(kz)[1] and x
  202. for s = 1 to i_devno by 1
  203. _hline(kzstart, time - 1 * tz, kzbodhigh[1] + devdiff * s, bdcol, line.style_solid, 1)
  204. _hline(kzstart, time - 1 * tz, kzbodlow[1] - devdiff * s, bdcol, line.style_solid, 1)
  205.  
  206. if disp and i_rshow
  207. ictbox(asia, i_vasia, "Asia", i_bool2)
  208. ictbox(cbdr, i_vcbdr, "CBDR", i_bool1)
  209. ictbox(london, i_vlon, "London", i_bool3)
  210. ictbox(nysesh, i_vny, "NY", i_bool4)
  211. ictbox(lcsesh, i_lc, "London \n Close", i_bool5)
  212.  
  213. if i_vline and nymid == nymid and disp
  214. line.new(nymid + dow, high, nymid + dow, low, xloc.bar_time, extend.both, i_vcol, vstyle, 1)
  215.  
  216.  
  217. //END
  218.  
  219. //Day of week
  220.  
  221.  
  222. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.monday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "MON", i_d2, false, size.tiny)
  223. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.tuesday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "TUE", i_d2, false, size.tiny)
  224. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.wednesday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "WED", i_d2, false, size.tiny)
  225. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.thursday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "THU", i_d2, false, size.tiny)
  226. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.friday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "FRI", i_d2, false, size.tiny)
  227. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.saturday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "SAT", i_d2, false, size.tiny)
  228. plotshape(i_d1 ? ta.change(time('D')) and dayofweek(time, i_d4) == dayofweek.sunday : na, "", shape.circle, location.bottom, color.new(color.black,100), i_d3, "SUN", i_d2, false, size.tiny)
  229.  
  230.  
  231.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement