xmd79

ICT Killzones by Mozi

Sep 29th, 2022
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.25 KB | None | 0 0
  1. //@version=5
  2. indicator("ICT Killzones by Mozi", overlay = true)
  3.  
  4. // Default color constants using tranparency of 25.
  5. LONDON_COLOR = #FFFFFF03
  6. NEWYORK_COLOR = #FFFFFF03
  7. DAY_END_COLOR = #FFFFFF03
  8. NEWYORKLUNCH_COLOR = #FF000006
  9. NO_COLOR = color(na)
  10. VERTICAL_LINE = #FFFFFF35
  11. JUDAS_COLOR = color.yellow
  12.  
  13. // FUNCTIONS
  14. in_session(sess) =>
  15. not na(time(timeframe.period, sess))
  16.  
  17. start_time(sess) =>
  18. int startTime = na
  19. startTime := in_session(sess) and not in_session(sess)[1] ? time : startTime[1]
  20. startTime
  21.  
  22. is_new_session(res, sess) =>
  23. t = time(res, sess)
  24. na(t[1]) and not na(t) or t[1] < t
  25.  
  26. BarInSession(sess) =>
  27. time(timeframe.period, sess) != 0
  28.  
  29. _hline(StartTime, EndTime, Price, Color, Style, Width) =>
  30. return_1 = line.new(StartTime, Price, EndTime, Price, xloc=xloc.bar_time, extend=extend.none, color=Color, style=Style, width=Width)
  31.  
  32.  
  33.  
  34. // Allow user to change the colors.
  35. londonKillzone = input.color(LONDON_COLOR, "London Killzone", group="Color Settings")
  36. newYorkKillzone = input.color(NEWYORK_COLOR, "New York Killzone", group="Color Settings")
  37. newYorkLunchTime = input.color(NEWYORKLUNCH_COLOR, "New York Lunch", group="Color Settings")
  38. dayEndColor = input.color(DAY_END_COLOR, "Daily End Color", group="Color Settings")
  39.  
  40. // Function returns `true` when the bar's time is
  41. timeInRange(tf, session) => time(tf, session) != 0
  42.  
  43. showKillzones = input(true, title="Show Killzones?", group="Default Settings")
  44. var chartIs30MinOrLess = timeframe.isseconds or (timeframe.isintraday and timeframe.multiplier <=30)
  45. sessionColor = if chartIs30MinOrLess and showKillzones
  46. switch
  47. timeInRange(timeframe.period, input.session(title='London Killzone', defval='0200-0500', group="Time Settings")) => londonKillzone
  48. timeInRange(timeframe.period, input.session(title='New York Killzone', defval='0700-1000', group="Time Settings")) => newYorkKillzone
  49. timeInRange(timeframe.period, input.session(title="New York Lunch", defval="1200-1300", group="Time Settings")) => newYorkLunchTime
  50. timeInRange(timeframe.period, input.session(title="Daily End Rallye", defval="1500-1600", group="Time Settings")) => dayEndColor
  51.  
  52. bgcolor(sessionColor)
  53.  
  54.  
  55. asiashow = input(true, title="Show Asia Range?", group="Default Settings")
  56. asiacolor = input(color.new(color.white, 90), 'Asia Range Color', group="Color Settings")
  57. asiabordercolor = color.new(color.white, 100)
  58. asia = input.session(title='Asia Session', defval='2000-0001', group="Time Settings")
  59.  
  60. //ASIA BOX
  61. asia_session = is_new_session('1440', asia)
  62.  
  63. float _asialow = na
  64. float _asiahigh = na
  65. _asiabox = box(na)
  66.  
  67. _asiastart = start_time(asia)
  68. _asialow := asia_session ? low : in_session(asia) ? math.min(low, _asialow[1]) : na
  69. _asiahigh := asia_session ? high : in_session(asia) ? math.max(high, _asiahigh[1]) : na
  70.  
  71. if in_session(asia)
  72. if in_session(asia)[1]
  73. box.delete(_asiabox[1])
  74.  
  75. if low < _asialow
  76. _asialow := low
  77. _asialow
  78. if high > _asiahigh
  79. _asiahigh := high
  80. _asiahigh
  81.  
  82. if asiashow
  83. _asiabox := box.new(_asiastart, _asiahigh, time, _asialow, xloc=xloc.bar_time, bgcolor=asiacolor, border_color=asiabordercolor, border_style=line.style_solid)
  84. _asiabox
  85.  
  86.  
  87.  
  88.  
  89. // Judas Swing
  90.  
  91. float _midnightopen = na
  92.  
  93. //midnight = input.session(title='Midnight Opening Price', defval='0000-0005', group="Time Settings")
  94. //midnight_session = is_new_session('1440', midnight)
  95. //_midnight = start_time(midnight)
  96. //_midnightopen := midnight_session ? open : in_session(midnight) ? open : na
  97.  
  98.  
  99. judasshow = input(true, title="Show Judas Swing?", group="Default Settings", tooltip="It only highlights the time when the Judas Swing usually occurs, not the actual Judas Swing. You need to check on your charts, if there is a Judas Swing or not.")
  100. judascolor = input(color.new(color.yellow, 95), 'Judas Swing Color', group="Color Settings")
  101. judasbordercolor = color.new(color.white, 100)
  102. judas = input.session(title='Judas Swing Time', defval='0000-0500', group="Time Settings")
  103.  
  104. judas_session = is_new_session('1440', judas)
  105.  
  106. float _judaslow = na
  107. float _judashigh = na
  108. _judasbox = box(na)
  109.  
  110. _judasstart = start_time(judas)
  111. _judaslow := judas_session ? low : in_session(judas) ? math.min(low, _judaslow[1]) : na
  112. _judashigh := judas_session ? high : in_session(judas) ? math.max(high, _judashigh[1]) : na
  113.  
  114. if in_session(judas)
  115. if in_session(judas)[1]
  116. box.delete(_judasbox[1])
  117.  
  118. if low < _judaslow
  119. _judaslow := low
  120. _judaslow
  121. if high > _judashigh
  122. _judashigh := high
  123. _judashigh
  124.  
  125. if judasshow
  126. _judasbox := box.new(_judasstart, _judashigh, time, _judaslow, xloc=xloc.bar_time, bgcolor=judascolor, border_color=judasbordercolor, border_style=line.style_solid)
  127. _judasbox
  128.  
  129.  
  130. // MARK NON-FARM PAYROLL FRIDAYS
  131. NONPAYROLLFRIDAYCOLOR = #a8325610
  132. nonPayRollFridayColor = input.color(NONPAYROLLFRIDAYCOLOR, "Non-Farm Payroll Color", group="Color Settings")
  133. nonPayRollFridayShow = input(true, title="Show Non-Farm Payroll Fridays?", group="Default Settings")
  134.  
  135.  
  136. bgColor = nonPayRollFridayColor
  137.  
  138. if dayofweek == dayofweek.friday and dayofmonth < 7 and nonPayRollFridayShow
  139. bgColor := nonPayRollFridayColor
  140. else
  141. bgColor := na
  142.  
  143. bgcolor(bgColor)
  144. plotshape(dayofweek == dayofweek.friday and dayofmonth < 7 and hour == 1 and minute == 30 and nonPayRollFridayShow ? true : false, text="NFP Friday", color=na, offset=0, style=shape.circle, location = location.top, textcolor=color.yellow, size=size.normal, editable=false)
  145.  
  146.  
  147.  
  148. // HOLIDAYS IN EUROPE AND US
  149. HOLIDAY_COLOR = #ff000008
  150. holidayColor = input.color(HOLIDAY_COLOR, "Holiday Color", group="Color Settings")
  151. holidayShow = input(true, title="Highlight Holidays?", group="Default Settings")
  152.  
  153. hYear = array.new_int(0)
  154. hMonth = array.new_int(0)
  155. hDay = array.new_int(0)
  156. hName = array.new_string(0)
  157.  
  158. _title= ""
  159. _year = 0
  160. _month = 0
  161. _day = 0
  162. _date = timestamp("5 Sep 2022 05:00")
  163.  
  164.  
  165. // US HOLIDAYS
  166. // New Years Day
  167. _date := input.time(timestamp("1 Jan 2022 05:00"), title="New Year's Day", group="US Holidays")
  168. _year := year(_date)
  169. _month := month(_date)
  170. _day := dayofmonth(_date)
  171. array.push(hYear, _year)
  172. array.push(hMonth, _month)
  173. array.push(hDay, _day)
  174. array.push(hName, "New Year's Day")
  175.  
  176. // Martin Luther King Jr. Day
  177. _date := input.time(timestamp("17 Jan 2022 05:00"), title="Martin Luther King Jr. Day", group="US Holidays")
  178. _year := year(_date)
  179. _month := month(_date)
  180. _day := dayofmonth(_date)
  181. array.push(hYear, _year)
  182. array.push(hMonth, _month)
  183. array.push(hDay, _day)
  184. array.push(hName, "Martin Luther King Jr. Day")
  185.  
  186. // Washington's Birthday
  187. _date := input.time(timestamp("21 Feb 2022 05:00"), title="Washington's Birthday", group="US Holidays")
  188. _year := year(_date)
  189. _month := month(_date)
  190. _day := dayofmonth(_date)
  191. array.push(hYear, _year)
  192. array.push(hMonth, _month)
  193. array.push(hDay, _day)
  194. array.push(hName, "Washington's Birthday")
  195.  
  196. // Memorial Day
  197. _date := input.time(timestamp("30 May 2022 05:00"), title="Memorial Day", group="US Holidays")
  198. _year := year(_date)
  199. _month := month(_date)
  200. _day := dayofmonth(_date)
  201. array.push(hYear, _year)
  202. array.push(hMonth, _month)
  203. array.push(hDay, _day)
  204. array.push(hName, "Memorial Day")
  205.  
  206. // Juneteenth National Independence Day
  207. _date := input.time(timestamp("19 Jun 2022 05:00"), title="Juneteenth Independence Day", group="US Holidays")
  208. _year := year(_date)
  209. _month := month(_date)
  210. _day := dayofmonth(_date)
  211. array.push(hYear, _year)
  212. array.push(hMonth, _month)
  213. array.push(hDay, _day)
  214. array.push(hName, "Juneteenth National Independence Day")
  215.  
  216. // Juneteenth National Independence Day
  217. _date := input.time(timestamp("4 Jul 2022 05:00"), title="Independence Day", group="US Holidays")
  218. _year := year(_date)
  219. _month := month(_date)
  220. _day := dayofmonth(_date)
  221. array.push(hYear, _year)
  222. array.push(hMonth, _month)
  223. array.push(hDay, _day)
  224. array.push(hName, "Independence Day")
  225.  
  226. // Labor Day
  227. _date := input.time(timestamp("5 Sep 2022 05:00"), title="Labor Day", group="US Holidays")
  228. _year := year(_date)
  229. _month := month(_date)
  230. _day := dayofmonth(_date)
  231. array.push(hYear, _year)
  232. array.push(hMonth, _month)
  233. array.push(hDay, _day)
  234. array.push(hName, "Labor Day")
  235.  
  236. // Veterans Day US
  237. _date := input.time(timestamp("9 Nov 2022 05:00"), title="Veterans Day US", group="US Holidays")
  238. _year := year(_date)
  239. _month := month(_date)
  240. _day := dayofmonth(_date)
  241. array.push(hYear, _year)
  242. array.push(hMonth, _month)
  243. array.push(hDay, _day)
  244. array.push(hName, "Veterans Day US")
  245.  
  246. // Thanksgiving
  247. _date := input.time(timestamp("24 Nov 2022 05:00"), title="Thanksgiving", group="US Holidays")
  248. _year := year(_date)
  249. _month := month(_date)
  250. _day := dayofmonth(_date)
  251. array.push(hYear, _year)
  252. array.push(hMonth, _month)
  253. array.push(hDay, _day)
  254. array.push(hName, "Thanksgiving")
  255.  
  256. // Christmas Day
  257. _date := input.time(timestamp("25 Dec 2022 05:00"), title="Christmas Day", group="US Holidays")
  258. _year := year(_date)
  259. _month := month(_date)
  260. _day := dayofmonth(_date)
  261. array.push(hYear, _year)
  262. array.push(hMonth, _month)
  263. array.push(hDay, _day)
  264. array.push(hName, "Christmas Day")
  265.  
  266.  
  267. // UK HOLIDAYS
  268.  
  269. // Queen II Funeral UK
  270. array.push(hYear, 2022)
  271. array.push(hMonth, 9)
  272. array.push(hDay, 19)
  273. array.push(hName, "Queen II Funeral")
  274.  
  275. // New Years Day
  276. _date := input.time(timestamp("3 Jan 2022 05:00"), title="New Year's Day", group="UK Holidays")
  277. _year := year(_date)
  278. _month := month(_date)
  279. _day := dayofmonth(_date)
  280. array.push(hYear, _year)
  281. array.push(hMonth, _month)
  282. array.push(hDay, _day)
  283. array.push(hName, "New Year's Day")
  284.  
  285. // Good Friday
  286. _date := input.time(timestamp("15 Apr 2022 05:00"), title="Good Friday", group="UK Holidays")
  287. _year := year(_date)
  288. _month := month(_date)
  289. _day := dayofmonth(_date)
  290. array.push(hYear, _year)
  291. array.push(hMonth, _month)
  292. array.push(hDay, _day)
  293. array.push(hName, "Good Friday")
  294.  
  295. // Easter Monday
  296. _date := input.time(timestamp("18 Apr 2022 05:00"), title="Easter Monday", group="UK Holidays")
  297. _year := year(_date)
  298. _month := month(_date)
  299. _day := dayofmonth(_date)
  300. array.push(hYear, _year)
  301. array.push(hMonth, _month)
  302. array.push(hDay, _day)
  303. array.push(hName, "Easter Monday")
  304.  
  305. // Early May
  306. _date := input.time(timestamp("2 May 2022 05:00"), title="Early May", group="UK Holidays")
  307. _year := year(_date)
  308. _month := month(_date)
  309. _day := dayofmonth(_date)
  310. array.push(hYear, _year)
  311. array.push(hMonth, _month)
  312. array.push(hDay, _day)
  313. array.push(hName, "Early May")
  314.  
  315. // Spring Bank Holiday
  316. _date := input.time(timestamp("2 Jun 2022 05:00"), title="Spring Bank Holiday", group="UK Holidays")
  317. _year := year(_date)
  318. _month := month(_date)
  319. _day := dayofmonth(_date)
  320. array.push(hYear, _year)
  321. array.push(hMonth, _month)
  322. array.push(hDay, _day)
  323. array.push(hName, "Spring Bank Holiday")
  324.  
  325. // Summer Bank Holiday
  326. _date := input.time(timestamp("29 Aug 2022 05:00"), title="Summer Bank Holiday", group="UK Holidays")
  327. _year := year(_date)
  328. _month := month(_date)
  329. _day := dayofmonth(_date)
  330. array.push(hYear, _year)
  331. array.push(hMonth, _month)
  332. array.push(hDay, _day)
  333. array.push(hName, "Summer Bank Holiday")
  334.  
  335. // Christmas Day
  336. _date := input.time(timestamp("27 Dec 2022 05:00"), title="Christmas Day", group="UK Holidays")
  337. _year := year(_date)
  338. _month := month(_date)
  339. _day := dayofmonth(_date)
  340. array.push(hYear, _year)
  341. array.push(hMonth, _month)
  342. array.push(hDay, _day)
  343. array.push(hName, "Christmas Day")
  344.  
  345. // Boxing Day
  346. _date := input.time(timestamp("28 Dec 2022 05:00"), title="Boxing Day", group="UK Holidays")
  347. _year := year(_date)
  348. _month := month(_date)
  349. _day := dayofmonth(_date)
  350. array.push(hYear, _year)
  351. array.push(hMonth, _month)
  352. array.push(hDay, _day)
  353. array.push(hName, "Boxing Day")
  354.  
  355.  
  356. pYear = 0
  357. pMonth = 0
  358. pDay = 0
  359. pName = ""
  360. t = time(timeframe.period, "0000-0001")
  361. for i = 0 to array.size(hYear) -1
  362. pYear := array.get(hYear, i)
  363. pMonth := array.get(hMonth, i)
  364. pDay := array.get(hDay, i)
  365. pName := array.get(hName, i)
  366.  
  367.  
  368. if year == pYear and month == pMonth and dayofmonth == pDay and holidayShow
  369. bgColor := holidayColor
  370.  
  371. if year == pYear and month == pMonth and dayofmonth == pDay and (not na(t)) and holidayShow
  372. label.new(bar_index, high, pName, color=color.blue, textcolor=color.white, yloc=yloc.abovebar)
  373.  
  374. bgcolor(bgColor)
  375.  
  376.  
  377.  
  378.  
Advertisement
Add Comment
Please, Sign In to add comment