xmd79

ICT Session Killzone Boxes & Deviations

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