xmd79

dmn's ICT Toolkit

Dec 5th, 2022
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.58 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. // © fxdmn
  3. // @version=5
  4. indicator(title="dmn's ICT Toolkit", shorttitle="dmn's ICT Toolkit", overlay=true, max_lines_count=500)
  5. // ███████╗██╗ ██╗██████╗ ███╗ ███╗███╗ ██╗
  6. // ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║████╗ ██║
  7. // █████╗ ╚███╔╝ ██║ ██║██╔████╔██║██╔██╗ ██║
  8. // ██╔══╝ ██╔██╗ ██║ ██║██║╚██╔╝██║██║╚██╗██║
  9. // ██║ ██╔╝ ██╗██████╔╝██║ ╚═╝ ██║██║ ╚████║
  10. // ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝
  11.  
  12.  
  13. //{ Constants
  14. var CBDR_SESSION = "1400-2000"
  15. var FLOUT_SESSION = "1500-2359"
  16. var ASIA_SESSION = "2000-2400"
  17. var TRUEDAY_SESSION = "0000-0001"
  18. var DAILY_OPEN_SESSION = "1700-1704"
  19. var LONDON_OPEN_KILLZONE_SESSION = "0200-0500"
  20. var NY_OPEN_KILLZONE_SESSION = "0830-1100"
  21. var LONDON_CLOSE_KILLZONE_SESSION = "1000-1130"
  22. var CBDR_LABEL_NAME = "CBDR"
  23. var FLOUT_LABEL_NAME = "Flout"
  24. var ASIA_LABEL_NAME = "AR"
  25.  
  26. var TT_ADR_LOOKBACK_INPUT = "Number of closed candles used to calculate the ADR"
  27. var TT_SESSION_ZONE_INPUT = "Change if not displaying New York midnight correctly"
  28. var TT_TABLE_LOC_INPUT = "Shows x days average daily range, current daily range, CBDR range and Asian range"
  29. var TT_ADR_DYNAMIC_TEXT = "Colors the ADR box information dynamically based on the ranges. Readable using most sensible background colors. Disabling this option will make the text black or white depending on percieved brighness of the background color"
  30. var DECIMALS = int(math.log10(1/syminfo.mintick))
  31. var PIP = math.pow(10, DECIMALS-1)
  32. //}
  33. //{ Inputs
  34. sessionZoneInput = input.string('GMT-5', title='New York Time Zone', tooltip=TT_SESSION_ZONE_INPUT, options=['GMT-11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-2', 'GMT-1', 'GMT', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+4', 'GMT+5', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11', 'GMT+12'])
  35. //{ ADR inputs
  36. adrLookbackInput = input.int(5, "ADR Lookback", 1, tooltip=TT_ADR_LOOKBACK_INPUT)
  37. tableBgInput = input.color(color.new(#ffffff, 5), "", inline="table")
  38. tableLocInput = input.string("Top Right", "", ["Top Left", "Bottom Left", "Top Right", "Bottom Right"], TT_TABLE_LOC_INPUT, inline="table")
  39. tableToggleInput = input.bool(true, "Daily stat box", "", inline="table")
  40. tableDynamicTextInputToggle = input.bool(true, "Dynamic Text Color", TT_ADR_DYNAMIC_TEXT, inline="table")
  41. //}
  42. //{ CBDR Box inputs
  43. cbdrBoxColorInput = input.color(color.new(color.green, 85), "", group="CBDR", inline="CBDR_show")
  44. cbdrBoxToggleInput = input.bool(true,"Box", group="CBDR", inline="CBDR_show")
  45. cbdrHistoryInput = input.bool(true, "History", group="CBDR", inline="CBDR_show")
  46. cbdrBorderColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_border")
  47. cbdrBorderSizeInput = input.int(1, "Border", minval=0, maxval=3, group="CBDR", inline="CBDR_border")
  48. cbdrBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="CBDR", inline="CBDR_border")
  49. cbdrLabelColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_label")
  50. cbdrRangeToggleInput = input.bool(true,"Pips", group="CBDR", inline="CBDR_label")
  51. cbdrNameToggleInput = input.bool(false,"Name", group="CBDR", inline="CBDR_label")
  52. cbdrProjectionColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_ext")
  53. cbdrProjectionToggleInput = input.bool(false, "Std. Deviations", group="CBDR", inline="CBDR_ext")
  54. cbdrProjectionHistoryInput = input.bool(false, "History", group="CBDR", inline="CBDR_ext")
  55. //}
  56. //{ Flout Box inputs
  57. floutBoxColorInput = input.color(color.rgb(76, 122, 175, 85), "", group="flout", inline="flout_show")
  58. floutToggleInput = input.bool(false,"Box", group="flout", inline="flout_show")
  59. floutHistoryToggleInput = input.bool(true, "History", group="flout", inline="flout_show")
  60. floutBorderColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="flout_border")
  61. floutBorderSizeInput = input.int(1, "Border", minval=0, maxval=3, group="flout", inline="flout_border")
  62. floutBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="flout", inline="flout_border")
  63. floutLabelColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="flout_label")
  64. floutRangeToggleInput = input.bool(true,"Pips", group="flout", inline="flout_label")
  65. floutNameToggleInput = input.bool(false,"Name", group="flout", inline="flout_label")
  66. floutProjectionColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="floutExt")
  67. floutProjectionToggleInput = input.bool(false, "Std. Deviations", group="flout", inline="floutExt")
  68. floutProjectionHistoryInput = input.bool(false, "History", group="flout", inline="floutExt")
  69. //}
  70. //{ Asia Box inputs
  71. asiaBoxColorInput = input.color(color.new(color.purple, 85), "", group="AR", inline="asia_show")
  72. asiaToggleInput = input.bool(true,"Box", group="AR", inline="asia_show")
  73. asiaHistoryInput = input.bool(true, "History", group="AR", inline="asia_show")
  74. asiaBorderColorInput = input.color(color.purple, "", group="AR", inline="AR_border")
  75. asiaBorderSizeInput = input.int(1, "Border", minval=0, maxval=3,group="AR", inline="AR_border")
  76. asiaBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="AR", inline="AR_border")
  77. asiaLabelColorInput = input.color(color.purple, "", group="AR", inline="asia_label")
  78. asiaRangeToggleInput = input.bool(true,"Pips", group="AR", inline="asia_label")
  79. asiaNameToggleInput = input.bool(false,"Name", group="AR", inline="asia_label")
  80. asiaProjectionColorInput = input.color(color.purple, "", group="AR", inline="asiaExt")
  81. asiaProjectionToggle = input.bool(false, "Std. Deviations", group="AR", inline="asiaExt")
  82. asiaProjectionHistoryInput = input.bool(false, "History", group="AR", inline="asiaExt")
  83. //}
  84. //{ Trueday inputs
  85. truedayColorInput = input.color(color.new(#838383, 18), "", group="Levels and Lines", inline="trueDay")
  86. truedayWidthInput = input.int(1, "", 1, 3, group="Levels and Lines", inline="trueDay")
  87. truedayTypeInput = input.string("Dashed", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="trueDay")
  88. truedayToggleInput = input.bool(true,"True Day", inline="trueDay", group="Levels and Lines")
  89. truedayHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="trueDay")
  90.  
  91. midnightColorInput = input.color(color.new(#ffcb3b, 5), "", group="Levels and Lines", inline="midnight")
  92. midnightWidthInput = input.int(2, "", 1, 3, group="Levels and Lines", inline="midnight")
  93. midnightTypeInput = input.string("Solid", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="midnight")
  94. midnightToggleInput = input.bool(true,"Midnight", inline="midnight", group="Levels and Lines")
  95. midnightHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="midnight")
  96.  
  97. dailyOpenColorInput = input.color(color.new(#e75845, 5), "", group="Levels and Lines", inline="daily")
  98. dailyOpenWidthInput = input.int(2, "", 1, 3, group="Levels and Lines", inline="daily")
  99. dailyOpenTypeInput = input.string("Solid", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="daily")
  100. dailyOpenToggleInput = input.bool(false,"Daily Open", inline="daily", group="Levels and Lines")
  101. dailyOpenHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="daily")
  102. //}
  103. //{ Killzone inputs
  104. killzoneToggleInput = input.bool(true, "Killzones", group="Killzones", inline="kzToggle")
  105. killzoneHistoryToggleInput = input.bool(true, "History", group="Killzones", inline="kzToggle")
  106. killzoneLondonOpenColorInput = input.color(color.new(#515cbb, 5), "", group="Killzones", inline="kzLO")
  107. killzoneLondonOpenSessionInput = input.session(LONDON_OPEN_KILLZONE_SESSION, "", group="Killzones", inline="kzLO")
  108. killzoneLondonOpenToggleInput = input.bool(true, "London", group="Killzones", inline="kzLO")
  109. killzoneNyColorInput = input.color(color.new(#f3c547, 5), "", group="Killzones", inline="kzNY")
  110. killzoneNyOpenSessionInput = input.session(NY_OPEN_KILLZONE_SESSION, "", group="Killzones", inline="kzNY")
  111. killzoneNyToggleInput = input.bool(true, "New York", group="Killzones", inline="kzNY")
  112. killzoneLondonCloseColorInput = input.color(color.new(#515cbb, 5), "", group="Killzones", inline="kzLC")
  113. killzoneLondonCloseSessionInput = input.session(LONDON_CLOSE_KILLZONE_SESSION, "", group="Killzones", inline="kzLC")
  114. killzoneLondonCloseToggleInput = input.bool(true, "London Close", group="Killzones", inline="kzLC")
  115. //}
  116. //}
  117. //{ FUNCTIONS
  118. hours(int h, int m=0) =>
  119. //@function Returns UNIX time a certain number hours from now.
  120. //@param h (int) number of hours
  121. //@param m (int) (optional) number of minutes
  122. time+(3600000*h)+(60000*m)
  123.  
  124. stringToHour(s) =>
  125. //@function Converts session input strings to integers for using with the hours() function
  126. //@param s session string
  127. //@return (int) hours part of the session string input parameter
  128. math.round(str.tonumber(str.substring(s, 0, 2)))
  129.  
  130. stringToMinutes(s) =>
  131. //@function Converts session input strings to integers for using with the hours() function
  132. //@param s session string
  133. //@return (int) minutes part of the session string input parameter
  134. math.round(str.tonumber(str.substring(s, 2, 4)))
  135.  
  136. averageRange(h, l, n) =>
  137. //@function Calculate the average range in pips of a number of bars
  138. //@param h = high, l = low, n = number of bars
  139. r = 0.0
  140. for i = 1 to n
  141. r += h[i]-l[i]
  142. PIP*r/n
  143.  
  144. addLines(a, x1, x2, y, c, n) =>
  145. //@function Adds horizonal lines to a line array
  146. //@param a = array id, x1 & x2 = x coordinates, y = y coordinate, c = color, n = number of lines
  147. for i=0 to n-1
  148. array.push(a, line.new(x1, y, x2, y, xloc=xloc.bar_time, color=c, style=line.style_solid, width=1))
  149.  
  150. delLines(a) =>
  151. //@function Delete all lines in a line array
  152. //@param a = line array
  153. if array.size(a) > 0
  154. for i=0 to array.size(a)-1
  155. line.delete(array.get(a, i))
  156.  
  157. setLineArrayY(a, y, spacing, m) =>
  158. //@function moves all lines in a line array and space them based on a range, starting at y, m=1 for upward spacing, -1 for downward
  159. //@param a = line array, y = y coordinate to start from, spacing = distance between lines, m = upward or downward spacing (+/-1)
  160. for [i, l] in a
  161. float step=(i+1) * spacing * m
  162. line.set_y1(l, y+step)
  163. line.set_y2(l, y+step)
  164.  
  165.  
  166. lineset_y(l, y) =>
  167. //@function Makes a line horizontal at a location.abovebar
  168. //@param l = line id, y = y coordinate
  169. line.set_y1(l, y)
  170. line.set_y2(l, y)
  171.  
  172.  
  173.  
  174. inSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
  175. //@function Checks if a session is active
  176. //@param SessionTime = session start and end, sessionTimeZone = optional timezone parameter
  177. not na(time(timeframe.period, sessionTime, sessionTimeZone))
  178.  
  179.  
  180. getBrightness(color c) =>
  181. //@function Calculates percieved brightness of a color
  182. //@param c (color)
  183. //@returns (float) brightness of c between 0 and 255
  184. r = color.r(c)
  185. g = color.g(c)
  186. b = color.b(c)
  187. math.sqrt(r*r*0.241 + g*g*0.691 + b*b*0.068)
  188. //}
  189. //{ CBDR vars
  190. var cbdrHighPrice = 0.0
  191. var cbdrLowPrice = 0.0
  192. var cbdrRange = 0.0
  193. var box cbdrBox = na
  194. var cbdrBorderStyle = cbdrBorderTypeInput == "Solid" ? line.style_solid : cbdrBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  195. var label cbdrLabel = na
  196. var cbdrLabelText = cbdrNameToggleInput and cbdrRangeToggleInput ? CBDR_LABEL_NAME + ": " : cbdrNameToggleInput ? CBDR_LABEL_NAME : ""
  197. var array<line> cbdrLinesHi = array.new<line>()
  198. var array<line> cbdrLinesLo = array.new<line>()
  199. //}
  200. //{ Flout vars
  201. var floutHighPrice = 0.0
  202. var floutLowPrice = 0.0
  203. var floutRange = 0.0
  204. var box floutBox = na
  205. var floutBorderStyle = floutBorderTypeInput == "Solid" ? line.style_solid : floutBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  206. var label floutLabel = na
  207. var floutLabelText = floutNameToggleInput and floutRangeToggleInput ? FLOUT_LABEL_NAME + ": " : floutNameToggleInput ? FLOUT_LABEL_NAME : ""
  208. var line floutLineMid = na
  209. var array<line> floutLinesHi = array.new<line>()
  210. var array<line> floutLinesLo = array.new<line>()
  211. //}
  212. //{ Asian vars
  213. var asiaHighPrice = 0.0
  214. var asiaLowPrice = 0.0
  215. var asiaRange = 0.0
  216. var box asiaBox = na
  217. var asiaBorderStyle = asiaBorderTypeInput == "Solid" ? line.style_solid : asiaBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  218. var label asiaLabel = na
  219. var asiaLabelText = asiaNameToggleInput and asiaRangeToggleInput ? ASIA_LABEL_NAME + ": " : asiaNameToggleInput ? ASIA_LABEL_NAME : ""
  220. var array<line> asiaLinesHi = array.new<line>()
  221. var array<line> asiaLinesLo = array.new<line>()
  222. //}
  223. //{ Trueday vars
  224. var truedayOpenPrice = 0.0
  225. var truedayHighPrice = 0.0
  226. var truedayLowPrice = 0.0
  227. var label truedayLabel = na
  228. var line truedayLine = na
  229. var line midnightLine = na
  230. var killzoneHighPrice = 0.0
  231. var killzoneLowPrice = 0.0
  232. var line kzLoLine1 = na
  233. var line kzLoLine2 = na
  234. var line kzNYLine1 = na
  235. var line kzNYLine2 = na
  236. var line kzLCLine1 = na
  237. var line kzLCLine2 = na
  238. var dailyOpenPrice = 0.0
  239. var line dailyOpenLine = na
  240. var truedayStyle = truedayTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  241. var midnightStyle = midnightTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  242. var dailyOpenStyle = dailyOpenTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
  243. //}
  244. //{ Killzone vars
  245. var LONDON_OPEN_KILLZONE_START = str.substring(killzoneLondonOpenSessionInput, 0, 4)
  246. var LONDON_OPEN_KILLZONE_END = str.substring(killzoneLondonOpenSessionInput, 5, 9)
  247. var NY_OPEN_KILLZONE_START = str.substring(killzoneNyOpenSessionInput, 0, 4)
  248. var NY_OPEN_KILLZONE_END = str.substring(killzoneNyOpenSessionInput, 5, 9)
  249. var LONDON_CLOSE_KILLZONE_START = str.substring(killzoneLondonCloseSessionInput, 0, 4)
  250. var LONDON_CLOSE_KILLZONE_END = str.substring(killzoneLondonCloseSessionInput, 5, 9)
  251. //}
  252. //{ Session Start checks
  253. inCbdrSession = inSession(CBDR_SESSION, sessionZoneInput) and timeframe.isintraday
  254. cbdrStart = inCbdrSession and not inCbdrSession[1]
  255.  
  256. inFloutSession = inSession(FLOUT_SESSION, sessionZoneInput) and timeframe.isintraday
  257. floutStart = inFloutSession and not inFloutSession[1]
  258.  
  259. inasiaSession = inSession(ASIA_SESSION, sessionZoneInput) and timeframe.isintraday
  260. asiaStart = inasiaSession and not inasiaSession[1]
  261.  
  262. intruedaySession = inSession(TRUEDAY_SESSION, sessionZoneInput) and timeframe.isintraday
  263. truedayStart = intruedaySession and not intruedaySession[1]
  264.  
  265. indailyOpenSession = inSession(DAILY_OPEN_SESSION, sessionZoneInput) and timeframe.isintraday
  266. dailyOpenStart = indailyOpenSession and not indailyOpenSession[1]
  267.  
  268. inkzLOSession = inSession(killzoneLondonOpenSessionInput, sessionZoneInput) and timeframe.isintraday
  269. kzLOStart = inkzLOSession and not inkzLOSession[1]
  270.  
  271. inkzNySession = inSession(killzoneNyOpenSessionInput, sessionZoneInput) and timeframe.isintraday
  272. kzNyStart = inkzNySession and not inkzNySession[1]
  273.  
  274. inkzLcSession = inSession(killzoneLondonCloseSessionInput, sessionZoneInput) and timeframe.isintraday
  275. kzLcStart = inkzLcSession and not inkzLcSession[1]
  276.  
  277. if cbdrStart //are we at the start of a CBDR?
  278. if not cbdrHistoryInput //is CBDR history off?
  279. box.delete(cbdrBox) //
  280. label.delete(cbdrLabel) //then delete previous boxes and labels
  281.  
  282. if not cbdrProjectionHistoryInput or not cbdrHistoryInput //is CBDR Projection history off OR CBDR history off?
  283. delLines(cbdrLinesHi) //
  284. delLines(cbdrLinesLo) //then delete previous CBDR projections
  285.  
  286. array.clear(cbdrLinesHi) //
  287. array.clear(cbdrLinesLo) //Clean up the CBDR Line arrays
  288.  
  289. cbdrHighPrice := high //
  290. cbdrLowPrice := low //Set the initial high and low of the CBDR
  291.  
  292. cbdrRange := 0.0 //
  293. asiaRange := 0.0 //Reset the range of the CBDR and Asian Range
  294.  
  295. else if inCbdrSession //are we in the CBDR session?
  296. cbdrHighPrice := math.max(cbdrHighPrice, high) //
  297. cbdrLowPrice := math.min(cbdrLowPrice, low) //check for new high and low
  298. cbdrRange := (PIP*(cbdrHighPrice-cbdrLowPrice)) //calculate the CBDR and convert to pips
  299.  
  300. if floutStart
  301. if not floutHistoryToggleInput //is flout history off?
  302. box.delete(floutBox) //
  303. label.delete(floutLabel) //then delete previous boxes and labels
  304.  
  305. if not floutProjectionHistoryInput or not floutHistoryToggleInput //is flout Projection history off OR flout history off?
  306. line.delete(floutLineMid)
  307. delLines(floutLinesHi) //
  308. delLines(floutLinesLo) //then delete previous flout projections
  309.  
  310. array.clear(floutLinesHi) //
  311. array.clear(floutLinesLo) //Clean up the flout Line arrays
  312.  
  313. floutHighPrice := high //
  314. floutLowPrice := low //reset flout high and low
  315. else if inFloutSession //are we already in the flout?
  316. floutHighPrice := math.max(floutHighPrice, high) //check for new flout high
  317. floutLowPrice := math.min(floutLowPrice, low) //check for new flout low
  318. floutRange := PIP*(floutHighPrice-floutLowPrice) //calculate current flout range and convert to pips
  319.  
  320. if asiaStart //are we at the start of a new asian range?
  321. if not asiaHistoryInput //is asian range history off?
  322. box.delete(asiaBox) //
  323. label.delete(asiaLabel) //then delete previous boxes and labels
  324.  
  325. if not asiaProjectionHistoryInput or not asiaHistoryInput //is asian range rrojection history off OR asian range history off?
  326. delLines(asiaLinesHi) //
  327. delLines(asiaLinesLo) //then delete previous asian range projections
  328.  
  329. array.clear(asiaLinesHi) //
  330. array.clear(asiaLinesLo) //Clean up the asian Line arrays
  331. asiaHighPrice := high //
  332. asiaLowPrice := low //reset asian range high and low
  333. else if inasiaSession //are we already in the asian range?
  334. asiaHighPrice := math.max(asiaHighPrice, high) //check for new asian range high
  335. asiaLowPrice := math.min(asiaLowPrice, low) //check for new asian range low
  336. asiaRange := (PIP*(asiaHighPrice-asiaLowPrice)) //calculate current asian range and convert to pips
  337.  
  338. if dailyOpenStart
  339. if not dailyOpenHistoryToggleInput
  340. line.delete(dailyOpenLine)
  341. if dailyOpenToggleInput
  342. dailyOpenLine := line.new(time, open, dayofweek(time) == 6 ? hours(72) : hours(24), open, xloc=xloc.bar_time, color=dailyOpenColorInput, style=dailyOpenStyle, width=dailyOpenWidthInput)
  343.  
  344. if truedayStart //are we at the start of a new true day?
  345. if not midnightHistoryToggleInput
  346. line.delete(midnightLine)
  347. if not truedayHistoryToggleInput
  348. line.delete(truedayLine)
  349. if not killzoneHistoryToggleInput //is killzone history off?
  350. line.delete(kzLoLine1) //
  351. line.delete(kzLoLine2) //
  352. line.delete(kzLCLine1) //
  353. line.delete(kzLCLine2) //
  354. line.delete(kzNYLine1) //
  355. line.delete(kzNYLine2) //then delete previous killzone lines
  356.  
  357. killzoneHighPrice := high //
  358. killzoneLowPrice := low //reset killzone line levels
  359. if killzoneToggleInput //are killzones enabled?
  360. if killzoneLondonOpenToggleInput //is london killzone enabled?
  361. kzLoLine1 := line.new(hours(stringToHour(LONDON_OPEN_KILLZONE_START), stringToMinutes(LONDON_OPEN_KILLZONE_START)),
  362. killzoneHighPrice,
  363. hours(stringToHour(LONDON_OPEN_KILLZONE_END), stringToMinutes(LONDON_OPEN_KILLZONE_END)),
  364. killzoneHighPrice, xloc=xloc.bar_time, color=killzoneLondonOpenColorInput, style=line.style_solid, width=4)
  365. kzLoLine2 := line.copy(kzLoLine1) //draw london open killzone lines from it's start to end
  366. if killzoneNyToggleInput //is new york killzone enabled?
  367. kzNYLine1 := line.new(hours(stringToHour(NY_OPEN_KILLZONE_START), stringToMinutes(NY_OPEN_KILLZONE_START)),
  368. killzoneHighPrice,
  369. hours(stringToHour(NY_OPEN_KILLZONE_END), stringToMinutes(NY_OPEN_KILLZONE_END)),
  370. killzoneHighPrice, xloc=xloc.bar_time, color=killzoneNyColorInput, style=line.style_solid, width=4)
  371. kzNYLine2 := line.copy(kzNYLine1) //draw new york open killzone lines from it's start to end
  372. if killzoneLondonCloseToggleInput //is london close killzone enabled?
  373. kzLCLine1 := line.new(hours(stringToHour(LONDON_CLOSE_KILLZONE_START), stringToMinutes(LONDON_CLOSE_KILLZONE_START)),
  374. killzoneHighPrice,
  375. hours(stringToHour(LONDON_CLOSE_KILLZONE_END), stringToMinutes(LONDON_CLOSE_KILLZONE_END)),
  376. killzoneHighPrice, xloc=xloc.bar_time, color=killzoneLondonCloseColorInput, style=line.style_solid, width=4)
  377. kzLCLine2 := line.copy(kzLCLine1) //draw london close killzone lines from it's start to end
  378.  
  379. if midnightToggleInput //draw the new york midnight price level line if it's enabled
  380. midnightLine := line.new(time, open, dayofweek(time) == 6 ? hours(72) : hours(24), open, xloc=xloc.bar_time, color=midnightColorInput, style=midnightStyle, width=midnightWidthInput)
  381. if truedayToggleInput //draw the true day deliniation if enabled
  382. truedayLine := line.new(time, open, time, open+1, xloc=xloc.bar_time, extend=extend.both, color=truedayColorInput, style=truedayStyle, width=truedayWidthInput)
  383.  
  384.  
  385.  
  386.  
  387. //}
  388. //{ Draw stuff
  389. if cbdrStart and cbdrBoxToggleInput
  390. cbdrBox := box.new(bar_index, na, na, na, cbdrBorderColorInput, cbdrBorderSizeInput, cbdrBorderStyle, bgcolor=cbdrBoxColorInput)
  391. cbdrLabel := label.new(bar_index, high, "", style=label.style_none, textcolor=cbdrLabelColorInput, textalign=text.align_center)
  392. if cbdrProjectionToggleInput
  393. s = dayofweek == 6 ? hours(54) : hours(6)
  394. h = dayofweek == 6 ? hours(72) : hours(24)
  395. addLines(cbdrLinesHi, s, h, high, cbdrProjectionColorInput, 4)
  396. addLines(cbdrLinesLo, s, h, high, cbdrProjectionColorInput, 4)
  397.  
  398. if floutStart and floutToggleInput
  399. floutBox := box.new(bar_index, na, na, na, floutBorderColorInput, floutBorderSizeInput, floutBorderStyle, bgcolor=floutBoxColorInput)
  400. floutLabel := label.new(bar_index, high, "", xloc.bar_time, style=label.style_none, textcolor=floutLabelColorInput, textalign=text.align_center)
  401. if floutProjectionToggleInput
  402. s = dayofweek == 6 ? hours(57) : hours(9)
  403. h = dayofweek == 6 ? hours(71) : hours(23)
  404. floutLineMid :=line.new(s, high, h, high, xloc.bar_time, color=floutProjectionColorInput, style=line.style_dashed, width=1)
  405. addLines(floutLinesHi, s, h, high, floutProjectionColorInput, 4)
  406. addLines(floutLinesLo, s, h, high, floutProjectionColorInput, 4)
  407.  
  408. if asiaStart and asiaToggleInput
  409. asiaBox := box.new(bar_index, na, na, na, asiaBorderColorInput, asiaBorderSizeInput, asiaBorderStyle, bgcolor=asiaBoxColorInput)
  410. asiaLabel := label.new(bar_index, high, "", style=label.style_none, textcolor=asiaLabelColorInput, textalign=text.align_center)
  411. if asiaProjectionToggle
  412. s = hours(4) // length of asian range session in hours
  413. h = dayofweek == 6 ? hours(66) : hours(18) // hours until next asian rage session
  414. addLines(asiaLinesHi, s, h, high, asiaProjectionColorInput, 4)
  415. addLines(asiaLinesLo, s, h, high, asiaProjectionColorInput, 4)
  416.  
  417.  
  418. //}
  419. //{ Update drawn stuff
  420. if inCbdrSession and cbdrBoxToggleInput
  421. true_cbdr = cbdrHighPrice-cbdrLowPrice
  422. box.set_top(cbdrBox, cbdrHighPrice)
  423. box.set_bottom(cbdrBox, cbdrLowPrice)
  424. box.set_right(cbdrBox, bar_index + 1)
  425. label.set_text(cbdrLabel, cbdrRangeToggleInput ? cbdrLabelText + str.tostring(cbdrRange) : cbdrLabelText)
  426. label.set_x(cbdrLabel, bar_index)
  427. label.set_y(cbdrLabel, cbdrHighPrice)
  428. setLineArrayY(cbdrLinesHi, cbdrHighPrice, true_cbdr, 1)
  429. setLineArrayY(cbdrLinesLo, cbdrLowPrice, true_cbdr, -1)
  430.  
  431. if inFloutSession and floutToggleInput
  432. true_flout = (floutHighPrice-floutLowPrice)/2
  433. box.set_top(floutBox, floutHighPrice)
  434. box.set_bottom(floutBox, floutLowPrice)
  435. box.set_right(floutBox, bar_index + 1)
  436. label.set_text(floutLabel, floutRangeToggleInput ? floutLabelText + str.tostring(floutRange) : floutLabelText)
  437. label.set_x(floutLabel, hours(-1))
  438. label.set_y(floutLabel, floutHighPrice)
  439. lineset_y(floutLineMid, floutHighPrice-true_flout)
  440. setLineArrayY(floutLinesHi, floutHighPrice, true_flout, 1)
  441. setLineArrayY(floutLinesLo, floutLowPrice, true_flout, -1)
  442.  
  443. if inasiaSession and asiaToggleInput
  444. true_asia = asiaHighPrice-asiaLowPrice
  445. box.set_top(asiaBox, asiaHighPrice)
  446. box.set_bottom(asiaBox, asiaLowPrice)
  447. box.set_right(asiaBox, bar_index + 1)
  448. label.set_text(asiaLabel, asiaRangeToggleInput ? asiaLabelText + str.tostring(asiaRange) : asiaLabelText)
  449. label.set_x(asiaLabel, bar_index-1)
  450. label.set_y(asiaLabel, asiaHighPrice)
  451. setLineArrayY(asiaLinesHi, asiaHighPrice, true_asia, 1)
  452. setLineArrayY(asiaLinesLo, asiaLowPrice, true_asia, -1)
  453. //}
  454. //{ Killzone lines
  455. killzoneHighPrice := math.max(killzoneHighPrice, high)
  456. killzoneLowPrice := math.min(killzoneLowPrice, low)
  457. lineset_y(kzLoLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
  458. lineset_y(kzLoLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
  459.  
  460. lineset_y(kzNYLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
  461. lineset_y(kzNYLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
  462.  
  463. lineset_y(kzLCLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
  464. lineset_y(kzLCLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
  465. //}
  466. //{ ADR Table
  467. averageDailyRangeRounded = math.round(request.security(syminfo.tickerid, "1D", averageRange(high, low, adrLookbackInput)),1) //set average daily range for the past 'adrLookbackInput' number of days and round it
  468. [currentDailyLow, currentDailyHigh] = request.security(syminfo.tickerid, "1D", [low, high]) //get current daily high and low
  469. currentDailyRangeRounded = math.round(PIP*(currentDailyHigh-currentDailyLow),1) //set current daily range and round it
  470.  
  471. if tableToggleInput
  472. tablePosition = tableLocInput == "Top Left" ? position.top_left : tableLocInput == "Bottom Left" ? position.bottom_left : tableLocInput == "Top Right" ? position.top_right : position.bottom_right
  473. adrTable = table.new(tablePosition, 2, 4, tableBgInput, border_width = 1)
  474. bgBrightness = getBrightness(tableBgInput)
  475. color staticTextColor = bgBrightness > 130 ? color.black : color.white
  476. color dynamicGreen = staticTextColor
  477. color dynamicRed = staticTextColor
  478. color dynamicOrange = staticTextColor
  479. color currentDailyRangeColor = staticTextColor
  480.  
  481. if tableDynamicTextInputToggle
  482. dynamicGreen := bgBrightness > 130 ? color.green : color.rgb(0, 255, 0)
  483. dynamicRed := bgBrightness > 130 ? color.rgb(155, 0, 0) : color.rgb(255, 0, 0)
  484. dynamicOrange := bgBrightness > 130 ? color.rgb(255, 152, 0) : color.rgb(255, 200, 0)
  485. currentDailyRangeColor := currentDailyRangeRounded/averageDailyRangeRounded < 0.5 ? dynamicGreen : currentDailyRangeRounded/averageDailyRangeRounded < 1.0 ? dynamicOrange : dynamicRed
  486.  
  487. if adrLookbackInput and barstate.islast
  488. table.cell(adrTable, 0, 0, str.tostring(adrLookbackInput) + "ADR:", text_color=staticTextColor, text_halign = text.align_right)
  489. table.cell(adrTable, 1, 0, str.tostring(averageDailyRangeRounded), text_color=staticTextColor, text_halign = text.align_left)
  490. table.cell(adrTable, 0, 1, "CDR:", text_color=currentDailyRangeColor, text_halign = text.align_right)
  491. table.cell(adrTable, 1, 1, str.tostring(currentDailyRangeRounded), text_color=currentDailyRangeColor, text_halign = text.align_left)
  492.  
  493. table.cell(adrTable, 0, 2, "CBDR:", text_color=cbdrRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_right)
  494. table.cell(adrTable, 1, 2, str.tostring(cbdrRange), text_color=cbdrRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_left)
  495.  
  496. table.cell(adrTable, 0, 3, "AR:", text_color=asiaRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_right)
  497. table.cell(adrTable, 1, 3, asiaRange == 0.0 ? "n/a" : str.tostring(asiaRange), text_color=asiaRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_left)
  498.  
  499.  
  500.  
  501.  
  502. //}
  503. //{ DEBUGGING
  504. //debugTable = table.new(position.bottom_left, 1, 1, tableBgInput, border_width = 1)
  505. //debugText = str.tostring(getBrightness(color.green))
  506. //table.cell(debugTable, 0, 0, debugText, text_halign = text.align_left)
  507. //}
  508.  
Advertisement
Add Comment
Please, Sign In to add comment