Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © ImPunisherLokoteTV
- //
- //@version=5
- //
- // Last working production version: 1.0
- // 24-Nov-2023
- indicator("ICT Index Futures edit by PunisherLokote", shorttitle="ICT Index Futures Edited" ,overlay=true, max_lines_count=500, max_labels_count=500)
- // Sessions and inputs
- 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")
- 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.
- var TodayStart = time // Store the timestamp when a new day starts
- 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
- 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
- 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
- showIndicator = (timeframe.multiplier <= inputMaxInterval) and (timeframe.isintraday) // If current timeframe is lower or equal to input then showIndicator = true
- // Drawings: Labels and Lines
- group_draw = "Line and Label Style Settings"
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- // Daily Session settings
- group_daily = "Daily Session"
- 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
- DailySession = time(timeframe.period, i_DailySession, i_timezone) // Calculate time for the Globex/Overnight session.
- var float Daily_hi = na // Daily High
- var Daily_hi_time = time // Store High's timestamp
- var float Daily_lo = na // Daily Low
- var Daily_lo_time = time // Store Low's timestamp
- showDailyHigh = input.bool(defval=true, title="Show Today's High", group=group_daily, inline="High")
- i_DailyHighCol = input.color(title="", defval=color.new(#404040,0), group=group_daily, inline="High")
- showDailyLow = input.bool(defval=true, title="Show Today's Low", group=group_daily, inline="High")
- i_DailyLowCol = input.color(title="", tooltip="Today's High and Low Line Color", defval=color.new(#404040,0), group=group_daily, inline="High")
- 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
- 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
- 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
- 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
- // PD High and PD Low
- var float PD_hi = na // Previous Daily High
- var float PD_lo = na // Previous Daily Low
- var PD_hi_time = time // Previous Daily High timestamp
- var PD_lo_time = time // Previous Daily Low timestamp
- 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")
- 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
- 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
- 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
- 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
- var DailySessionStart = time // To register the timestamp when the Daily Session begins
- // Globex (or Overnight) session settings and inputs
- showGlobex = input.bool(defval=false, title="Show Start Globex Overnight", group="Globex Session Settings", inline="GS1") // Show Globex Vertical Starting Line
- 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
- showGlobexDrawings = input.bool(defval=false, title="Show AM New York Levels", group="Globex Session Settings", inline="GS2") // Show Globex price levels
- 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
- showGlobexOpenLine = input.bool(defval=false, title="Show Globex/Overnight Opening Price", group="Globex Session Settings", inline="GS3") // Show Globex Open price level
- 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
- 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.
- GlobexSession = time(timeframe.period, i_GlobexSession, i_timezone) // Calculate time for the Globex/Overnight session.
- var float Globex_open = na // Store the Globex Opening price
- var float Globex_hi = na // High for the Globex Session
- var float Globex_lo = na // Low for the Globex Session
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- var GlobexSessionStart = time // To register the timestamp when the Globex Overnight Session begins
- // -------------------------------- KILLZONE SESSIONS ---------------------------------------------------------------------------
- // ASIA Killzone Inputs and Settings
- 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
- 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
- AsianSession = time(timeframe.period, i_AsianSession, i_timezone) // Calculate time for the Asian session.
- 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
- 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
- AsianSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_AsianSessionHour, i_AsianSessionMin, 00)-86400000 // Coordinate for Asian Killzone Start time (minus 1 day)
- 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
- 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
- AsianSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_AsianSessionEndHour, i_AsianSessionEndMin, 00)-86400000 // Coordinate for Asian Killzone End time (minus 1 day)
- 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
- 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
- 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
- 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
- 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
- var AsianKZFill = linefill.new(Asian_KZ_start, Asian_KZ_end, i_AsianSessionFillCol) // Asian Killzone Vertical Linefill
- 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
- 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
- // London Killzone session settings and inputs
- 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
- 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
- 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
- LondonSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_LondonSessionHour, i_LondonSessionMin, 00) // Coordinate for London Killzone Start time
- 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
- 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
- LondonSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_LondonSessionEndHour, i_LondonSessionEndMin, 00) // Coordinate for London Killzone End time
- 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
- 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
- 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
- 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
- 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
- var LondonKZFill = linefill.new(London_KZ_start, London_KZ_end, i_LondonSessionFillCol) // London Killzone Vertical Linefill
- 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
- 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
- // NY Open Killzone session settings and inputs
- nykz_group = "NY KZ Session Settings"
- 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
- i_NYKZSessionHour = input.int(title="NY Lunch Start Hr.", defval=12, minval=0, maxval=23, group=nykz_group, inline="NYKZS") // NY Killzone Opening Hour
- 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
- NYKZSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_NYKZSessionHour, i_NYKZSessionMin, 00) // Coordinate for NY Killzone Start time
- i_NYKZSessionEndHour = input.int(title="NY Lunch End Hour", defval=13, minval=0, maxval=23, group=nykz_group, inline="NYKZEnd") // NY Killzone Closing Hour
- 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
- NYKZSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_NYKZSessionEndHour, i_NYKZSessionEndMin, 00) // Coordinate for NY Killzone End time
- 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
- 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
- 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
- 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
- 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
- var NYKZFill = linefill.new(NY_KZ_start, NY_KZ_end, i_NYKZSessionFillCol) // NY Killzone Vertical Linefill
- 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
- 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
- // NY PM session settings and inputs
- nypm_group = "NY PM Session Settings"
- showLine_NYPM = input.bool(defval=false, title="Show NY PM ", tooltip="Show NY PM session", group=nypm_group, inline="NYPM") // NY Killzone Toggle
- i_NYPMSessionHour = input.int(title="NY PM Start Hr.", defval=13, minval=0, maxval=23, group=nypm_group, inline="NYPMS") // NY Killzone Opening Hour
- 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
- NYPMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_NYPMSessionHour, i_NYPMSessionMin, 00) // Coordinate for NY Killzone Start time
- i_NYPMSessionEndHour = input.int(title="NY PM End Hour", defval=16, minval=0, maxval=23, group=nypm_group, inline="NYPMEnd") // NY Killzone Closing Hour
- 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
- NYPMSessionEndTime = timestamp(i_timezone, year, month, dayofmonth, i_NYPMSessionEndHour, i_NYPMSessionEndMin, 00) // Coordinate for NY Killzone End time
- 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
- 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
- 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
- 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
- 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
- var NYPMFill = linefill.new(NY_PM_start, NY_PM_end, i_NYPMSessionFillCol) // NY Killzone Vertical Linefill
- 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
- 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
- // New York Session settings and inputs
- ny_group = "New York Session Vertical Settings"
- nyprice_group = "New York Price Horizontal Level Settings"
- nytime_group = "New York Session Time Settings"
- cmeprice_group = "CME Price Horizontal Level Settings"
- showLine_MOP = input.bool(defval=false, title="Show New York Midnight Line", group=ny_group ,inline="NYMNV") // Show New York AM Vertical Line
- 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
- showLine_AM = input.bool(defval=true, title="Show New York AM Vertical Line", group=ny_group, inline="NYAM") // Show New York AM Vertical Line
- 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
- showLine_CME = input.bool(defval=false, title="Show CME Open Vertical Line", group=ny_group, inline="CMEL") // Show CME Open Vertical Line
- 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
- showLine_Lunch = input.bool(defval=true, title="Show New York Lunch", group=ny_group, inline="LunchL") // Show New York Lunch Vertical Line
- 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
- 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
- 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
- showLine_PM = input.bool(defval=true, title="Show New York PM Vertical Line", group=ny_group, inline="PML") // Show New York PM Vertical Line
- 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
- 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
- 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
- NYMNOpenTime = timestamp(i_timezone, year, month, dayofmonth, 00, 00, 00) // Coordinate for NY Midnight Opening Time coordinate (Every day 00:00)
- 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
- 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
- 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
- AMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_AMSessionHour, i_AMSessionMin, 00) // Coordinate for NY AM Start session time
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- showCMEOpenLine = input.bool(defval=false, title="Show CME Opening Horizontal Price Level",group=cmeprice_group, inline="CMEOP") // Show CME Open price level line
- 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
- 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
- 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
- i_CMESessionHour = input.int(title="CME Open Hour", defval=9, minval=0, maxval=23, group=nytime_group, inline="CME") // CME Session Opening Hour
- 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
- CMESessionTime = timestamp(i_timezone, year, month, dayofmonth, i_CMESessionHour, i_CMESessionMin, 00) // Coordinate for CME Start session time
- 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
- i_LunchSessionHour = input.int(title="Lunch Hour", defval=12, minval=0, maxval=23, group=nytime_group, inline="Lunch") // Lunch Hour
- 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
- LunchSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_LunchSessionHour, i_LunchSessionMin, 00) // Coordinate for Lunch Start time
- 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
- 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
- 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
- PMSessionTime = timestamp(i_timezone, year, month, dayofmonth, i_PMSessionHour, i_PMSessionMin, 00) // Coordinate for NY PM Start session time
- 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
- var LunchLineFill = linefill.new(LunchStartLine, PMSessionLine, i_LunchSessionFillCol) // Lunch Vertical Linefill (No Trade Zone)
- 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
- 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
- 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
- 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
- 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
- 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
- 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)
- 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
- // HTF Lines
- showWeekOpen = input.bool(defval=false, title="Show Weekly Open", group="HTF Levels", inline="WO")
- i_WeekOpenCol = input.color(title="", tooltip="Weekly Open Line Color", defval=color.new(color.gray,0), group="HTF Levels", inline="WO")
- 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
- 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
- var WeeklyOpenTime = time // Coordinate for Weekly Open Price - will be set with newWeek function
- showMonthOpen = input.bool(defval=false, title="Show Monthly Open", group="HTF Levels", inline="MO")
- i_MonthOpenCol = input.color(title="", tooltip="Monthly Open Line Color", defval=color.new(color.gray,0), group="HTF Levels", inline="MO")
- 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
- 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
- var MonthlyOpenTime = time // Coordinate for Monthly Open Price - will be set with newMonth function
- showDebug = input.bool(title="Show Debugging Info", defval=false, group="Debug") // Toggle display of the table with debug information
- log_show_msg = input.int(10, title = "# of message to show", group = "Debug")
- log_offset = input.int(0, title = "# of messages to offset", group = "Debug", step = 1)
- // LOGGING FUNCTION
- var logsize = 50
- var bar_arr = array.new_int(logsize)
- var time_arr = array.new_string(logsize)
- var msg_arr = array.new_string(logsize)
- var type_arr = array.new_string(logsize)
- log_msg(message, type) =>
- array.push(bar_arr, bar_index)
- 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)))
- array.push(msg_arr, message)
- array.push(type_arr, type)
- // Housekeeping, delete the oldest log entries. This prevents the array from becoming too big.
- array.shift(bar_arr)
- array.shift(time_arr)
- array.shift(msg_arr)
- array.shift(type_arr)
- // END LOGGING CODE
- // Get HTF Price levels
- WeeklyOpen = request.security(syminfo.tickerid, "W", open, lookahead = barmerge.lookahead_on) // Get the Week's opening price
- MonthlyOpen = request.security(syminfo.tickerid, "M", open, lookahead = barmerge.lookahead_on) // Get the Month's opening price
- // END HTF
- // Detect the Start of a new week
- newWeek = ta.change(weekofyear) // Needed for drawing the HTF lines and levels just once per week
- if newWeek
- WeeklyOpenTime := time
- log_msg("New Week Started", 'low')
- // Detect the Start of a new month
- newMonth = ta.change(time("M")) // Needed for drawing the HTF lines and levels just once per month
- if newMonth
- MonthlyOpenTime := time
- log_msg("New Month Started", 'low')
- // *** End of inputs and variables
- // Convert linestyle
- linestyle = (i_linestyle == "solid (─)") ? line.style_solid :
- (i_linestyle == "dashed (╌)") ? line.style_dashed :
- line.style_dotted // Default value is dotted to avoid drawing over wicks
- // Convert linestyle for Levels
- linestyle_level = (i_linestyleLevels == "solid (─)") ? line.style_solid :
- (i_linestyleLevels == "dashed (╌)") ? line.style_dashed :
- line.style_dotted // Default value is dotted
- // Functions
- // Function to draw Vertical Lines
- vline(Start, Color, linestyle, LineWidth) =>
- if i_lineExtend // If the option is set to extend all vertical lines...
- 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)
- else
- 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
- // End function
- // Draw Horizontal Lines
- _hline(StartTime, EndTime, Price, Extend, Color, Style, Width) =>
- return_1 = line.new(StartTime, Price, EndTime, Price, xloc=xloc.bar_time, extend=Extend, color=Color, style=Style, width=Width)
- // 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 )
- sessionBegins(sess) =>
- t = time("", sess , i_timezone)
- showIndicator and (not barstate.isfirst) and na(t[1]) and not na(t)
- // End session function
- // Housekeeping - Remove old drawing objects
- housekeeping(days) =>
- // Delete old drawing objects
- // One day is 86400000 milliseconds
- removal_timestamp = AsianSessionTime - (days * 86400000) // Remove every drawing object older than the start of the Asian Session.
- a_allLines = line.all
- a_allLabels = label.all
- // Remove old lines
- if array.size(a_allLines) > 0
- for i = 0 to array.size(a_allLines) - 1
- line_x2 = line.get_x2(array.get(a_allLines, i))
- if line_x2 < removal_timestamp
- line.delete(array.get(a_allLines, i))
- // Remove old labels
- if array.size(a_allLabels) > 0
- for i = 0 to array.size(a_allLabels) - 1
- label_x = label.get_x(array.get(a_allLabels, i))
- if label_x < removal_timestamp
- label.delete(array.get(a_allLabels, i))
- // End of housekeeping function
- // *** End of all functions
- // ************************** <<
- // Start MAIN Logic
- // Daily Session Start | this works for everything but stocks
- if sessionBegins(i_DailySession) // When a new Daily Session is started
- log_msg("Daily Session Start", 'medium')
- log_msg("You are trading: " + syminfo.ticker + " and its asset class is: " + syminfo.type, 'medium')
- DailySessionStart := time // Store the Session Starting timestamp
- NYMNOpenTime := time
- // Store Previous Day's High and Low
- PD_hi := Daily_hi
- PD_hi_time := Daily_hi_time
- PD_lo := Daily_lo
- PD_lo_time := Daily_lo_time
- // Calculate timestamps for the coming session
- // Killzone vertical line timestamps
- if AsianSessionTime < DailySessionStart // If the AsianSessionTime is in the past, then add 1 day
- AsianSessionTime := AsianSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if AsianSessionEndTime < DailySessionStart // If the AsianSessionEndTime is in the past, then add 1 day
- AsianSessionEndTime := AsianSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if LondonSessionTime < DailySessionStart // If the LondonSessionTime is in the past, then add 1 day
- LondonSessionTime := LondonSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if LondonSessionEndTime < DailySessionStart // If the LondonSessionEndTime is in the past, then add 1 day
- LondonSessionEndTime := LondonSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if NYKZSessionTime < DailySessionStart // If the NYKZSessionTime is in the past, then add 1 day
- NYKZSessionTime := NYKZSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if NYKZSessionEndTime < DailySessionStart // If the NYKZSessionEndTime is in the past, then add 1 day
- NYKZSessionEndTime := NYKZSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- // Session vertical line timestamps
- if AMSessionTime < DailySessionStart // If the AMSessionTime is in the past, then add 1 day
- AMSessionTime := AMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if AMSessionTime < DailySessionStart // If the AMSessionTime is in the past, then add 1 day
- AMSessionTime := AMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if CMESessionTime < DailySessionStart // If the NYSessionEndTime is in the past, then add 1 day
- CMESessionTime := CMESessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if LunchSessionTime < DailySessionStart // If the LunchSessionTime is in the past, then add 1 day
- LunchSessionTime := LunchSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if PMSessionTime < DailySessionStart // If the PMSessionTime is in the past, then add 1 day
- PMSessionTime := PMSessionTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- 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)
- if NYSessionEndTime < DailySessionStart // If the NYSessionEndTime is in the past, then add 1 day
- NYSessionEndTime := NYSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- // Extend previous day's High and Low line.
- // This needs to be done after the housekeeping, otherwise it could get cleaned up again.
- if showDailyHigh and extendPDHL
- 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
- if showLabels
- 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
- label.set_tooltip(PDHighLabel, "Previous Daily High: " + str.tostring(PD_hi))
- if showCaptions
- label.set_text(PDHighLabel, "PD High")
- if showDailyLow and extendPDHL
- 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
- if showLabels
- 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
- label.set_tooltip(PDLowLabel, "Previous Daily Low: " + str.tostring(PD_lo))
- if showCaptions
- label.set_text(PDLowLabel, "PD Low")
- // Now for the Current High and Low
- // We are entering Daily Session hours; reset hi/lo.
- Daily_hi := high
- Daily_lo := low
- // Initialize the drawings for today
- if showDailyHigh // Draw the Daily Open Vertical Line
- 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
- if showLabels
- 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
- if showCaptions
- label.set_text(DailyHighLabel, "Daily High")
- if showDailyLow
- 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
- if showLabels
- 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
- if showCaptions
- label.set_text(DailyLowLabel, "Daily Low")
- // When a new day start, draw all the vertical lines
- // Draw the Asian Killzone Lines
- if (showLine_Asian and showIndicator)
- log_msg("Asian Killzone printed", 'low')
- Asian_KZ_start := vline(AsianSessionTime, i_AsianSessionCol, linestyle, i_lineWidth)
- Asian_KZ_end := vline(AsianSessionEndTime, i_AsianSessionCol, linestyle, i_lineWidth)
- // Fill the area during Asian Killzone
- if (i_AsianKZHighlight and showIndicator)
- AsianKZFill := linefill.new(Asian_KZ_start, Asian_KZ_end, i_AsianSessionFillCol)
- // Draw the London Killzone Lines
- if (showLine_London and showIndicator)
- log_msg("London KZ Started", 'low')
- London_KZ_start := vline(LondonSessionTime, i_LondonSessionCol, linestyle, i_lineWidth)
- London_KZ_end := vline(LondonSessionEndTime, i_LondonSessionCol, linestyle, i_lineWidth)
- // Fill the area during London Killzone
- if (i_LondonKZHighlight and showIndicator)
- LondonKZFill := linefill.new(London_KZ_start, London_KZ_end, i_LondonSessionFillCol)
- // Draw the NY Midnight Open Line
- if (showLine_MOP and showIndicator)
- NYMN_line := vline(NYMNOpenTime, i_NYMNVertCol, linestyle, i_lineWidth)
- 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')
- // Draw the NY AM Session Start Line
- if (showLine_AM and showIndicator)
- AMSessionLine := vline(AMSessionTime, i_AMSessionCol, linestyle, i_lineWidth)
- log_msg("New York AM Open Vertical line", 'low')
- // Draw the CME Open Start Line
- if (showLine_CME and showIndicator)
- CMESessionLine := vline(CMESessionTime, i_CMESessionCol, linestyle, i_lineWidth)
- log_msg("CME Open Vertical line", 'low')
- // Draw the NY Killzone Lines
- if (showLine_NYKZ and showIndicator)
- log_msg("NY Open Killzone Started", 'low')
- NY_KZ_start := vline(NYKZSessionTime, i_NYKZSessionCol, linestyle, i_lineWidth)
- NY_KZ_end := vline(NYKZSessionEndTime, i_NYKZSessionCol, linestyle, i_lineWidth)
- // Fill the area during NY Killzone
- if (i_NYKZHighlight and showIndicator)
- NYKZFill := linefill.new(NY_KZ_start, NY_KZ_end, i_NYKZSessionFillCol)
- // Draw the NY Lunch Start Line
- if (showLine_Lunch and showIndicator)
- LunchStartLine := vline(LunchSessionTime, i_LunchSessionCol, linestyle, i_lineWidth)
- // Draw the NY PM Session Start Line
- if (showLine_PM and showIndicator)
- PMSessionLine := vline(PMSessionTime, i_PMSessionCol, linestyle, i_lineWidth)
- // Fill the area during lunch no trading zone
- if (i_LunchSessionNTZ and showIndicator)
- LunchLineFill := linefill.new(LunchStartLine, PMSessionLine, i_LunchSessionFillCol)
- // Draw the NY Session End Line
- if (showLine_NYEnd and showIndicator)
- NYSessionEndLine := vline(NYSessionEndTime, i_NYSessionEndCol, linestyle, i_lineWidth)
- log_msg("New York Session END Vertical line", 'low')
- //
- // *** End of Vertical Lines section
- // HTF Levels
- if showWeekOpen // Weekly line will be re-drawn each day
- line.delete(Weekly_open[1]) // Delete Previous line
- if showLabels
- label.delete(Weekly_openlbl[1])
- 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
- log_msg("Weekly Open Horizontal Line", 'low')
- if showLabels
- 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)
- label.set_tooltip(Weekly_openlbl, "Weekly Open: " + str.tostring(WeeklyOpen))
- if showCaptions
- label.set_text(Weekly_openlbl, "Weekly Open")
- if showMonthOpen // Monthly line will be re-drawn each day
- line.delete(Monthly_open[1]) // Delete Previous line
- if showLabels
- label.delete(Monthy_openlbl[1])
- 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
- log_msg("Monthly Open Horizontal Line", 'low')
- if showLabels
- 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)
- label.set_tooltip(Monthy_openlbl, "Monthly Open: " + str.tostring(MonthlyOpen))
- if showCaptions
- label.set_text(Monthy_openlbl, "Monthly Open")
- else if DailySession
- // We are in allowed DailySession hours; track hi/lo.
- Daily_hi := math.max(high, Daily_hi)
- Daily_lo := math.min(low, Daily_lo)
- if (Daily_hi > Daily_hi[1])
- if showDailyHigh
- log_msg("New Daily High formed", 'low')
- Daily_hi_time := time
- line.set_y1(id=DailyHighLine, y=Daily_hi)
- line.set_y2(id=DailyHighLine, y=Daily_hi)
- if showLabels
- label.set_y(id=DailyHighLabel, y=Daily_hi)
- label.set_y(id=DailyHighLabel, y=Daily_hi)
- label.set_tooltip(DailyHighLabel, "Daily High: " + str.tostring(Daily_hi))
- if showCaptions
- label.set_text(DailyHighLabel, "High")
- if (Daily_lo < Daily_lo[1])
- if showDailyLow
- log_msg("New Daily Low formed", 'low')
- Daily_lo_time := time
- line.set_y1(id=DailyLowLine, y=Daily_lo)
- line.set_y2(id=DailyLowLine, y=Daily_lo)
- if showLabels
- label.set_y(id=DailyLowLabel, y=Daily_lo)
- label.set_y(id=DailyLowLabel, y=Daily_lo)
- label.set_tooltip(DailyLowLabel, "Daily Low: " + str.tostring(Daily_lo))
- if showCaptions
- label.set_text(DailyLowLabel, "Low")
- // END Daily Session Code
- // Start of Horizontal Price Levels
- // New York Midnight Open Price line
- 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)
- 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
- log_msg("New York Midnight Open Horizontal Price line CME", 'low')
- if showLabels
- 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)
- label.set_tooltip(NYMNOpenLabel, "NY Midnight Open: " + str.tostring(open))
- if showCaptions
- label.set_text(NYMNOpenLabel, "00:00 Open")
- // *** End of NY MN Level line
- // New York AM Open Price line
- if (showNYAMOpenLine and time == AMSessionTime and showIndicator) // Only draw the NY AM line once at 08.30
- NYAM_line_open:= _hline(AMSessionTime, NYSessionEndTime, open, extend.none, i_NYAMOpenCol, linestyle_level, i_lineWidthLevels) // NYAM Open priceline
- log_msg("New York AM Open Horizontal Price line", 'low')
- if showLabels
- 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)
- label.set_tooltip(NYAMOpenLabel, "NY AM Open: " + str.tostring(open))
- if showCaptions
- label.set_text(NYAMOpenLabel, "NY AM Open")
- // *** End of NYAM Open Level line
- // CME Open Price line
- if (showCMEOpenLine and time == CMESessionTime and showIndicator) // Only draw the CME Open line once at 09.30
- CME_line_open:= _hline(CMESessionTime, NYSessionEndTime, open, extend.none, i_CMEOpenCol, linestyle_level, i_lineWidthLevels) // CME Open priceline
- log_msg("CME Open Horizontal Price line", 'low')
- if showLabels
- 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)
- label.set_tooltip(CMEOpenLabel, "CME Open: " + str.tostring(open))
- if showCaptions
- label.set_text(CMEOpenLabel, "CME Open")
- // *** End of CME Open Level line
- // New York PM Open Price line
- if (showNYPMOpenLine and time == PMSessionTime and showIndicator) // Only draw the NY PM line once at 13.00
- NYPM_line_open:= _hline(PMSessionTime, NYSessionEndTime, open, extend.none, i_NYPMOpenCol, linestyle_level, i_lineWidthLevels) // NYPM Open priceline
- log_msg("New York PM Open Horizontal Price line", 'low')
- if showLabels
- 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)
- label.set_tooltip(NYPMOpenLabel, "NY PM Open: " + str.tostring(open))
- if showCaptions
- label.set_text(NYPMOpenLabel, "NY PM Open")
- // *** End of NYPM Open Level line
- // END OF HORIZONTAL PRICE LINES
- // *** SESSION CODE ***
- //
- // Begin Asian Killzone Session Code
- var float Asian_hi = na // High for the Asian Session
- var float Asian_lo = na // Low for the Asian Session
- var Asian_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol) // Asian High line
- var Asian_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_AsianLevelCol) // Asian Low line
- 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)
- 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)
- var AsianSessionStart = time // To register the timestap when the Asian Session begins on the previous day
- if sessionBegins(i_AsianSession) and showIndicator // When a new Asian Killzone Session is started
- log_msg("Asian Killzone Session Start", 'low')
- AsianSessionStart := time // Store the Session Starting timestamp
- if NYSessionEndTime < AsianSessionStart // If the NYSessionEndTime is in the past, then add 1 day
- if dayofweek == dayofweek.sunday and (syminfo.type == "futures" or syminfo.type == "cfd" or syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "forex")
- NYSessionEndTime := NYSessionEndTime+(2*86400000) // Add 2 days, so level lines will be drawn to the right like they should
- else
- NYSessionEndTime := NYSessionEndTime+(86400000) // Add 1 day, so level lines will be drawn to the right like they should. For crypto and 24hr markets
- // We are entering Asian Session hours; reset hi/lo.
- Asian_hi := high
- Asian_lo := low
- // Initialize the drawings for today
- if showLevel_Asian
- 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
- 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
- if showLabels
- 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)
- 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)
- label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
- if showCaptions
- label.set_text(AsianHighLabel, "AM High")
- label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
- if showCaptions
- label.set_text(AsianLowLabel, "AM Low")
- else if AsianSession
- // We are in allowed AsianSession hours; track hi/lo.
- log_msg("Asian Killzone: Tracking Highs and Lows", 'low')
- Asian_hi := math.max(high, Asian_hi)
- Asian_lo := math.min(low, Asian_lo)
- if (Asian_hi > Asian_hi[1])
- log_msg("Asian Killzone: New High found", 'low')
- if showLevel_Asian
- line.set_xy1(id=Asian_line_hi, x=time, y=Asian_hi)
- line.set_xy2(id=Asian_line_hi, x=NYSessionEndTime, y=Asian_hi)
- if showLabels
- label.set_xy(id=AsianHighLabel, x=NYSessionEndTime, y=Asian_hi)
- label.set_xy(id=AsianLowLabel, x=NYSessionEndTime, y=Asian_lo)
- label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
- label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
- if (Asian_lo < Asian_lo[1])
- log_msg("Asian Killzone: New Low found", 'low')
- if showLevel_Asian
- line.set_xy1(id=Asian_line_lo, x=time, y=Asian_lo)
- line.set_xy2(id=Asian_line_lo, x=NYSessionEndTime, y=Asian_lo)
- if showLabels
- label.set_xy(id=AsianHighLabel, x=NYSessionEndTime, y=Asian_hi)
- label.set_xy(id=AsianLowLabel, x=NYSessionEndTime, y=Asian_lo)
- label.set_tooltip(AsianHighLabel, "AM High: " + str.tostring(Asian_hi))
- label.set_tooltip(AsianLowLabel, "AM Low: " + str.tostring(Asian_lo))
- // END Asian Session Code
- // ***
- // Begin London Killzone Session Code
- var float London_hi = na // High for the London Session
- var float London_lo = na // Low for the London Session
- var London_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol) // London High line
- var London_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_LondonLevelCol) // London Low line
- 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)
- 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)
- var LondonSessionStart = time // To register the timestap when the London Session begins
- if (time == LondonSessionTime and showIndicator) // When a new London Killzone Session is started
- log_msg("London Killzone Session Start", 'low')
- LondonSessionStart := time // Store the Session Starting timestamp
- // We are entering London Session hours; reset hi/lo.
- London_hi := high
- London_lo := low
- // Initialize the drawings for today
- if showLevel_London
- 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
- 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
- if showLabels
- 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)
- label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
- if showCaptions
- label.set_text(LondonHighLabel, "London High")
- 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)
- label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
- if showCaptions
- label.set_text(LondonLowLabel, "London Low")
- else if (time > LondonSessionTime and time <= LondonSessionEndTime)
- // We are in allowed LondonSession hours; track hi/lo.
- London_hi := math.max(high, London_hi)
- London_lo := math.min(low, London_lo)
- if (London_hi > London_hi[1])
- if showLevel_London
- line.set_xy1(id=London_line_hi, x=time, y=London_hi)
- line.set_xy2(id=London_line_hi, x=NYSessionEndTime, y=London_hi)
- if showLabels
- label.set_xy(id=LondonHighLabel, x=NYSessionEndTime, y=London_hi)
- label.set_xy(id=LondonLowLabel, x=NYSessionEndTime, y=London_lo)
- label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
- label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
- if (London_lo < London_lo[1])
- if showLevel_London
- line.set_xy1(id=London_line_lo, x=time, y=London_lo)
- line.set_xy2(id=London_line_lo, x=NYSessionEndTime, y=London_lo)
- if showLabels
- label.set_xy(id=LondonHighLabel, x=NYSessionEndTime, y=London_hi)
- label.set_xy(id=LondonLowLabel, x=NYSessionEndTime, y=London_lo)
- label.set_tooltip(LondonHighLabel, "London High: " + str.tostring(London_hi))
- label.set_tooltip(LondonLowLabel, "London Low: " + str.tostring(London_lo))
- // END London Session Code
- // ***
- //
- // Begin Globex Session Code
- if sessionBegins(i_GlobexSession) and showIndicator // When a new Globex Session is started
- log_msg("Globex Session Start", 'low')
- GlobexSessionStart := time // Store the Session Starting timestamp
- if NYSessionEndTime < GlobexSessionStart // If the NYSessionEndTime is in the past, then add 1 day
- NYSessionEndTime := NYSessionEndTime+86400000 // Add 1 day, so level lines will be drawn to the right like they should
- if dayofweek == dayofweek.sunday and (syminfo.type == "futures" or syminfo.type == "cfd" or syminfo.type == "stock" or syminfo.type == "index" or syminfo.type == "forex")
- NYSessionEndTime := NYSessionEndTime+(2*86400000) // Add another day, so level lines will be drawn to the right like they should
- // We are entering Globex Session hours; reset hi/lo.
- Globex_open := open
- log_msg("Globex Open: " + str.tostring(Globex_open), 'low')
- Globex_hi := high
- Globex_lo := low
- // Initialize the drawings for today
- if showGlobex // Draw the Globex Open Vertical Line
- Globex_line := vline(GlobexSessionStart, i_GlobexSessionCol, linestyle, i_lineWidth)
- if showGlobexDrawings
- // Create new objects for today
- if showGlobexOpenLine // Only paints once.
- 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
- if showLabels
- 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)
- label.set_tooltip(GlobexOpenLabel, "Globex Open: " + str.tostring(Globex_open))
- if showCaptions
- label.set_text(GlobexOpenLabel, "Globex Open")
- 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
- 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
- if showLabels
- 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)
- 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)
- label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
- label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
- if showCaptions
- label.set_text(GlobexHighLabel, "Globex High")
- if showCaptions
- label.set_text(GlobexLowLabel, "Globex Low")
- else if GlobexSession
- // We are in allowed GlobexSession hours; track hi/lo.
- Globex_hi := math.max(high, Globex_hi)
- Globex_lo := math.min(low, Globex_lo)
- if (Globex_hi > Globex_hi[1])
- if showGlobexDrawings
- line.set_xy1(id=Globex_line_hi, x=time, y=Globex_hi)
- line.set_xy2(id=Globex_line_hi, x=NYSessionEndTime, y=Globex_hi)
- if showLabels
- label.set_xy(id=GlobexHighLabel, x=NYSessionEndTime, y=Globex_hi)
- label.set_xy(id=GlobexLowLabel, x=NYSessionEndTime, y=Globex_lo)
- label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
- label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
- if (Globex_lo < Globex_lo[1])
- if showGlobexDrawings
- line.set_xy1(id=Globex_line_lo, x=time, y=Globex_lo)
- line.set_xy2(id=Globex_line_lo, x=NYSessionEndTime, y=Globex_lo)
- if showLabels
- label.set_xy(id=GlobexHighLabel, x=NYSessionEndTime, y=Globex_hi)
- label.set_xy(id=GlobexLowLabel, x=NYSessionEndTime, y=Globex_lo)
- label.set_tooltip(GlobexHighLabel, "Globex High: " + str.tostring(Globex_hi))
- label.set_tooltip(GlobexLowLabel, "Globex Low: " + str.tostring(Globex_lo))
- // END Globex Session Code
- // Begin NYKZ Killzone Session Code
- var float NYKZ_hi = na // High for the NYKZ Session
- var float NYKZ_lo = na // Low for the NYKZ Session
- var NYKZ_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZLevelCol) // NYKZ High line
- var NYKZ_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYKZLevelCol) // NYKZ Low line
- 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)
- 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)
- var NYKZSessionStart = time // To register the timestap when the NYKZ Session begins
- if (time == NYKZSessionTime and showIndicator) // When a new NYKZ Killzone Session is started
- log_msg("NY Killzone Session Start", 'low')
- NYKZSessionStart := time // Store the Session Starting timestamp
- // We are entering NYKZ Session hours; reset hi/lo.
- NYKZ_hi := high
- NYKZ_lo := low
- // Initialize the drawings for today
- if showLevel_NYKZ
- 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
- 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
- if showLabels
- 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)
- 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)
- label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
- label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
- if showCaptions
- label.set_text(NYKZHighLabel, "Lunch High")
- if showCaptions
- label.set_text(NYKZLowLabel, "Lunch Low")
- else if (time > NYKZSessionTime and time <= NYKZSessionEndTime)
- // We are in allowed NYKZSession hours; track hi/lo.
- NYKZ_hi := math.max(high, NYKZ_hi)
- NYKZ_lo := math.min(low, NYKZ_lo)
- if (NYKZ_hi > NYKZ_hi[1])
- if showLevel_NYKZ
- line.set_xy1(id=NYKZ_line_hi, x=time, y=NYKZ_hi)
- line.set_xy2(id=NYKZ_line_hi, x=NYSessionEndTime, y=NYKZ_hi)
- if showLabels
- label.set_xy(id=NYKZHighLabel, x=NYSessionEndTime, y=NYKZ_hi)
- label.set_xy(id=NYKZLowLabel, x=NYSessionEndTime, y=NYKZ_lo)
- label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
- label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
- if (NYKZ_lo < NYKZ_lo[1])
- if showLevel_NYKZ
- line.set_xy1(id=NYKZ_line_lo, x=time, y=NYKZ_lo)
- line.set_xy2(id=NYKZ_line_lo, x=NYSessionEndTime, y=NYKZ_lo)
- if showLabels
- label.set_xy(id=NYKZHighLabel, x=NYSessionEndTime, y=NYKZ_hi)
- label.set_xy(id=NYKZLowLabel, x=NYSessionEndTime, y=NYKZ_lo)
- label.set_tooltip(NYKZHighLabel, "Lunch High: " + str.tostring(NYKZ_hi))
- label.set_tooltip(NYKZLowLabel, "Lunch Low: " + str.tostring(NYKZ_lo))
- // END NYKZ Session Code
- // ***
- // Begin NYPM Killzone Session Code
- var float NYPM_hi = na // High for the NYKZ Session
- var float NYPM_lo = na // Low for the NYKZ Session
- var NYPM_line_hi = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMLevelCol) // NYKZ High line
- var NYPM_line_lo = line.new(x1=na, y1=na, x2=na, xloc=xloc.bar_time, y2=close, color=i_NYPMLevelCol) // NYKZ Low line
- 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)
- 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)
- var NYPMSessionStart = time // To register the timestap when the NYPM Session begins
- if (time == NYPMSessionTime and showIndicator) // When a new NYKZ Killzone Session is started
- log_msg("NY Killzone Session Start", 'low')
- NYPMSessionStart := time // Store the Session Starting timestamp
- // We are entering NYKZ Session hours; reset hi/lo.
- NYPM_hi := high
- NYPM_lo := low
- // Initialize the drawings for today
- if showLevel_NYPM
- 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
- 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
- if showLabels
- 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)
- 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)
- label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
- label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
- if showCaptions
- label.set_text(NYPMHighLabel, "PM High")
- if showCaptions
- label.set_text(NYPMLowLabel, "PM Low")
- else if (time > NYPMSessionTime and time <= NYPMSessionEndTime)
- // We are in allowed NYKZSession hours; track hi/lo.
- NYPM_hi := math.max(high, NYPM_hi)
- NYPM_lo := math.min(low, NYPM_lo)
- if (NYPM_hi > NYPM_hi[1])
- if showLevel_NYPM
- line.set_xy1(id=NYPM_line_hi, x=time, y=NYPM_hi)
- line.set_xy2(id=NYPM_line_hi, x=NYSessionEndTime, y=NYPM_hi)
- if showLabels
- label.set_xy(id=NYPMHighLabel, x=NYSessionEndTime, y=NYPM_hi)
- label.set_xy(id=NYPMLowLabel, x=NYSessionEndTime, y=NYPM_lo)
- label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
- label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
- if (NYPM_lo < NYPM_lo[1])
- if showLevel_NYPM
- line.set_xy1(id=NYPM_line_lo, x=time, y=NYPM_lo)
- line.set_xy2(id=NYPM_line_lo, x=NYSessionEndTime, y=NYPM_lo)
- if showLabels
- label.set_xy(id=NYPMHighLabel, x=NYSessionEndTime, y=NYPM_hi)
- label.set_xy(id=NYPMLowLabel, x=NYSessionEndTime, y=NYPM_lo)
- label.set_tooltip(NYPMHighLabel, "PM High: " + str.tostring(NYPM_hi))
- label.set_tooltip(NYPMLowLabel, "PM Low: " + str.tostring(NYPM_lo))
- // END NYKZ Session Code
- // ***
- // Create and fill log table //
- var log_tbl = table.new(position.bottom_left, 3, log_show_msg + 2, border_width = 1)
- if (barstate.isconfirmed and showDebug)
- table.merge_cells(log_tbl, 0, 0, 2, 0)
- table.cell(log_tbl, 0, 0, 'Debug Logging', text_size=size.normal, text_color=color.black, bgcolor = color.gray, text_halign=text.align_center)
- table.cell(log_tbl, 0, 1, "Bar #", bgcolor = color.gray, text_size = size.small)
- table.cell(log_tbl, 1, 1, "Time", bgcolor = color.gray, text_size = size.small)
- table.cell(log_tbl, 2, 1, "Message", bgcolor = color.gray, text_size = size.small)
- for i = 1 to log_show_msg
- arr_i = array.size(msg_arr) - log_show_msg + i - 1 - log_offset
- if (arr_i < 0)
- break
- type = array.get(type_arr, arr_i)
- msg_color = type == 'low' ? #cccccc :
- type == 'medium' ? #F5AC4E :
- type == 'high' ? #DD4224 : na
- table.cell(log_tbl, 0, i+1, str.tostring(array.get(bar_arr, arr_i)), bgcolor = msg_color, text_size = size.small)
- table.cell(log_tbl, 1, i+1, array.get(time_arr, arr_i), bgcolor = msg_color, text_size = size.small)
- table.cell(log_tbl, 2, i+1, array.get(msg_arr, arr_i), bgcolor = msg_color, text_size = size.small)
- ///////////////////////////////
- // Testing area
- //log_msg(str.format("NYMNOpenTime: {0,date, y-MM-d'.' hh:mm:ss}" ,NYMNOpenTime), "low")
- //log_msg("TodayStart Timestamp: " + str.tostring(TodayStart), 'low')
- // Start Plotting
- 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))
- 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))
- 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))
- 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))
- 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))
- 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))
- 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))
- // Do housekeeping of old objects - remove everything before the number of days set
- housekeeping(i_showDaysDraw)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement