Advertisement
xmd79

ICT Index Futures edit by PunisherLokote

Dec 4th, 2023
459
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 82.62 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. // © ImPunisherLokoteTV
  3. //
  4. //@version=5
  5. //
  6. // Last working production version: 1.0
  7. // 24-Nov-2023
  8.  
  9. indicator("ICT Index Futures edit by PunisherLokote", shorttitle="ICT Index Futures Edited" ,overlay=true, max_lines_count=500, max_labels_count=500)
  10.  
  11. // Sessions and inputs
  12. i_timezone = input.string(defval="America/New_York", title="Timezone Selection", options=["GMT", "America/Los_Angeles", "America/Phoenix", "America/Vancouver", "America/El_Salvador", "America/Bogota", "America/Chicago", "America/New_York", "America/Toronto", "America/Argentina/Buenos_Aires", "America/Sao_Paulo", "Etc/UTC", "Europe/Amsterdam", "Europe/London", "Europe/Berlin", "Europe/Madrid", "Europe/Paris", "Europe/Warsaw", "Europe/Athens", "Europe/Moscow", "Asia/Tehran", "Asia/Dubai", "Asia/Ashkhabad", "Asia/Kolkata", "Asia/Almaty", "Asia/Bangkok", "Asia/Hong_Kong", "Asia/Shanghai", "Asia/Singapore", "Asia/Taipei", "Asia/Seoul", "Asia/Tokyo", "Australia/ACT", "Australia/Adelaide", "Australia/Brisbane", "Australia/Sydney", "Pacific/Auckland", "Pacific/Fakaofo", "Pacific/Chatham", "Pacific/Honolulu"], tooltip="Select the Exchange Timezone, or your own. Whatever works best for you.", group="Global Settings")
  13. i_showDaysDraw = input.int(title="Show Drawings of last # Session Days", defval=5, minval=0, maxval=100, group="Global Settings", tooltip="Remove all drawings older than x days. 0 = Only today's session") // Use in combination with the housekeeping function.
  14. var TodayStart = time // Store the timestamp when a new day starts
  15. showDOW = input.bool(defval=false, title="Show Day of Week", tooltip="Displays the weekday at the bottom of the chart", group="Global Settings", inline="DOW") // Shows the weekdays at the bottom of the screen
  16. i_DOWCol = input.color(title="",tooltip="Change the color of the weekday text", defval=color.black, group="Global Settings", inline="DOW") // Color setting for Weekday text
  17. inputMaxInterval = input.int(30, title="Hide indicator above specified time", tooltip="Above 30 minutes the chart will become messy and unreadable", group="Global Settings") // Input for max timeframe to show indicator
  18. showIndicator = (timeframe.multiplier <= inputMaxInterval) and (timeframe.isintraday) // If current timeframe is lower or equal to input then showIndicator = true
  19.  
  20. // Drawings: Labels and Lines
  21. group_draw = "Line and Label Style Settings"
  22. showLabels = input.bool(defval=true, title="Show labels on horizontal Lines ", tooltip="Show Session Labels on every line", group=group_draw, inline="labels") // Toggle display of labels and tooltips on price levels
  23. showCaptions = input.bool(defval=true, title="Show label text", tooltip="Show Session Labels on every price line with or without captions", group=group_draw, inline="labels") // Toggle captions on labels
  24. i_LabelCol = input.color(title="Label Color", defval=color.new(color.gray, 70), group=group_draw, inline="labelcol") // Set the color of the labels on levels
  25. i_LabelTextcol = input.color(title="Label Text Color", defval=color.new(color.white,0), group=group_draw, inline="labelcol", tooltip="Color settings for the horizontal priceline labels") // Set the textcolor of the labels on levels
  26. i_linestyle = input.string(title="Vertical Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)"], defval="solid (─)",group=group_draw, inline="Line") // Default value is solid to avoid drawing over wicks
  27. i_lineWidth = input.int(title="Width", defval=1, minval=1, maxval=5, group=group_draw, inline="Line", tooltip="Linestyle settings for the vertical dividers") // Set the linewidth of the vertical lines
  28. i_lineExtend = input.bool(title="Extend", defval=true, group=group_draw, inline="Line", tooltip="Extend the vertical dividers or only to the high an low of the day") // Extend the lines or not
  29. i_linestyleLevels = input.string(title="Horizontal Line Style", options=["solid (─)", "dotted (┈)", "dashed (╌)"], defval="solid (─)", group=group_draw, inline="HLine") // Default value is dashed for price levels
  30. i_lineWidthLevels = input.int(title="Width", defval=1, minval=1, maxval=5, group=group_draw, inline="HLine", tooltip="Linestyle settings for the horitontal price levels") // Set the linewidth of the horizontal lines
  31.  
  32. // Daily Session settings
  33. group_daily = "Daily Session"
  34. i_DailySession = input.session(title="Daily High/Low Time Window", defval="0930-1600:1234567", group=group_daily, tooltip="Scan for High and Low of the day during this time window") // Daily Session, Every day
  35. DailySession = time(timeframe.period, i_DailySession, i_timezone) // Calculate time for the Globex/Overnight session.
  36. var float Daily_hi = na // Daily High
  37. var Daily_hi_time = time // Store High's timestamp
  38. var float Daily_lo = na // Daily Low
  39. var Daily_lo_time = time // Store Low's timestamp
  40. showDailyHigh = input.bool(defval=true, title="Show Today's High", group=group_daily, inline="High")
  41. i_DailyHighCol = input.color(title="", defval=color.new(#404040,0), group=group_daily, inline="High")
  42. showDailyLow = input.bool(defval=true, title="Show Today's Low", group=group_daily, inline="High")
  43. i_DailyLowCol = input.color(title="", tooltip="Today's High and Low Line Color", defval=color.new(#404040,0), group=group_daily, inline="High")
  44. var DailyHighLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=na, color=i_DailyHighCol, width=i_lineWidthLevels) // Today's High Price level line
  45. var DailyHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Today's High Price label
  46. var DailyLowLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=na, color=i_DailyLowCol, width=i_lineWidthLevels) // Today's Low Price level line
  47. var DailyLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Today's Low Price label
  48. // PD High and PD Low
  49. var float PD_hi = na // Previous Daily High
  50. var float PD_lo = na // Previous Daily Low
  51. var PD_hi_time = time // Previous Daily High timestamp
  52. var PD_lo_time = time // Previous Daily Low timestamp
  53. extendPDHL = input.bool(defval=true, title="Extend previous Day's High and Low", group=group_daily, tooltip="Extend the PD High and PD Low line all to the end of the chart")
  54. var PDHighLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=na, color=i_DailyHighCol, width=i_lineWidthLevels) // PD's High Price level line
  55. var PDHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // PD's High Price label
  56. var PDLowLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=na, color=i_DailyLowCol, width=i_lineWidthLevels) // PD's Low Price level line
  57. var PDLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // PD's Low Price label
  58.  
  59. var DailySessionStart = time // To register the timestamp when the Daily Session begins
  60.  
  61.  
  62. // Globex (or Overnight) session settings and inputs
  63. showGlobex = input.bool(defval=false, title="Show Start Globex Overnight", group="Globex Session Settings", inline="GS1") // Show Globex Vertical Starting Line
  64. i_GlobexSessionCol = input.color(title="", tooltip="Show Globex/Overnight Starting Line", defval=color.new(color.blue,0), group="Globex Session Settings", inline="GS1") // Globex Session Color setting
  65. showGlobexDrawings = input.bool(defval=false, title="Show AM New York Levels", group="Globex Session Settings", inline="GS2") // Show Globex price levels
  66. i_GlobexLevelCol = input.color(title="", tooltip="Show Globex/Overnight High and Low", defval=color.new(color.gray,0), group="Globex Session Settings", inline="GS2") // Globex (Overnight) Session, color setting for level lines
  67. showGlobexOpenLine = input.bool(defval=false, title="Show Globex/Overnight Opening Price", group="Globex Session Settings", inline="GS3") // Show Globex Open price level
  68. i_GlobexOpenCol = input.color(title="", tooltip="Show Globex/Overnight Open priceline", defval=color.new(color.yellow,0), group="Globex Session Settings", inline="GS3") // Globex (Overnight) Session, color setting for Open price lines
  69. i_GlobexSession = input.session(title="Globex/Overnight Time Window", defval="1700-0830:1234567", group="Globex Session Settings") // Globex (Overnight) Session, Monday - Friday 17:00 - 0830. Globex opens at 5pm CST and closes when the US session starts 8:30CST.
  70. GlobexSession = time(timeframe.period, i_GlobexSession, i_timezone) // Calculate time for the Globex/Overnight session.
  71. var float Globex_open = na // Store the Globex Opening price
  72. var float Globex_hi = na // High for the Globex Session
  73. var float Globex_lo = na // Low for the Globex Session
  74. var Globex_line = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexOpenCol, width=i_lineWidthLevels) // Globex Start Vertical line
  75. var Globex_line_open= line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexOpenCol, width=i_lineWidthLevels) // Globex Open Price line
  76. var Globex_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol, width=i_lineWidthLevels) // Globex High line
  77. var Globex_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_GlobexLevelCol, width=i_lineWidthLevels) // Globex Low line
  78. var GlobexOpenLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Globex Open Price label
  79. var GlobexHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Globex High Price label
  80. var GlobexLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Globex Low Price label
  81. var GlobexSessionStart = time // To register the timestamp when the Globex Overnight Session begins
  82.  
  83.  
  84.  
  85. // -------------------------------- KILLZONE SESSIONS ---------------------------------------------------------------------------
  86. // ASIA Killzone Inputs and Settings
  87. showLine_Asian = input.bool(defval=false, title="Show NY AM Killzone", tooltip="Show Asian Killzone Vertical Lines", group="Asian Session Settings", inline="AKZ") // Asian Killzone Toggle
  88. i_AsianSession = input.session(title="New York AM Session", defval="0930-1200", group="Asian Session Settings", tooltip="This is needed for the high low calculations") // Asian Session, Monday - Friday
  89. AsianSession = time(timeframe.period, i_AsianSession, i_timezone) // Calculate time for the Asian session.
  90. i_AsianSessionHour = input.int(title="Asian Killzone Start Hr.", defval=20, minval=0, maxval=23, group="Asian Session Settings", inline="Asian") // Asian Killzone Opening Hour
  91. i_AsianSessionMin = input.int(title="Min.", defval=00, minval=0, maxval=59, group="Asian Session Settings", inline="Asian", tooltip="This is the Start of the Asian Killzone") // Asian Killzone Opening Minute
  92. AsianSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_AsianSessionHour, i_AsianSessionMin, 00)-86400000 // Coordinate for Asian Killzone Start time (minus 1 day)
  93. i_AsianSessionEndHour = input.int(title="Asian Killzone End Hour", defval=23, minval=0, maxval=23, group="Asian Session Settings", inline="AsianEnd") // Asian Killzone Closing Hour
  94. i_AsianSessionEndMin = input.int(title="Min.", defval=59, minval=0, maxval=59, group="Asian Session Settings", inline="AsianEnd", tooltip="This is the end of the Asian Killzone") // Asian Killzone Closing Minute
  95. AsianSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_AsianSessionEndHour, i_AsianSessionEndMin, 00)-86400000 // Coordinate for Asian Killzone End time (minus 1 day)
  96. i_AsianSessionCol = input.color(title="",tooltip="Asian Killzone Line Color", defval=color.new(color.yellow,0), group="Asian Session Settings", inline="Asian") // Asian Killzone Color setting
  97. var Asian_KZ_start = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol, width=i_lineWidth) // Asian Killzone Start Vertical Line
  98. var Asian_KZ_end = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianSessionCol, width=i_lineWidth) // Asian Killzone End Vertical Line
  99. i_AsianKZHighlight = input.bool(defval=true, title="Highlight KZ", tooltip="Fills the Killzone with a solid color", group="Asian Session Settings", inline="AKZ") // Asian Killzone Fill the area between start and end time
  100. i_AsianSessionFillCol = input.color(title="",tooltip="Asian Killzone Fill Color", defval=color.new(color.yellow,80), group="Asian Session Settings", inline="AKZ") // Asian Killzone Fill Color setting
  101. var AsianKZFill = linefill.new(Asian_KZ_start, Asian_KZ_end, i_AsianSessionFillCol) // Asian Killzone Vertical Linefill
  102. showLevel_Asian = input.bool(defval=true, title="Show AM High/Low", tooltip="Show Asian Killzone Horizontal price levels", group="Asian Session Settings", inline="ALvl") // Asian Killzone High/Low Toggle
  103. i_AsianLevelCol = input.color(title="Levels",tooltip="Asian KZ Levels Color", defval=#404040, group="Asian Session Settings", inline="ALvl") // Asian KZ Session, color setting for level lines
  104.  
  105. // London Killzone session settings and inputs
  106. showLine_London = input.bool(defval=false, title="Show London Killzone", tooltip="Show London Killzone Vertical Lines", group="London Session Settings", inline="LKZ") // London Killzone Toggle
  107. i_LondonSessionHour = input.int(title="London Killzone Start Hr.", defval=02, minval=0, maxval=23, group="London Session Settings", inline="London") // London Killzone Opening Hour
  108. i_LondonSessionMin = input.int(title="Min.", defval=00, minval=0, maxval=59, group="London Session Settings", inline="London", tooltip="This is the Start of the London Killzone") // London Killzone Opening Minute
  109. LondonSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_LondonSessionHour, i_LondonSessionMin, 00) // Coordinate for London Killzone Start time
  110. i_LondonSessionEndHour = input.int(title="London Killzone End Hour", defval=5, minval=0, maxval=23, group="London Session Settings", inline="LondonEnd") // London Killzone Closing Hour
  111. i_LondonSessionEndMin = input.int(title="Min.", defval=0, minval=0, maxval=59, group="London Session Settings", inline="LondonEnd", tooltip="This is the end of the London Killzone") // London Killzone Closing Minute
  112. LondonSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_LondonSessionEndHour, i_LondonSessionEndMin, 00) // Coordinate for London Killzone End time
  113. i_LondonSessionCol = input.color(title="",tooltip="London Killzone Line Color", defval=color.new(color.green,0), group="London Session Settings", inline="London") // London Killzone Color setting
  114. var London_KZ_start = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol, width=i_lineWidth) // London Killzone Start Vertical Line
  115. var London_KZ_end = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonSessionCol, width=i_lineWidth) // London Killzone End Vertical Line
  116. i_LondonKZHighlight = input.bool(defval=true, title="Highlight KZ", tooltip="Fills the Killzone with a solid color", group="London Session Settings", inline="LKZ") // London Killzone Fill the area between start and end time
  117. i_LondonSessionFillCol = input.color(title="",tooltip="London Killzone Fill Color", defval=color.new(color.green,80), group="London Session Settings", inline="LKZ") // London Killzone Fill Color setting
  118. var LondonKZFill = linefill.new(London_KZ_start, London_KZ_end, i_LondonSessionFillCol) // London Killzone Vertical Linefill
  119. showLevel_London = input.bool(defval=true, title="Show London High/Low", tooltip="Show London Killzone Horizontal price levels", group="London Session Settings", inline="LVL") // London Killzone High/Low Toggle
  120. i_LondonLevelCol = input.color(title="Levels",tooltip="London KZ Levels Color", defval=#404040, group="London Session Settings", inline="LVL") // London KZ Session, color setting for level lines
  121.  
  122. // NY Open Killzone session settings and inputs
  123. nykz_group = "NY KZ Session Settings"
  124. showLine_NYKZ = input.bool(defval=false, title="Show NY Lunch ", tooltip="Show NY Open Killzone Vertical Lines", group=nykz_group, inline="NYKZ") // NY Killzone Toggle
  125. i_NYKZSessionHour = input.int(title="NY Lunch Start Hr.", defval=12, minval=0, maxval=23, group=nykz_group, inline="NYKZS") // NY Killzone Opening Hour
  126. i_NYKZSessionMin = input.int(title="Min.", defval=00, minval=0, maxval=59, group=nykz_group, inline="NYKZS", tooltip="This is the Start of the NY Killzone") // NY Killzone Opening Minute
  127. NYKZSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_NYKZSessionHour, i_NYKZSessionMin, 00) // Coordinate for NY Killzone Start time
  128. i_NYKZSessionEndHour = input.int(title="NY Lunch End Hour", defval=13, minval=0, maxval=23, group=nykz_group, inline="NYKZEnd") // NY Killzone Closing Hour
  129. i_NYKZSessionEndMin = input.int(title="Min.", defval=0, minval=0, maxval=59, group=nykz_group, inline="NYKZEnd", tooltip="This is the end of the NY Killzone") // NY Killzone Closing Minute
  130. NYKZSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_NYKZSessionEndHour, i_NYKZSessionEndMin, 00) // Coordinate for NY Killzone End time
  131. i_NYKZSessionCol = input.color(title="",tooltip="NY Killzone Line Color", defval=color.new(color.orange,0), group=nykz_group, inline="NYKZS") // NY Killzone Color setting
  132. var NY_KZ_start = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZSessionCol, width=i_lineWidth) // NY Killzone Start Vertical Line
  133. var NY_KZ_end = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZSessionCol, width=i_lineWidth) // NY Killzone End Vertical Line
  134. i_NYKZHighlight = input.bool(defval=true, title="Highlight KZ", tooltip="Fills the NY Killzone with a solid color", group=nykz_group, inline="NYKZ") // NY Killzone Fill the area between start and end time
  135. i_NYKZSessionFillCol = input.color(title="",tooltip="NY Killzone Fill Color", defval=color.new(color.orange,80), group=nykz_group, inline="NYKZ") // NY Killzone Fill Color setting
  136. var NYKZFill = linefill.new(NY_KZ_start, NY_KZ_end, i_NYKZSessionFillCol) // NY Killzone Vertical Linefill
  137. showLevel_NYKZ = input.bool(defval=true, title="Show Lunch High/Low", tooltip="Show NYKZ Killzone Horizontal price levels", group=nykz_group, inline="NYKZLvl") // NYKZ Killzone High/Low Toggle
  138. i_NYKZLevelCol = input.color(title="Levels",tooltip="NYKZ KZ Levels Color", defval=#404040, group=nykz_group, inline="NYKZLvl") // NYKZ KZ Session, color setting for level lines
  139.  
  140. // NY PM session settings and inputs
  141. nypm_group = "NY PM Session Settings"
  142. showLine_NYPM = input.bool(defval=false, title="Show NY PM ", tooltip="Show NY PM session", group=nypm_group, inline="NYPM") // NY Killzone Toggle
  143. i_NYPMSessionHour = input.int(title="NY PM Start Hr.", defval=13, minval=0, maxval=23, group=nypm_group, inline="NYPMS") // NY Killzone Opening Hour
  144. i_NYPMSessionMin = input.int(title="Min.", defval=30, minval=0, maxval=59, group=nypm_group, inline="NYPMS", tooltip="This is the Start of the NY PM") // NY Killzone Opening Minute
  145. NYPMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_NYPMSessionHour, i_NYPMSessionMin, 00) // Coordinate for NY Killzone Start time
  146. i_NYPMSessionEndHour = input.int(title="NY PM End Hour", defval=16, minval=0, maxval=23, group=nypm_group, inline="NYPMEnd") // NY Killzone Closing Hour
  147. i_NYPMSessionEndMin = input.int(title="Min.", defval=0, minval=0, maxval=59, group=nypm_group, inline="NYPMEnd", tooltip="This is the end of the NY Killzone") // NY Killzone Closing Minute
  148. NYPMSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_NYPMSessionEndHour, i_NYPMSessionEndMin, 00) // Coordinate for NY Killzone End time
  149. i_NYPMSessionCol = input.color(title="",tooltip="NY PM Line Color", defval=color.new(color.orange,0), group=nypm_group, inline="NYPMS") // NY Killzone Color setting
  150. var NY_PM_start = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMSessionCol, width=i_lineWidth) // NY Killzone Start Vertical Line
  151. var NY_PM_end = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMSessionCol, width=i_lineWidth) // NY Killzone End Vertical Line
  152. i_NYPMHighlight = input.bool(defval=true, title="Highlight PM", tooltip="Fills the NYPM Killzone with a solid color", group=nypm_group, inline="NYPM") // NY Killzone Fill the area between start and end time
  153. i_NYPMSessionFillCol = input.color(title="",tooltip="NY PM Fill Color", defval=color.new(color.orange,80), group=nypm_group, inline="NYPM") // NY Killzone Fill Color setting
  154. var NYPMFill = linefill.new(NY_PM_start, NY_PM_end, i_NYPMSessionFillCol) // NY Killzone Vertical Linefill
  155. showLevel_NYPM = input.bool(defval=true, title="Show PM High/Low", tooltip="Show NYPM Horizontal price levels", group=nypm_group, inline="NYPMLvl") // NYKZ Killzone High/Low Toggle
  156. i_NYPMLevelCol = input.color(title="Levels",tooltip="NYPM Levels Color", defval=#404040, group=nypm_group, inline="NYPMLvl") // NYKZ KZ Session, color setting for level lines
  157.  
  158. // New York Session settings and inputs
  159. ny_group = "New York Session Vertical Settings"
  160. nyprice_group = "New York Price Horizontal Level Settings"
  161. nytime_group = "New York Session Time Settings"
  162. cmeprice_group = "CME Price Horizontal Level Settings"
  163.  
  164. showLine_MOP = input.bool(defval=false, title="Show New York Midnight Line", group=ny_group ,inline="NYMNV") // Show New York AM Vertical Line
  165. i_NYMNVertCol = input.color(title="", tooltip="Show New York Midnight Vertical Line", defval=color.new(color.fuchsia,0), group=ny_group, inline="NYMNV") // New York Midnight Opening Vertical Line, color setting
  166. showLine_AM = input.bool(defval=true, title="Show New York AM Vertical Line", group=ny_group, inline="NYAM") // Show New York AM Vertical Line
  167. i_AMSessionCol = input.color(title="", tooltip="Show New York AM Vertical Line", defval=color.new(#404040,0), group=ny_group, inline="NYAM") // New York Session Color setting
  168. showLine_CME = input.bool(defval=false, title="Show CME Open Vertical Line", group=ny_group, inline="CMEL") // Show CME Open Vertical Line
  169. i_CMESessionCol = input.color(title="", tooltip="Show CME Open Vertical Line", defval=color.new(color.orange,0), group=ny_group, inline="CMEL") // CME Session Color setting
  170. showLine_Lunch = input.bool(defval=true, title="Show New York Lunch", group=ny_group, inline="LunchL") // Show New York Lunch Vertical Line
  171. i_LunchSessionCol = input.color(title="", tooltip="Show New York Lunch Vertical Line" , defval=color.new(#404040,0), group=ny_group, inline="LunchL") // Lunch Color setting
  172. i_LunchSessionNTZ = input.bool(defval=true, title="Show New York Lunch No-Trade-Zone", group=ny_group, inline="LunchNTZ") // No Trades During Lunch Color setting
  173. i_LunchSessionFillCol= input.color(title="",tooltip="Highlight NY Lunch No Trade Zone", defval=color.new(#404040,80), group=ny_group, inline="LunchNTZ") // Lunch Color setting
  174. showLine_PM = input.bool(defval=true, title="Show New York PM Vertical Line", group=ny_group, inline="PML") // Show New York PM Vertical Line
  175. i_PMSessionCol = input.color(title="", tooltip="Show New York PM Vertical Line", defval=color.new(#404040,0), group=ny_group, inline="PML") // New York Session PM Color setting
  176. showLine_NYEnd = input.bool(defval=true, title="Show New York End Vertical Line", group=ny_group, inline="NYEL") // Show New York End of Day Vertical Line
  177. i_NYSessionEndCol = input.color(title="", tooltip="Show New York End of Day Vertical Line", defval=color.new(#404040,0), group=ny_group, inline="NYEL") // New York Session Color setting
  178.  
  179. NYMNOpenTime = timestamp(i_timezone, year, month, dayofmonth, 00, 00, 00) // Coordinate for NY Midnight Opening Time coordinate (Every day 00:00)
  180. var NYMN_line = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=na, color=i_NYMNVertCol, width=i_lineWidth) // New York Midnight Open Vertical line
  181.  
  182. i_AMSessionHour = input.int(title="New York AM Hour", defval=09, minval=0, maxval=23, group=nytime_group, inline="AM") // New York Session Opening Hour
  183. i_AMSessionMin = input.int(title="Min.", defval=30, minval=0, maxval=59, group=nytime_group, inline="AM", tooltip="Start of the NY Session") // New York Session Opening Minute
  184. AMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_AMSessionHour, i_AMSessionMin, 00) // Coordinate for NY AM Start session time
  185. var AMSessionLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AMSessionCol, width=i_lineWidth) // New York AM Vertical Line
  186.  
  187. showNYMNOpenLine = input.bool(defval=false, title="Show New York Midnight Opening Price Level", group=nyprice_group, inline="NYMOP") // Show New York Open price level line
  188. i_NYMNOpenCol = input.color(title="", tooltip="Show New York Midnight Opening Horizontal Price Level", defval=color.new(color.fuchsia,0), group=nyprice_group, inline="NYMOP") // New York Midnight Open Price, color setting
  189. var NYMN_line_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYMNOpenCol, width=i_lineWidthLevels) // New York Midnight Open Price level line
  190. var NYMNOpenLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // New York Midnight Open Price label
  191.  
  192. showNYAMOpenLine = input.bool(defval=false, title="Show New York AM Opening Horizontal Price Level",group=nyprice_group, inline="NYOP") // Show New York Open price level line
  193. i_NYAMOpenCol = input.color(title="", tooltip="Show New York AM Opening Horizontal Price Level", defval=color.new(color.yellow,0), group=nyprice_group, inline="NYOP") // New York AM Opening Price, color setting
  194. var NYAM_line_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYAMOpenCol, width=i_lineWidthLevels) // New York AM Open Price level line
  195. var NYAMOpenLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // New York AM Open Price label
  196.  
  197. showCMEOpenLine = input.bool(defval=false, title="Show CME Opening Horizontal Price Level",group=cmeprice_group, inline="CMEOP") // Show CME Open price level line
  198. i_CMEOpenCol = input.color(title="", tooltip="Show CME Opening Horizontal Price Level", defval=color.new(color.orange,0), group=cmeprice_group, inline="CMEOP") // CME Opening Price, color setting
  199. var CME_line_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_CMEOpenCol, width=i_lineWidthLevels) // CME Open Price level line
  200. var CMEOpenLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // CME Open Price label
  201.  
  202. i_CMESessionHour = input.int(title="CME Open Hour", defval=9, minval=0, maxval=23, group=nytime_group, inline="CME") // CME Session Opening Hour
  203. i_CMESessionMin = input.int(title="Min.", defval=30, minval=0, maxval=59, group=nytime_group, inline="CME", tooltip="Start of the CME session") // CME Session Opening Minute
  204. CMESessionTime = timestamp(i_timezone, year, month, dayofmonth, i_CMESessionHour, i_CMESessionMin, 00) // Coordinate for CME Start session time
  205. var CMESessionLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_CMESessionCol, width=i_lineWidth) // CME Open Vertical Line
  206.  
  207. i_LunchSessionHour = input.int(title="Lunch Hour", defval=12, minval=0, maxval=23, group=nytime_group, inline="Lunch") // Lunch Hour
  208. i_LunchSessionMin = input.int(title="Min.", defval=00, minval=0, maxval=59, group=nytime_group, inline="Lunch", tooltip="This is the Start of Lunch ") // Lunch Minute
  209.  
  210. LunchSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_LunchSessionHour, i_LunchSessionMin, 00) // Coordinate for Lunch Start time
  211. var LunchStartLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LunchSessionCol, width=i_lineWidth) // Lunch Start Vertical Line
  212.  
  213. i_PMSessionHour = input.int(title="New York PM Session Hr.", defval=13, minval=0, maxval=23, group=nytime_group, inline="PM") // New York Session PM Opening Hour
  214. i_PMSessionMin = input.int(title="Min.", defval=30, minval=0, maxval=59, group=nytime_group, inline="PM", tooltip="Start of the PM Session ") // New York Session PM Opening Minute
  215.  
  216. PMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_PMSessionHour, i_PMSessionMin, 00) // Coordinate for NY PM Start session time
  217. var PMSessionLine = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AMSessionCol, width=i_lineWidth) // New York AM Vertical Line
  218. var LunchLineFill = linefill.new(LunchStartLine, PMSessionLine, i_LunchSessionFillCol) // Lunch Vertical Linefill (No Trade Zone)
  219.  
  220. showNYPMOpenLine = input.bool(defval=false, title="Show New York PM Opening Horizontal Price Level",group=nyprice_group, inline="NYPMOP") // Show New York PM Open price level line
  221. i_NYPMOpenCol = input.color(title="", tooltip="Show New York PM Opening Horizontal Price Level", defval=color.new(color.blue,0), group=nyprice_group, inline="NYPMOP") // New York PM Opening Price, color setting
  222. var NYPM_line_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMOpenCol, width=i_lineWidthLevels) // New York PM Open Price level line
  223. var NYPMOpenLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // New York PM Open Price label
  224.  
  225. i_NYSessionEndHour = input.int(title="New York Session End Hour", defval=16, minval=0, maxval=23, group=nytime_group, inline="NYE") // New York Session Closing Hour
  226. i_NYSessionEndMin = input.int(title="Min.", defval=00, minval=0, maxval=59, group=nytime_group, inline="NYE", tooltip="This is the end of trading day") // New York Session Closing Minute
  227.  
  228. var NYSessionEndTime= timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00) // Coordinate for NY End of session time (this is also the terminus for the Level lines)
  229. var NYSessionEndLine= line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYSessionEndCol, width=i_lineWidth) // New York Session Vertical Closing line
  230.  
  231. // HTF Lines
  232.  
  233. showWeekOpen = input.bool(defval=false, title="Show Weekly Open", group="HTF Levels", inline="WO")
  234. i_WeekOpenCol = input.color(title="", tooltip="Weekly Open Line Color", defval=color.new(color.gray,0), group="HTF Levels", inline="WO")
  235. var Weekly_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_WeekOpenCol, width=i_lineWidthLevels) // Weekly Open Price level line
  236. var Weekly_openlbl = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Weekly Open Price label
  237. var WeeklyOpenTime = time // Coordinate for Weekly Open Price - will be set with newWeek function
  238. showMonthOpen = input.bool(defval=false, title="Show Monthly Open", group="HTF Levels", inline="MO")
  239. i_MonthOpenCol = input.color(title="", tooltip="Monthly Open Line Color", defval=color.new(color.gray,0), group="HTF Levels", inline="MO")
  240. var Monthly_open = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_MonthOpenCol, width=i_lineWidthLevels) // Monthly Open Price level line
  241. var Monthy_openlbl = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // Monthly Open Price label
  242. var MonthlyOpenTime = time // Coordinate for Monthly Open Price - will be set with newMonth function
  243.  
  244. showDebug = input.bool(title="Show Debugging Info", defval=false, group="Debug") // Toggle display of the table with debug information
  245. log_show_msg = input.int(10, title = "# of message to show", group = "Debug")
  246. log_offset = input.int(0, title = "# of messages to offset", group = "Debug", step = 1)
  247.  
  248. // LOGGING FUNCTION
  249. var logsize = 50
  250. var bar_arr = array.new_int(logsize)
  251. var time_arr = array.new_string(logsize)
  252. var msg_arr = array.new_string(logsize)
  253. var type_arr = array.new_string(logsize)
  254.  
  255. log_msg(message, type) =>
  256. array.push(bar_arr, bar_index)
  257. array.push(time_arr, str.tostring(year) + "-" + str.tostring(month) + "-" + str.tostring(dayofmonth) + " " + str.tostring(hour(time,i_timezone)) + ":" + str.tostring(minute(time,i_timezone)) + ":" + str.tostring(second(time,i_timezone)))
  258. array.push(msg_arr, message)
  259. array.push(type_arr, type)
  260. // Housekeeping, delete the oldest log entries. This prevents the array from becoming too big.
  261. array.shift(bar_arr)
  262. array.shift(time_arr)
  263. array.shift(msg_arr)
  264. array.shift(type_arr)
  265. // END LOGGING CODE
  266.  
  267.  
  268. // Get HTF Price levels
  269. WeeklyOpen = request.security(syminfo.tickerid, "W", open, lookahead = barmerge.lookahead_on) // Get the Week's opening price
  270. MonthlyOpen = request.security(syminfo.tickerid, "M", open, lookahead = barmerge.lookahead_on) // Get the Month's opening price
  271. // END HTF
  272.  
  273.  
  274. // Detect the Start of a new week
  275. newWeek = ta.change(weekofyear) // Needed for drawing the HTF lines and levels just once per week
  276.  
  277. if newWeek
  278. WeeklyOpenTime := time
  279. log_msg("New Week Started", 'low')
  280.  
  281.  
  282. // Detect the Start of a new month
  283. newMonth = ta.change(time("M")) // Needed for drawing the HTF lines and levels just once per month
  284.  
  285. if newMonth
  286. MonthlyOpenTime := time
  287. log_msg("New Month Started", 'low')
  288.  
  289. // *** End of inputs and variables
  290.  
  291. // Convert linestyle
  292. linestyle = (i_linestyle == "solid (─)") ? line.style_solid :
  293. (i_linestyle == "dashed (╌)") ? line.style_dashed :
  294. line.style_dotted // Default value is dotted to avoid drawing over wicks
  295.  
  296. // Convert linestyle for Levels
  297. linestyle_level = (i_linestyleLevels == "solid (─)") ? line.style_solid :
  298. (i_linestyleLevels == "dashed (╌)") ? line.style_dashed :
  299. line.style_dotted // Default value is dotted
  300.  
  301.  
  302. // Functions
  303. // Function to draw Vertical Lines
  304. vline(Start, Color, linestyle, LineWidth) =>
  305. if i_lineExtend // If the option is set to extend all vertical lines...
  306. line.new(x1=Start, y1=low - ta.tr, x2=Start, y2=high + ta.tr, xloc=xloc.bar_time, extend=extend.both, color=Color, style=linestyle, width=LineWidth)
  307. else
  308. line.new(x1=Start, y1=Daily_hi, x2=Start, y2=Daily_hi, xloc=xloc.bar_time, extend=extend.none, color=Color, style=linestyle, width=LineWidth) // Else the vertical lines will print to the daily high and low
  309. // End function
  310.  
  311. // Draw Horizontal Lines
  312. _hline(StartTime, EndTime, Price, Extend, Color, Style, Width) =>
  313. return_1 = line.new(StartTime, Price, EndTime, Price, xloc=xloc.bar_time, extend=Extend, color=Color, style=Style, width=Width)
  314.  
  315. // Function for determining the Start of a Session (taken from the Pinescript manual: https://www.tradingview.com/pine-script-docs/en/v5/concepts/Sessions.html )
  316. sessionBegins(sess) =>
  317. t = time("", sess , i_timezone)
  318. showIndicator and (not barstate.isfirst) and na(t[1]) and not na(t)
  319. // End session function
  320.  
  321. // Housekeeping - Remove old drawing objects
  322. housekeeping(days) =>
  323. // Delete old drawing objects
  324. // One day is 86400000 milliseconds
  325. removal_timestamp = AsianSessionTime - (days * 86400000) // Remove every drawing object older than the start of the Asian Session.
  326. a_allLines = line.all
  327. a_allLabels = label.all
  328. // Remove old lines
  329. if array.size(a_allLines) > 0
  330. for i = 0 to array.size(a_allLines) - 1
  331. line_x2 = line.get_x2(array.get(a_allLines, i))
  332. if line_x2 < removal_timestamp
  333. line.delete(array.get(a_allLines, i))
  334. // Remove old labels
  335. if array.size(a_allLabels) > 0
  336. for i = 0 to array.size(a_allLabels) - 1
  337. label_x = label.get_x(array.get(a_allLabels, i))
  338. if label_x < removal_timestamp
  339. label.delete(array.get(a_allLabels, i))
  340.  
  341. // End of housekeeping function
  342.  
  343. // *** End of all functions
  344.  
  345.  
  346.  
  347. // ************************** <<
  348. // Start MAIN Logic
  349.  
  350. // Daily Session Start | this works for everything but stocks
  351. if sessionBegins(i_DailySession) // When a new Daily Session is started
  352. log_msg("Daily Session Start", 'medium')
  353. log_msg("You are trading: " + syminfo.ticker + " and its asset class is: " + syminfo.type, 'medium')
  354. DailySessionStart := time // Store the Session Starting timestamp
  355. NYMNOpenTime := time
  356. // Store Previous Day's High and Low
  357. PD_hi := Daily_hi
  358. PD_hi_time := Daily_hi_time
  359. PD_lo := Daily_lo
  360. PD_lo_time := Daily_lo_time
  361.  
  362. // Calculate timestamps for the coming session
  363. // Killzone vertical line timestamps
  364. if AsianSessionTime < DailySessionStart // If the AsianSessionTime is in the past, then add 1 day
  365. AsianSessionTime := AsianSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  366.  
  367. if AsianSessionEndTime < DailySessionStart // If the AsianSessionEndTime is in the past, then add 1 day
  368. AsianSessionEndTime := AsianSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  369.  
  370. if LondonSessionTime < DailySessionStart // If the LondonSessionTime is in the past, then add 1 day
  371. LondonSessionTime := LondonSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  372.  
  373. if LondonSessionEndTime < DailySessionStart // If the LondonSessionEndTime is in the past, then add 1 day
  374. LondonSessionEndTime := LondonSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  375.  
  376. if NYKZSessionTime < DailySessionStart // If the NYKZSessionTime is in the past, then add 1 day
  377. NYKZSessionTime := NYKZSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  378.  
  379. if NYKZSessionEndTime < DailySessionStart // If the NYKZSessionEndTime is in the past, then add 1 day
  380. NYKZSessionEndTime := NYKZSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  381.  
  382. // Session vertical line timestamps
  383. if AMSessionTime < DailySessionStart // If the AMSessionTime is in the past, then add 1 day
  384. AMSessionTime := AMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  385.  
  386. if AMSessionTime < DailySessionStart // If the AMSessionTime is in the past, then add 1 day
  387. AMSessionTime := AMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  388.  
  389. if CMESessionTime < DailySessionStart // If the NYSessionEndTime is in the past, then add 1 day
  390. CMESessionTime := CMESessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  391.  
  392. if LunchSessionTime < DailySessionStart // If the LunchSessionTime is in the past, then add 1 day
  393. LunchSessionTime := LunchSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  394.  
  395. if PMSessionTime < DailySessionStart // If the PMSessionTime is in the past, then add 1 day
  396. PMSessionTime := PMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  397.  
  398. NYSessionEndTime := timestamp(i_timezone, year, month, dayofmonth, i_NYSessionEndHour, i_NYSessionEndMin, 00) // Coordinate for NY End of Cash session time (this is the terminus for the Level lines)
  399. if NYSessionEndTime < DailySessionStart // If the NYSessionEndTime is in the past, then add 1 day
  400. NYSessionEndTime := NYSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  401.  
  402. // Extend previous day's High and Low line.
  403. // This needs to be done after the housekeeping, otherwise it could get cleaned up again.
  404. if showDailyHigh and extendPDHL
  405. PDHighLine := line.new(x1=PD_hi_time, y1=PD_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=PD_hi, color=i_DailyHighCol, width=i_lineWidthLevels) // Extend PD's High Price level line
  406. if showLabels
  407. PDHighLabel := label.new(x=NYSessionEndTime, y=PD_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // PD's High Price label
  408. label.set_tooltip(PDHighLabel, "Previous Daily High: " + str.tostring(PD_hi))
  409. if showCaptions
  410. label.set_text(PDHighLabel, "PD High")
  411. if showDailyLow and extendPDHL
  412. PDLowLine := line.new(x1=PD_lo_time, y1=PD_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=PD_lo, color=i_DailyLowCol, width=i_lineWidthLevels) // Extend PD's Low Price level line
  413. if showLabels
  414. PDLowLabel := label.new(x=NYSessionEndTime, y=PD_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small) // PD's Low Price label
  415. label.set_tooltip(PDLowLabel, "Previous Daily Low: " + str.tostring(PD_lo))
  416. if showCaptions
  417. label.set_text(PDLowLabel, "PD Low")
  418.  
  419. // Now for the Current High and Low
  420. // We are entering Daily Session hours; reset hi/lo.
  421. Daily_hi := high
  422. Daily_lo := low
  423. // Initialize the drawings for today
  424. if showDailyHigh // Draw the Daily Open Vertical Line
  425. DailyHighLine := line.new(x1=NYMNOpenTime, y1=Daily_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Daily_hi, color=i_DailyHighCol, width=i_lineWidthLevels) // Today's High Price level line
  426. if showLabels
  427. DailyHighLabel := label.new(x=NYMNOpenTime, y=Daily_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_right, size=size.small) // Today's High Price label
  428. if showCaptions
  429. label.set_text(DailyHighLabel, "Daily High")
  430. if showDailyLow
  431. DailyLowLine := line.new(x1=NYMNOpenTime, y1=Daily_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Daily_lo, color=i_DailyLowCol, width=i_lineWidthLevels) // Today's Low Price level line
  432. if showLabels
  433. DailyLowLabel := label.new(x=NYMNOpenTime, y=Daily_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_right, size=size.small) // Today's Low Price label
  434. if showCaptions
  435. label.set_text(DailyLowLabel, "Daily Low")
  436. // When a new day start, draw all the vertical lines
  437.  
  438. // Draw the Asian Killzone Lines
  439. if (showLine_Asian and showIndicator)
  440. log_msg("Asian Killzone printed", 'low')
  441. Asian_KZ_start := vline(AsianSessionTime, i_AsianSessionCol, linestyle, i_lineWidth)
  442. Asian_KZ_end := vline(AsianSessionEndTime, i_AsianSessionCol, linestyle, i_lineWidth)
  443.  
  444. // Fill the area during Asian Killzone
  445. if (i_AsianKZHighlight and showIndicator)
  446. AsianKZFill := linefill.new(Asian_KZ_start, Asian_KZ_end, i_AsianSessionFillCol)
  447.  
  448. // Draw the London Killzone Lines
  449. if (showLine_London and showIndicator)
  450. log_msg("London KZ Started", 'low')
  451. London_KZ_start := vline(LondonSessionTime, i_LondonSessionCol, linestyle, i_lineWidth)
  452. London_KZ_end := vline(LondonSessionEndTime, i_LondonSessionCol, linestyle, i_lineWidth)
  453.  
  454. // Fill the area during London Killzone
  455. if (i_LondonKZHighlight and showIndicator)
  456. LondonKZFill := linefill.new(London_KZ_start, London_KZ_end, i_LondonSessionFillCol)
  457.  
  458. // Draw the NY Midnight Open Line
  459. if (showLine_MOP and showIndicator)
  460. NYMN_line := vline(NYMNOpenTime, i_NYMNVertCol, linestyle, i_lineWidth)
  461. log_msg("New York Midnight Open Vertical line | OpenTime: " + str.tostring(year) + "-" + str.tostring(month) + "-" + str.tostring(dayofmonth) + " " + str.tostring(hour(NYMNOpenTime,i_timezone)) + ":" + str.tostring(minute(NYMNOpenTime,i_timezone)) + ":" + str.tostring(second(NYMNOpenTime,i_timezone)), 'low')
  462.  
  463. // Draw the NY AM Session Start Line
  464. if (showLine_AM and showIndicator)
  465. AMSessionLine := vline(AMSessionTime, i_AMSessionCol, linestyle, i_lineWidth)
  466. log_msg("New York AM Open Vertical line", 'low')
  467.  
  468. // Draw the CME Open Start Line
  469. if (showLine_CME and showIndicator)
  470. CMESessionLine := vline(CMESessionTime, i_CMESessionCol, linestyle, i_lineWidth)
  471. log_msg("CME Open Vertical line", 'low')
  472.  
  473. // Draw the NY Killzone Lines
  474. if (showLine_NYKZ and showIndicator)
  475. log_msg("NY Open Killzone Started", 'low')
  476. NY_KZ_start := vline(NYKZSessionTime, i_NYKZSessionCol, linestyle, i_lineWidth)
  477. NY_KZ_end := vline(NYKZSessionEndTime, i_NYKZSessionCol, linestyle, i_lineWidth)
  478.  
  479. // Fill the area during NY Killzone
  480. if (i_NYKZHighlight and showIndicator)
  481. NYKZFill := linefill.new(NY_KZ_start, NY_KZ_end, i_NYKZSessionFillCol)
  482.  
  483. // Draw the NY Lunch Start Line
  484. if (showLine_Lunch and showIndicator)
  485. LunchStartLine := vline(LunchSessionTime, i_LunchSessionCol, linestyle, i_lineWidth)
  486.  
  487. // Draw the NY PM Session Start Line
  488. if (showLine_PM and showIndicator)
  489. PMSessionLine := vline(PMSessionTime, i_PMSessionCol, linestyle, i_lineWidth)
  490.  
  491. // Fill the area during lunch no trading zone
  492. if (i_LunchSessionNTZ and showIndicator)
  493. LunchLineFill := linefill.new(LunchStartLine, PMSessionLine, i_LunchSessionFillCol)
  494.  
  495.  
  496. // Draw the NY Session End Line
  497. if (showLine_NYEnd and showIndicator)
  498. NYSessionEndLine := vline(NYSessionEndTime, i_NYSessionEndCol, linestyle, i_lineWidth)
  499. log_msg("New York Session END Vertical line", 'low')
  500. //
  501. // *** End of Vertical Lines section
  502.  
  503. // HTF Levels
  504. if showWeekOpen // Weekly line will be re-drawn each day
  505. line.delete(Weekly_open[1]) // Delete Previous line
  506. if showLabels
  507. label.delete(Weekly_openlbl[1])
  508. Weekly_open:= line.new(x1=WeeklyOpenTime, y1=WeeklyOpen, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=WeeklyOpen, color=i_WeekOpenCol, style=linestyle_level, width=i_lineWidthLevels) // Weekly Open priceline
  509. log_msg("Weekly Open Horizontal Line", 'low')
  510. if showLabels
  511. Weekly_openlbl := label.new(x=NYSessionEndTime, y=WeeklyOpen, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  512. label.set_tooltip(Weekly_openlbl, "Weekly Open: " + str.tostring(WeeklyOpen))
  513. if showCaptions
  514. label.set_text(Weekly_openlbl, "Weekly Open")
  515.  
  516.  
  517. if showMonthOpen // Monthly line will be re-drawn each day
  518. line.delete(Monthly_open[1]) // Delete Previous line
  519. if showLabels
  520. label.delete(Monthy_openlbl[1])
  521. Monthly_open:= line.new(x1=MonthlyOpenTime, y1=MonthlyOpen, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=MonthlyOpen, color=i_MonthOpenCol, style=linestyle_level, width=i_lineWidthLevels) // Monthly Open priceline
  522. log_msg("Monthly Open Horizontal Line", 'low')
  523. if showLabels
  524. Monthy_openlbl := label.new(x=NYSessionEndTime, y=MonthlyOpen, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  525. label.set_tooltip(Monthy_openlbl, "Monthly Open: " + str.tostring(MonthlyOpen))
  526. if showCaptions
  527. label.set_text(Monthy_openlbl, "Monthly Open")
  528.  
  529. else if DailySession
  530. // We are in allowed DailySession hours; track hi/lo.
  531. Daily_hi := math.max(high, Daily_hi)
  532. Daily_lo := math.min(low, Daily_lo)
  533. if (Daily_hi > Daily_hi[1])
  534. if showDailyHigh
  535. log_msg("New Daily High formed", 'low')
  536. Daily_hi_time := time
  537. line.set_y1(id=DailyHighLine, y=Daily_hi)
  538. line.set_y2(id=DailyHighLine, y=Daily_hi)
  539. if showLabels
  540. label.set_y(id=DailyHighLabel, y=Daily_hi)
  541. label.set_y(id=DailyHighLabel, y=Daily_hi)
  542. label.set_tooltip(DailyHighLabel, "Daily High: " + str.tostring(Daily_hi))
  543. if showCaptions
  544. label.set_text(DailyHighLabel, "High")
  545. if (Daily_lo < Daily_lo[1])
  546. if showDailyLow
  547. log_msg("New Daily Low formed", 'low')
  548. Daily_lo_time := time
  549. line.set_y1(id=DailyLowLine, y=Daily_lo)
  550. line.set_y2(id=DailyLowLine, y=Daily_lo)
  551. if showLabels
  552. label.set_y(id=DailyLowLabel, y=Daily_lo)
  553. label.set_y(id=DailyLowLabel, y=Daily_lo)
  554. label.set_tooltip(DailyLowLabel, "Daily Low: " + str.tostring(Daily_lo))
  555. if showCaptions
  556. label.set_text(DailyLowLabel, "Low")
  557. // END Daily Session Code
  558.  
  559.  
  560. // Start of Horizontal Price Levels
  561.  
  562. // New York Midnight Open Price line
  563. if (showNYMNOpenLine and time == NYMNOpenTime and showIndicator) // Only draw the NY Midnight line once at 00:00 - FOR INDICES (Workaround by adding 1 day in milliseconds)
  564. NYMN_line_open:= line.new(x1=NYMNOpenTime, y1=open, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=open, color=i_NYMNOpenCol, style=linestyle_level, width=i_lineWidthLevels) // NYMN Open line
  565. log_msg("New York Midnight Open Horizontal Price line CME", 'low')
  566. if showLabels
  567. NYMNOpenLabel := label.new(x=NYSessionEndTime, y=open, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  568. label.set_tooltip(NYMNOpenLabel, "NY Midnight Open: " + str.tostring(open))
  569. if showCaptions
  570. label.set_text(NYMNOpenLabel, "00:00 Open")
  571. // *** End of NY MN Level line
  572.  
  573.  
  574. // New York AM Open Price line
  575. if (showNYAMOpenLine and time == AMSessionTime and showIndicator) // Only draw the NY AM line once at 08.30
  576. NYAM_line_open:= _hline(AMSessionTime, NYSessionEndTime, open, extend.none, i_NYAMOpenCol, linestyle_level, i_lineWidthLevels) // NYAM Open priceline
  577. log_msg("New York AM Open Horizontal Price line", 'low')
  578. if showLabels
  579. NYAMOpenLabel := label.new(x=NYSessionEndTime, y=open, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  580. label.set_tooltip(NYAMOpenLabel, "NY AM Open: " + str.tostring(open))
  581. if showCaptions
  582. label.set_text(NYAMOpenLabel, "NY AM Open")
  583. // *** End of NYAM Open Level line
  584.  
  585. // CME Open Price line
  586. if (showCMEOpenLine and time == CMESessionTime and showIndicator) // Only draw the CME Open line once at 09.30
  587. CME_line_open:= _hline(CMESessionTime, NYSessionEndTime, open, extend.none, i_CMEOpenCol, linestyle_level, i_lineWidthLevels) // CME Open priceline
  588. log_msg("CME Open Horizontal Price line", 'low')
  589. if showLabels
  590. CMEOpenLabel := label.new(x=NYSessionEndTime, y=open, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  591. label.set_tooltip(CMEOpenLabel, "CME Open: " + str.tostring(open))
  592. if showCaptions
  593. label.set_text(CMEOpenLabel, "CME Open")
  594. // *** End of CME Open Level line
  595.  
  596. // New York PM Open Price line
  597. if (showNYPMOpenLine and time == PMSessionTime and showIndicator) // Only draw the NY PM line once at 13.00
  598. NYPM_line_open:= _hline(PMSessionTime, NYSessionEndTime, open, extend.none, i_NYPMOpenCol, linestyle_level, i_lineWidthLevels) // NYPM Open priceline
  599. log_msg("New York PM Open Horizontal Price line", 'low')
  600. if showLabels
  601. NYPMOpenLabel := label.new(x=NYSessionEndTime, y=open, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  602. label.set_tooltip(NYPMOpenLabel, "NY PM Open: " + str.tostring(open))
  603. if showCaptions
  604. label.set_text(NYPMOpenLabel, "NY PM Open")
  605. // *** End of NYPM Open Level line
  606.  
  607. // END OF HORIZONTAL PRICE LINES
  608.  
  609.  
  610.  
  611.  
  612. // *** SESSION CODE ***
  613. //
  614.  
  615. // Begin Asian Killzone Session Code
  616. var float Asian_hi = na // High for the Asian Session
  617. var float Asian_lo = na // Low for the Asian Session
  618. var Asian_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol) // Asian High line
  619. var Asian_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol) // Asian Low line
  620. var AsianHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  621. var AsianLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  622. var AsianSessionStart = time // To register the timestap when the Asian Session begins on the previous day
  623.  
  624. if sessionBegins(i_AsianSession) and showIndicator // When a new Asian Killzone Session is started
  625. log_msg("Asian Killzone Session Start", 'low')
  626. AsianSessionStart := time // Store the Session Starting timestamp
  627. if NYSessionEndTime < AsianSessionStart // If the NYSessionEndTime is in the past, then add 1 day
  628. if dayofweek == dayofweek.sunday and (syminfo.type == "futures" or syminfo.type == "cfd" or syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "forex")
  629. NYSessionEndTime := NYSessionEndTime+(2*86400000) // Add 2 days, so level lines will be drawn to the right like they should
  630. else
  631. NYSessionEndTime := NYSessionEndTime+(86400000) // Add 1 day, so level lines will be drawn to the right like they should. For crypto and 24hr markets
  632. // We are entering Asian Session hours; reset hi/lo.
  633. Asian_hi := high
  634. Asian_lo := low
  635. // Initialize the drawings for today
  636.  
  637. if showLevel_Asian
  638. Asian_line_hi := line.new(x1=AsianSessionStart, y1=Asian_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Asian_hi, color=i_AsianLevelCol, width=i_lineWidthLevels, style=linestyle_level) // Asian High line
  639. Asian_line_lo := line.new(x1=AsianSessionStart, y1=Asian_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Asian_lo, color=i_AsianLevelCol, width=i_lineWidthLevels, style=linestyle_level) // Asian Low line
  640. if showLabels
  641. AsianHighLabel := label.new(x=AsianSessionStart, y=Asian_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  642. AsianLowLabel := label.new(x=AsianSessionStart, y=Asian_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  643. label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
  644. if showCaptions
  645. label.set_text(AsianHighLabel, "AM High")
  646. label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
  647. if showCaptions
  648. label.set_text(AsianLowLabel, "AM Low")
  649. else if AsianSession
  650. // We are in allowed AsianSession hours; track hi/lo.
  651. log_msg("Asian Killzone: Tracking Highs and Lows", 'low')
  652. Asian_hi := math.max(high, Asian_hi)
  653. Asian_lo := math.min(low, Asian_lo)
  654. if (Asian_hi > Asian_hi[1])
  655. log_msg("Asian Killzone: New High found", 'low')
  656. if showLevel_Asian
  657. line.set_xy1(id=Asian_line_hi, x=time, y=Asian_hi)
  658. line.set_xy2(id=Asian_line_hi, x=NYSessionEndTime, y=Asian_hi)
  659. if showLabels
  660. label.set_xy(id=AsianHighLabel, x=NYSessionEndTime, y=Asian_hi)
  661. label.set_xy(id=AsianLowLabel, x=NYSessionEndTime, y=Asian_lo)
  662. label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
  663. label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
  664. if (Asian_lo < Asian_lo[1])
  665. log_msg("Asian Killzone: New Low found", 'low')
  666. if showLevel_Asian
  667. line.set_xy1(id=Asian_line_lo, x=time, y=Asian_lo)
  668. line.set_xy2(id=Asian_line_lo, x=NYSessionEndTime, y=Asian_lo)
  669. if showLabels
  670. label.set_xy(id=AsianHighLabel, x=NYSessionEndTime, y=Asian_hi)
  671. label.set_xy(id=AsianLowLabel, x=NYSessionEndTime, y=Asian_lo)
  672. label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
  673. label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
  674. // END Asian Session Code
  675. // ***
  676.  
  677. // Begin London Killzone Session Code
  678. var float London_hi = na // High for the London Session
  679. var float London_lo = na // Low for the London Session
  680. var London_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol) // London High line
  681. var London_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol) // London Low line
  682. var LondonHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  683. var LondonLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  684. var LondonSessionStart = time // To register the timestap when the London Session begins
  685.  
  686. if (time == LondonSessionTime and showIndicator) // When a new London Killzone Session is started
  687. log_msg("London Killzone Session Start", 'low')
  688. LondonSessionStart := time // Store the Session Starting timestamp
  689. // We are entering London Session hours; reset hi/lo.
  690. London_hi := high
  691. London_lo := low
  692. // Initialize the drawings for today
  693. if showLevel_London
  694. London_line_hi := line.new(x1=LondonSessionStart, y1=London_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=London_hi, color=i_LondonLevelCol, width=i_lineWidthLevels, style=linestyle_level) // London High line
  695. London_line_lo := line.new(x1=LondonSessionStart, y1=London_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=London_lo, color=i_LondonLevelCol, width=i_lineWidthLevels, style=linestyle_level) // London Low line
  696. if showLabels
  697. LondonHighLabel := label.new(x=LondonSessionStart, y=London_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  698. label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
  699. if showCaptions
  700. label.set_text(LondonHighLabel, "London High")
  701. LondonLowLabel := label.new(x=LondonSessionStart, y=London_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  702. label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
  703. if showCaptions
  704. label.set_text(LondonLowLabel, "London Low")
  705. else if (time > LondonSessionTime and time <= LondonSessionEndTime)
  706. // We are in allowed LondonSession hours; track hi/lo.
  707. London_hi := math.max(high, London_hi)
  708. London_lo := math.min(low, London_lo)
  709. if (London_hi > London_hi[1])
  710. if showLevel_London
  711. line.set_xy1(id=London_line_hi, x=time, y=London_hi)
  712. line.set_xy2(id=London_line_hi, x=NYSessionEndTime, y=London_hi)
  713. if showLabels
  714. label.set_xy(id=LondonHighLabel, x=NYSessionEndTime, y=London_hi)
  715. label.set_xy(id=LondonLowLabel, x=NYSessionEndTime, y=London_lo)
  716. label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
  717. label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
  718. if (London_lo < London_lo[1])
  719. if showLevel_London
  720. line.set_xy1(id=London_line_lo, x=time, y=London_lo)
  721. line.set_xy2(id=London_line_lo, x=NYSessionEndTime, y=London_lo)
  722. if showLabels
  723. label.set_xy(id=LondonHighLabel, x=NYSessionEndTime, y=London_hi)
  724. label.set_xy(id=LondonLowLabel, x=NYSessionEndTime, y=London_lo)
  725. label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
  726. label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
  727. // END London Session Code
  728. // ***
  729.  
  730.  
  731. //
  732. // Begin Globex Session Code
  733. if sessionBegins(i_GlobexSession) and showIndicator // When a new Globex Session is started
  734. log_msg("Globex Session Start", 'low')
  735. GlobexSessionStart := time // Store the Session Starting timestamp
  736. if NYSessionEndTime < GlobexSessionStart // If the NYSessionEndTime is in the past, then add 1 day
  737. NYSessionEndTime := NYSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
  738. if dayofweek == dayofweek.sunday and (syminfo.type == "futures" or syminfo.type == "cfd" or syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "forex")
  739. NYSessionEndTime := NYSessionEndTime+(2*86400000) // Add another day, so level lines will be drawn to the right like they should
  740. // We are entering Globex Session hours; reset hi/lo.
  741. Globex_open := open
  742. log_msg("Globex Open: " + str.tostring(Globex_open), 'low')
  743. Globex_hi := high
  744. Globex_lo := low
  745. // Initialize the drawings for today
  746. if showGlobex // Draw the Globex Open Vertical Line
  747. Globex_line := vline(GlobexSessionStart, i_GlobexSessionCol, linestyle, i_lineWidth)
  748. if showGlobexDrawings
  749. // Create new objects for today
  750. if showGlobexOpenLine // Only paints once.
  751. Globex_line_open:= line.new(x1=GlobexSessionStart, y1=Globex_open, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Globex_open, color=i_GlobexOpenCol, style=linestyle_level, width=i_lineWidthLevels) // Globex Open line
  752. if showLabels
  753. GlobexOpenLabel := label.new(x=NYSessionEndTime, y=Globex_open, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  754. label.set_tooltip(GlobexOpenLabel, "Globex Open: " + str.tostring(Globex_open))
  755. if showCaptions
  756. label.set_text(GlobexOpenLabel, "Globex Open")
  757. Globex_line_hi := line.new(x1=GlobexSessionStart, y1=Globex_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Globex_hi, color=i_GlobexLevelCol, width=i_lineWidthLevels, style=linestyle_level) // Globex High line
  758. Globex_line_lo := line.new(x1=GlobexSessionStart, y1=Globex_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=Globex_lo, color=i_GlobexLevelCol, width=i_lineWidthLevels, style=linestyle_level) // Globex Low line
  759. if showLabels
  760. GlobexHighLabel := label.new(x=NYSessionEndTime, y=Globex_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  761. GlobexLowLabel := label.new(x=NYSessionEndTime, y=Globex_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  762. label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
  763. label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
  764. if showCaptions
  765. label.set_text(GlobexHighLabel, "Globex High")
  766. if showCaptions
  767. label.set_text(GlobexLowLabel, "Globex Low")
  768. else if GlobexSession
  769. // We are in allowed GlobexSession hours; track hi/lo.
  770. Globex_hi := math.max(high, Globex_hi)
  771. Globex_lo := math.min(low, Globex_lo)
  772. if (Globex_hi > Globex_hi[1])
  773. if showGlobexDrawings
  774. line.set_xy1(id=Globex_line_hi, x=time, y=Globex_hi)
  775. line.set_xy2(id=Globex_line_hi, x=NYSessionEndTime, y=Globex_hi)
  776. if showLabels
  777. label.set_xy(id=GlobexHighLabel, x=NYSessionEndTime, y=Globex_hi)
  778. label.set_xy(id=GlobexLowLabel, x=NYSessionEndTime, y=Globex_lo)
  779. label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
  780. label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
  781. if (Globex_lo < Globex_lo[1])
  782. if showGlobexDrawings
  783. line.set_xy1(id=Globex_line_lo, x=time, y=Globex_lo)
  784. line.set_xy2(id=Globex_line_lo, x=NYSessionEndTime, y=Globex_lo)
  785. if showLabels
  786. label.set_xy(id=GlobexHighLabel, x=NYSessionEndTime, y=Globex_hi)
  787. label.set_xy(id=GlobexLowLabel, x=NYSessionEndTime, y=Globex_lo)
  788. label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
  789. label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
  790. // END Globex Session Code
  791.  
  792.  
  793. // Begin NYKZ Killzone Session Code
  794. var float NYKZ_hi = na // High for the NYKZ Session
  795. var float NYKZ_lo = na // Low for the NYKZ Session
  796. var NYKZ_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZLevelCol) // NYKZ High line
  797. var NYKZ_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZLevelCol) // NYKZ Low line
  798. var NYKZHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  799. var NYKZLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  800. var NYKZSessionStart = time // To register the timestap when the NYKZ Session begins
  801.  
  802. if (time == NYKZSessionTime and showIndicator) // When a new NYKZ Killzone Session is started
  803. log_msg("NY Killzone Session Start", 'low')
  804. NYKZSessionStart := time // Store the Session Starting timestamp
  805. // We are entering NYKZ Session hours; reset hi/lo.
  806. NYKZ_hi := high
  807. NYKZ_lo := low
  808. // Initialize the drawings for today
  809. if showLevel_NYKZ
  810. NYKZ_line_hi := line.new(x1=NYKZSessionStart, y1=NYKZ_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=NYKZ_hi, color=i_NYKZLevelCol, width=i_lineWidthLevels, style=linestyle_level) // NYKZ High line
  811. NYKZ_line_lo := line.new(x1=NYKZSessionStart, y1=NYKZ_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=NYKZ_lo, color=i_NYKZLevelCol, width=i_lineWidthLevels, style=linestyle_level) // NYKZ Low line
  812. if showLabels
  813. NYKZHighLabel := label.new(x=NYKZSessionStart, y=NYKZ_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  814. NYKZLowLabel := label.new(x=NYKZSessionStart, y=NYKZ_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  815. label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
  816. label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
  817. if showCaptions
  818. label.set_text(NYKZHighLabel, "Lunch High")
  819. if showCaptions
  820. label.set_text(NYKZLowLabel, "Lunch Low")
  821. else if (time > NYKZSessionTime and time <= NYKZSessionEndTime)
  822. // We are in allowed NYKZSession hours; track hi/lo.
  823. NYKZ_hi := math.max(high, NYKZ_hi)
  824. NYKZ_lo := math.min(low, NYKZ_lo)
  825. if (NYKZ_hi > NYKZ_hi[1])
  826. if showLevel_NYKZ
  827. line.set_xy1(id=NYKZ_line_hi, x=time, y=NYKZ_hi)
  828. line.set_xy2(id=NYKZ_line_hi, x=NYSessionEndTime, y=NYKZ_hi)
  829. if showLabels
  830. label.set_xy(id=NYKZHighLabel, x=NYSessionEndTime, y=NYKZ_hi)
  831. label.set_xy(id=NYKZLowLabel, x=NYSessionEndTime, y=NYKZ_lo)
  832. label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
  833. label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
  834. if (NYKZ_lo < NYKZ_lo[1])
  835. if showLevel_NYKZ
  836. line.set_xy1(id=NYKZ_line_lo, x=time, y=NYKZ_lo)
  837. line.set_xy2(id=NYKZ_line_lo, x=NYSessionEndTime, y=NYKZ_lo)
  838. if showLabels
  839. label.set_xy(id=NYKZHighLabel, x=NYSessionEndTime, y=NYKZ_hi)
  840. label.set_xy(id=NYKZLowLabel, x=NYSessionEndTime, y=NYKZ_lo)
  841. label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
  842. label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
  843. // END NYKZ Session Code
  844. // ***
  845.  
  846. // Begin NYPM Killzone Session Code
  847. var float NYPM_hi = na // High for the NYKZ Session
  848. var float NYPM_lo = na // Low for the NYKZ Session
  849. var NYPM_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMLevelCol) // NYKZ High line
  850. var NYPM_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMLevelCol) // NYKZ Low line
  851. var NYPMHighLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  852. var NYPMLowLabel = label.new(x=na, y=na, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  853. var NYPMSessionStart = time // To register the timestap when the NYPM Session begins
  854.  
  855. if (time == NYPMSessionTime and showIndicator) // When a new NYKZ Killzone Session is started
  856. log_msg("NY Killzone Session Start", 'low')
  857. NYPMSessionStart := time // Store the Session Starting timestamp
  858. // We are entering NYKZ Session hours; reset hi/lo.
  859. NYPM_hi := high
  860. NYPM_lo := low
  861. // Initialize the drawings for today
  862. if showLevel_NYPM
  863. NYPM_line_hi := line.new(x1=NYPMSessionStart, y1=NYPM_hi, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=NYPM_hi, color=i_NYPMLevelCol, width=i_lineWidthLevels, style=linestyle_level) // NYKZ High line
  864. NYPM_line_lo := line.new(x1=NYPMSessionStart, y1=NYPM_lo, x2=NYSessionEndTime, xloc=xloc.bar_time, y2=NYPM_lo, color=i_NYPMLevelCol, width=i_lineWidthLevels, style=linestyle_level) // NYKZ Low line
  865. if showLabels
  866. NYPMHighLabel := label.new(x=NYPMSessionStart, y=NYPM_hi, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  867. NYPMLowLabel := label.new(x=NYPMSessionStart, y=NYPM_lo, xloc=xloc.bar_time, color=i_LabelCol, textcolor=i_LabelTextcol, style=label.style_label_left, size=size.small)
  868. label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
  869. label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
  870. if showCaptions
  871. label.set_text(NYPMHighLabel, "PM High")
  872. if showCaptions
  873. label.set_text(NYPMLowLabel, "PM Low")
  874. else if (time > NYPMSessionTime and time <= NYPMSessionEndTime)
  875. // We are in allowed NYKZSession hours; track hi/lo.
  876. NYPM_hi := math.max(high, NYPM_hi)
  877. NYPM_lo := math.min(low, NYPM_lo)
  878. if (NYPM_hi > NYPM_hi[1])
  879. if showLevel_NYPM
  880. line.set_xy1(id=NYPM_line_hi, x=time, y=NYPM_hi)
  881. line.set_xy2(id=NYPM_line_hi, x=NYSessionEndTime, y=NYPM_hi)
  882. if showLabels
  883. label.set_xy(id=NYPMHighLabel, x=NYSessionEndTime, y=NYPM_hi)
  884. label.set_xy(id=NYPMLowLabel, x=NYSessionEndTime, y=NYPM_lo)
  885. label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
  886. label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
  887. if (NYPM_lo < NYPM_lo[1])
  888. if showLevel_NYPM
  889. line.set_xy1(id=NYPM_line_lo, x=time, y=NYPM_lo)
  890. line.set_xy2(id=NYPM_line_lo, x=NYSessionEndTime, y=NYPM_lo)
  891. if showLabels
  892. label.set_xy(id=NYPMHighLabel, x=NYSessionEndTime, y=NYPM_hi)
  893. label.set_xy(id=NYPMLowLabel, x=NYSessionEndTime, y=NYPM_lo)
  894. label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
  895. label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
  896. // END NYKZ Session Code
  897. // ***
  898.  
  899.  
  900. // Create and fill log table //
  901. var log_tbl = table.new(position.bottom_left, 3, log_show_msg + 2, border_width = 1)
  902.  
  903. if (barstate.isconfirmed and showDebug)
  904.  
  905. table.merge_cells(log_tbl, 0, 0, 2, 0)
  906. table.cell(log_tbl, 0, 0, 'Debug Logging', text_size=size.normal, text_color=color.black, bgcolor = color.gray, text_halign=text.align_center)
  907. table.cell(log_tbl, 0, 1, "Bar #", bgcolor = color.gray, text_size = size.small)
  908. table.cell(log_tbl, 1, 1, "Time", bgcolor = color.gray, text_size = size.small)
  909. table.cell(log_tbl, 2, 1, "Message", bgcolor = color.gray, text_size = size.small)
  910.  
  911. for i = 1 to log_show_msg
  912. arr_i = array.size(msg_arr) - log_show_msg + i - 1 - log_offset
  913.  
  914. if (arr_i < 0)
  915. break
  916.  
  917. type = array.get(type_arr, arr_i)
  918.  
  919. msg_color = type == 'low' ? #cccccc :
  920. type == 'medium' ? #F5AC4E :
  921. type == 'high' ? #DD4224 : na
  922.  
  923. table.cell(log_tbl, 0, i+1, str.tostring(array.get(bar_arr, arr_i)), bgcolor = msg_color, text_size = size.small)
  924. table.cell(log_tbl, 1, i+1, array.get(time_arr, arr_i), bgcolor = msg_color, text_size = size.small)
  925. table.cell(log_tbl, 2, i+1, array.get(msg_arr, arr_i), bgcolor = msg_color, text_size = size.small)
  926.  
  927. ///////////////////////////////
  928.  
  929. // Testing area
  930. //log_msg(str.format("NYMNOpenTime: {0,date, y-MM-d'.' hh:mm:ss}" ,NYMNOpenTime), "low")
  931.  
  932. //log_msg("TodayStart Timestamp: " + str.tostring(TodayStart), 'low')
  933.  
  934. // Start Plotting
  935. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.monday : false, offset=0, style=shape.diamond, text="Monday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  936. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.tuesday : false, offset=0, style=shape.diamond, text="Tuesday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  937. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.wednesday : false, offset=0, style=shape.diamond, text="Wednesday", color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  938. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.thursday : false, offset=0, style=shape.diamond, text="Thursday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  939. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.friday : false, offset=0, style=shape.diamond, text="Friday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  940. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.saturday : false, offset=0, style=shape.diamond, text="Saturday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  941. plotshape(showDOW and showIndicator ? hour == 4 and minute == 0 and dayofweek == dayofweek.sunday : false, offset=0, style=shape.diamond, text="Sunday" , color=color.new(i_DOWCol, 0), location = location.bottom, textcolor=color.new(i_DOWCol, 0))
  942.  
  943. // Do housekeeping of old objects - remove everything before the number of days set
  944. housekeeping(i_showDaysDraw)
  945.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement