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/
- // © fxdmn
- // @version=5
- indicator(title="dmn's ICT Toolkit", shorttitle="dmn's ICT Toolkit", overlay=true, max_lines_count=500)
- // ███████╗██╗ ██╗██████╗ ███╗ ███╗███╗ ██╗
- // ██╔════╝╚██╗██╔╝██╔══██╗████╗ ████║████╗ ██║
- // █████╗ ╚███╔╝ ██║ ██║██╔████╔██║██╔██╗ ██║
- // ██╔══╝ ██╔██╗ ██║ ██║██║╚██╔╝██║██║╚██╗██║
- // ██║ ██╔╝ ██╗██████╔╝██║ ╚═╝ ██║██║ ╚████║
- // ╚═╝ ╚═╝ ╚═╝╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═══╝
- //{ Constants
- var CBDR_SESSION = "1400-2000"
- var FLOUT_SESSION = "1500-2359"
- var ASIA_SESSION = "2000-2400"
- var TRUEDAY_SESSION = "0000-0001"
- var DAILY_OPEN_SESSION = "1700-1704"
- var LONDON_OPEN_KILLZONE_SESSION = "0200-0500"
- var NY_OPEN_KILLZONE_SESSION = "0830-1100"
- var LONDON_CLOSE_KILLZONE_SESSION = "1000-1130"
- var CBDR_LABEL_NAME = "CBDR"
- var FLOUT_LABEL_NAME = "Flout"
- var ASIA_LABEL_NAME = "AR"
- var TT_ADR_LOOKBACK_INPUT = "Number of closed candles used to calculate the ADR"
- var TT_SESSION_ZONE_INPUT = "Change if not displaying New York midnight correctly"
- var TT_TABLE_LOC_INPUT = "Shows x days average daily range, current daily range, CBDR range and Asian range"
- var TT_ADR_DYNAMIC_TEXT = "Colors the ADR box information dynamically based on the ranges. Readable using most sensible background colors. Disabling this option will make the text black or white depending on percieved brighness of the background color"
- var DECIMALS = int(math.log10(1/syminfo.mintick))
- var PIP = math.pow(10, DECIMALS-1)
- //}
- //{ Inputs
- sessionZoneInput = input.string('GMT-5', title='New York Time Zone', tooltip=TT_SESSION_ZONE_INPUT, options=['GMT-11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-2', 'GMT-1', 'GMT', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+4', 'GMT+5', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11', 'GMT+12'])
- //{ ADR inputs
- adrLookbackInput = input.int(5, "ADR Lookback", 1, tooltip=TT_ADR_LOOKBACK_INPUT)
- tableBgInput = input.color(color.new(#ffffff, 5), "", inline="table")
- tableLocInput = input.string("Top Right", "", ["Top Left", "Bottom Left", "Top Right", "Bottom Right"], TT_TABLE_LOC_INPUT, inline="table")
- tableToggleInput = input.bool(true, "Daily stat box", "", inline="table")
- tableDynamicTextInputToggle = input.bool(true, "Dynamic Text Color", TT_ADR_DYNAMIC_TEXT, inline="table")
- //}
- //{ CBDR Box inputs
- cbdrBoxColorInput = input.color(color.new(color.green, 85), "", group="CBDR", inline="CBDR_show")
- cbdrBoxToggleInput = input.bool(true,"Box", group="CBDR", inline="CBDR_show")
- cbdrHistoryInput = input.bool(true, "History", group="CBDR", inline="CBDR_show")
- cbdrBorderColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_border")
- cbdrBorderSizeInput = input.int(1, "Border", minval=0, maxval=3, group="CBDR", inline="CBDR_border")
- cbdrBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="CBDR", inline="CBDR_border")
- cbdrLabelColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_label")
- cbdrRangeToggleInput = input.bool(true,"Pips", group="CBDR", inline="CBDR_label")
- cbdrNameToggleInput = input.bool(false,"Name", group="CBDR", inline="CBDR_label")
- cbdrProjectionColorInput = input.color(color.green, "", group="CBDR", inline="CBDR_ext")
- cbdrProjectionToggleInput = input.bool(false, "Std. Deviations", group="CBDR", inline="CBDR_ext")
- cbdrProjectionHistoryInput = input.bool(false, "History", group="CBDR", inline="CBDR_ext")
- //}
- //{ Flout Box inputs
- floutBoxColorInput = input.color(color.rgb(76, 122, 175, 85), "", group="flout", inline="flout_show")
- floutToggleInput = input.bool(false,"Box", group="flout", inline="flout_show")
- floutHistoryToggleInput = input.bool(true, "History", group="flout", inline="flout_show")
- floutBorderColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="flout_border")
- floutBorderSizeInput = input.int(1, "Border", minval=0, maxval=3, group="flout", inline="flout_border")
- floutBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="flout", inline="flout_border")
- floutLabelColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="flout_label")
- floutRangeToggleInput = input.bool(true,"Pips", group="flout", inline="flout_label")
- floutNameToggleInput = input.bool(false,"Name", group="flout", inline="flout_label")
- floutProjectionColorInput = input.color(color.rgb(76, 122, 175), "", group="flout", inline="floutExt")
- floutProjectionToggleInput = input.bool(false, "Std. Deviations", group="flout", inline="floutExt")
- floutProjectionHistoryInput = input.bool(false, "History", group="flout", inline="floutExt")
- //}
- //{ Asia Box inputs
- asiaBoxColorInput = input.color(color.new(color.purple, 85), "", group="AR", inline="asia_show")
- asiaToggleInput = input.bool(true,"Box", group="AR", inline="asia_show")
- asiaHistoryInput = input.bool(true, "History", group="AR", inline="asia_show")
- asiaBorderColorInput = input.color(color.purple, "", group="AR", inline="AR_border")
- asiaBorderSizeInput = input.int(1, "Border", minval=0, maxval=3,group="AR", inline="AR_border")
- asiaBorderTypeInput = input.string("Dotted", "", options=['Solid', 'Dotted', 'Dashed'],group="AR", inline="AR_border")
- asiaLabelColorInput = input.color(color.purple, "", group="AR", inline="asia_label")
- asiaRangeToggleInput = input.bool(true,"Pips", group="AR", inline="asia_label")
- asiaNameToggleInput = input.bool(false,"Name", group="AR", inline="asia_label")
- asiaProjectionColorInput = input.color(color.purple, "", group="AR", inline="asiaExt")
- asiaProjectionToggle = input.bool(false, "Std. Deviations", group="AR", inline="asiaExt")
- asiaProjectionHistoryInput = input.bool(false, "History", group="AR", inline="asiaExt")
- //}
- //{ Trueday inputs
- truedayColorInput = input.color(color.new(#838383, 18), "", group="Levels and Lines", inline="trueDay")
- truedayWidthInput = input.int(1, "", 1, 3, group="Levels and Lines", inline="trueDay")
- truedayTypeInput = input.string("Dashed", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="trueDay")
- truedayToggleInput = input.bool(true,"True Day", inline="trueDay", group="Levels and Lines")
- truedayHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="trueDay")
- midnightColorInput = input.color(color.new(#ffcb3b, 5), "", group="Levels and Lines", inline="midnight")
- midnightWidthInput = input.int(2, "", 1, 3, group="Levels and Lines", inline="midnight")
- midnightTypeInput = input.string("Solid", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="midnight")
- midnightToggleInput = input.bool(true,"Midnight", inline="midnight", group="Levels and Lines")
- midnightHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="midnight")
- dailyOpenColorInput = input.color(color.new(#e75845, 5), "", group="Levels and Lines", inline="daily")
- dailyOpenWidthInput = input.int(2, "", 1, 3, group="Levels and Lines", inline="daily")
- dailyOpenTypeInput = input.string("Solid", "", options=['Solid', 'Dotted', 'Dashed'],group="Levels and Lines", inline="daily")
- dailyOpenToggleInput = input.bool(false,"Daily Open", inline="daily", group="Levels and Lines")
- dailyOpenHistoryToggleInput = input.bool(true, "History", group="Levels and Lines", inline="daily")
- //}
- //{ Killzone inputs
- killzoneToggleInput = input.bool(true, "Killzones", group="Killzones", inline="kzToggle")
- killzoneHistoryToggleInput = input.bool(true, "History", group="Killzones", inline="kzToggle")
- killzoneLondonOpenColorInput = input.color(color.new(#515cbb, 5), "", group="Killzones", inline="kzLO")
- killzoneLondonOpenSessionInput = input.session(LONDON_OPEN_KILLZONE_SESSION, "", group="Killzones", inline="kzLO")
- killzoneLondonOpenToggleInput = input.bool(true, "London", group="Killzones", inline="kzLO")
- killzoneNyColorInput = input.color(color.new(#f3c547, 5), "", group="Killzones", inline="kzNY")
- killzoneNyOpenSessionInput = input.session(NY_OPEN_KILLZONE_SESSION, "", group="Killzones", inline="kzNY")
- killzoneNyToggleInput = input.bool(true, "New York", group="Killzones", inline="kzNY")
- killzoneLondonCloseColorInput = input.color(color.new(#515cbb, 5), "", group="Killzones", inline="kzLC")
- killzoneLondonCloseSessionInput = input.session(LONDON_CLOSE_KILLZONE_SESSION, "", group="Killzones", inline="kzLC")
- killzoneLondonCloseToggleInput = input.bool(true, "London Close", group="Killzones", inline="kzLC")
- //}
- //}
- //{ FUNCTIONS
- hours(int h, int m=0) =>
- //@function Returns UNIX time a certain number hours from now.
- //@param h (int) number of hours
- //@param m (int) (optional) number of minutes
- time+(3600000*h)+(60000*m)
- stringToHour(s) =>
- //@function Converts session input strings to integers for using with the hours() function
- //@param s session string
- //@return (int) hours part of the session string input parameter
- math.round(str.tonumber(str.substring(s, 0, 2)))
- stringToMinutes(s) =>
- //@function Converts session input strings to integers for using with the hours() function
- //@param s session string
- //@return (int) minutes part of the session string input parameter
- math.round(str.tonumber(str.substring(s, 2, 4)))
- averageRange(h, l, n) =>
- //@function Calculate the average range in pips of a number of bars
- //@param h = high, l = low, n = number of bars
- r = 0.0
- for i = 1 to n
- r += h[i]-l[i]
- PIP*r/n
- addLines(a, x1, x2, y, c, n) =>
- //@function Adds horizonal lines to a line array
- //@param a = array id, x1 & x2 = x coordinates, y = y coordinate, c = color, n = number of lines
- for i=0 to n-1
- array.push(a, line.new(x1, y, x2, y, xloc=xloc.bar_time, color=c, style=line.style_solid, width=1))
- delLines(a) =>
- //@function Delete all lines in a line array
- //@param a = line array
- if array.size(a) > 0
- for i=0 to array.size(a)-1
- line.delete(array.get(a, i))
- setLineArrayY(a, y, spacing, m) =>
- //@function moves all lines in a line array and space them based on a range, starting at y, m=1 for upward spacing, -1 for downward
- //@param a = line array, y = y coordinate to start from, spacing = distance between lines, m = upward or downward spacing (+/-1)
- for [i, l] in a
- float step=(i+1) * spacing * m
- line.set_y1(l, y+step)
- line.set_y2(l, y+step)
- lineset_y(l, y) =>
- //@function Makes a line horizontal at a location.abovebar
- //@param l = line id, y = y coordinate
- line.set_y1(l, y)
- line.set_y2(l, y)
- inSession(sessionTime, sessionTimeZone=syminfo.timezone) =>
- //@function Checks if a session is active
- //@param SessionTime = session start and end, sessionTimeZone = optional timezone parameter
- not na(time(timeframe.period, sessionTime, sessionTimeZone))
- getBrightness(color c) =>
- //@function Calculates percieved brightness of a color
- //@param c (color)
- //@returns (float) brightness of c between 0 and 255
- r = color.r(c)
- g = color.g(c)
- b = color.b(c)
- math.sqrt(r*r*0.241 + g*g*0.691 + b*b*0.068)
- //}
- //{ CBDR vars
- var cbdrHighPrice = 0.0
- var cbdrLowPrice = 0.0
- var cbdrRange = 0.0
- var box cbdrBox = na
- var cbdrBorderStyle = cbdrBorderTypeInput == "Solid" ? line.style_solid : cbdrBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- var label cbdrLabel = na
- var cbdrLabelText = cbdrNameToggleInput and cbdrRangeToggleInput ? CBDR_LABEL_NAME + ": " : cbdrNameToggleInput ? CBDR_LABEL_NAME : ""
- var array<line> cbdrLinesHi = array.new<line>()
- var array<line> cbdrLinesLo = array.new<line>()
- //}
- //{ Flout vars
- var floutHighPrice = 0.0
- var floutLowPrice = 0.0
- var floutRange = 0.0
- var box floutBox = na
- var floutBorderStyle = floutBorderTypeInput == "Solid" ? line.style_solid : floutBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- var label floutLabel = na
- var floutLabelText = floutNameToggleInput and floutRangeToggleInput ? FLOUT_LABEL_NAME + ": " : floutNameToggleInput ? FLOUT_LABEL_NAME : ""
- var line floutLineMid = na
- var array<line> floutLinesHi = array.new<line>()
- var array<line> floutLinesLo = array.new<line>()
- //}
- //{ Asian vars
- var asiaHighPrice = 0.0
- var asiaLowPrice = 0.0
- var asiaRange = 0.0
- var box asiaBox = na
- var asiaBorderStyle = asiaBorderTypeInput == "Solid" ? line.style_solid : asiaBorderTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- var label asiaLabel = na
- var asiaLabelText = asiaNameToggleInput and asiaRangeToggleInput ? ASIA_LABEL_NAME + ": " : asiaNameToggleInput ? ASIA_LABEL_NAME : ""
- var array<line> asiaLinesHi = array.new<line>()
- var array<line> asiaLinesLo = array.new<line>()
- //}
- //{ Trueday vars
- var truedayOpenPrice = 0.0
- var truedayHighPrice = 0.0
- var truedayLowPrice = 0.0
- var label truedayLabel = na
- var line truedayLine = na
- var line midnightLine = na
- var killzoneHighPrice = 0.0
- var killzoneLowPrice = 0.0
- var line kzLoLine1 = na
- var line kzLoLine2 = na
- var line kzNYLine1 = na
- var line kzNYLine2 = na
- var line kzLCLine1 = na
- var line kzLCLine2 = na
- var dailyOpenPrice = 0.0
- var line dailyOpenLine = na
- var truedayStyle = truedayTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- var midnightStyle = midnightTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- var dailyOpenStyle = dailyOpenTypeInput == "Solid" ? line.style_solid : truedayTypeInput == "Dotted" ? line.style_dotted : line.style_dashed
- //}
- //{ Killzone vars
- var LONDON_OPEN_KILLZONE_START = str.substring(killzoneLondonOpenSessionInput, 0, 4)
- var LONDON_OPEN_KILLZONE_END = str.substring(killzoneLondonOpenSessionInput, 5, 9)
- var NY_OPEN_KILLZONE_START = str.substring(killzoneNyOpenSessionInput, 0, 4)
- var NY_OPEN_KILLZONE_END = str.substring(killzoneNyOpenSessionInput, 5, 9)
- var LONDON_CLOSE_KILLZONE_START = str.substring(killzoneLondonCloseSessionInput, 0, 4)
- var LONDON_CLOSE_KILLZONE_END = str.substring(killzoneLondonCloseSessionInput, 5, 9)
- //}
- //{ Session Start checks
- inCbdrSession = inSession(CBDR_SESSION, sessionZoneInput) and timeframe.isintraday
- cbdrStart = inCbdrSession and not inCbdrSession[1]
- inFloutSession = inSession(FLOUT_SESSION, sessionZoneInput) and timeframe.isintraday
- floutStart = inFloutSession and not inFloutSession[1]
- inasiaSession = inSession(ASIA_SESSION, sessionZoneInput) and timeframe.isintraday
- asiaStart = inasiaSession and not inasiaSession[1]
- intruedaySession = inSession(TRUEDAY_SESSION, sessionZoneInput) and timeframe.isintraday
- truedayStart = intruedaySession and not intruedaySession[1]
- indailyOpenSession = inSession(DAILY_OPEN_SESSION, sessionZoneInput) and timeframe.isintraday
- dailyOpenStart = indailyOpenSession and not indailyOpenSession[1]
- inkzLOSession = inSession(killzoneLondonOpenSessionInput, sessionZoneInput) and timeframe.isintraday
- kzLOStart = inkzLOSession and not inkzLOSession[1]
- inkzNySession = inSession(killzoneNyOpenSessionInput, sessionZoneInput) and timeframe.isintraday
- kzNyStart = inkzNySession and not inkzNySession[1]
- inkzLcSession = inSession(killzoneLondonCloseSessionInput, sessionZoneInput) and timeframe.isintraday
- kzLcStart = inkzLcSession and not inkzLcSession[1]
- if cbdrStart //are we at the start of a CBDR?
- if not cbdrHistoryInput //is CBDR history off?
- box.delete(cbdrBox) //
- label.delete(cbdrLabel) //then delete previous boxes and labels
- if not cbdrProjectionHistoryInput or not cbdrHistoryInput //is CBDR Projection history off OR CBDR history off?
- delLines(cbdrLinesHi) //
- delLines(cbdrLinesLo) //then delete previous CBDR projections
- array.clear(cbdrLinesHi) //
- array.clear(cbdrLinesLo) //Clean up the CBDR Line arrays
- cbdrHighPrice := high //
- cbdrLowPrice := low //Set the initial high and low of the CBDR
- cbdrRange := 0.0 //
- asiaRange := 0.0 //Reset the range of the CBDR and Asian Range
- else if inCbdrSession //are we in the CBDR session?
- cbdrHighPrice := math.max(cbdrHighPrice, high) //
- cbdrLowPrice := math.min(cbdrLowPrice, low) //check for new high and low
- cbdrRange := (PIP*(cbdrHighPrice-cbdrLowPrice)) //calculate the CBDR and convert to pips
- if floutStart
- if not floutHistoryToggleInput //is flout history off?
- box.delete(floutBox) //
- label.delete(floutLabel) //then delete previous boxes and labels
- if not floutProjectionHistoryInput or not floutHistoryToggleInput //is flout Projection history off OR flout history off?
- line.delete(floutLineMid)
- delLines(floutLinesHi) //
- delLines(floutLinesLo) //then delete previous flout projections
- array.clear(floutLinesHi) //
- array.clear(floutLinesLo) //Clean up the flout Line arrays
- floutHighPrice := high //
- floutLowPrice := low //reset flout high and low
- else if inFloutSession //are we already in the flout?
- floutHighPrice := math.max(floutHighPrice, high) //check for new flout high
- floutLowPrice := math.min(floutLowPrice, low) //check for new flout low
- floutRange := PIP*(floutHighPrice-floutLowPrice) //calculate current flout range and convert to pips
- if asiaStart //are we at the start of a new asian range?
- if not asiaHistoryInput //is asian range history off?
- box.delete(asiaBox) //
- label.delete(asiaLabel) //then delete previous boxes and labels
- if not asiaProjectionHistoryInput or not asiaHistoryInput //is asian range rrojection history off OR asian range history off?
- delLines(asiaLinesHi) //
- delLines(asiaLinesLo) //then delete previous asian range projections
- array.clear(asiaLinesHi) //
- array.clear(asiaLinesLo) //Clean up the asian Line arrays
- asiaHighPrice := high //
- asiaLowPrice := low //reset asian range high and low
- else if inasiaSession //are we already in the asian range?
- asiaHighPrice := math.max(asiaHighPrice, high) //check for new asian range high
- asiaLowPrice := math.min(asiaLowPrice, low) //check for new asian range low
- asiaRange := (PIP*(asiaHighPrice-asiaLowPrice)) //calculate current asian range and convert to pips
- if dailyOpenStart
- if not dailyOpenHistoryToggleInput
- line.delete(dailyOpenLine)
- if dailyOpenToggleInput
- dailyOpenLine := line.new(time, open, dayofweek(time) == 6 ? hours(72) : hours(24), open, xloc=xloc.bar_time, color=dailyOpenColorInput, style=dailyOpenStyle, width=dailyOpenWidthInput)
- if truedayStart //are we at the start of a new true day?
- if not midnightHistoryToggleInput
- line.delete(midnightLine)
- if not truedayHistoryToggleInput
- line.delete(truedayLine)
- if not killzoneHistoryToggleInput //is killzone history off?
- line.delete(kzLoLine1) //
- line.delete(kzLoLine2) //
- line.delete(kzLCLine1) //
- line.delete(kzLCLine2) //
- line.delete(kzNYLine1) //
- line.delete(kzNYLine2) //then delete previous killzone lines
- killzoneHighPrice := high //
- killzoneLowPrice := low //reset killzone line levels
- if killzoneToggleInput //are killzones enabled?
- if killzoneLondonOpenToggleInput //is london killzone enabled?
- kzLoLine1 := line.new(hours(stringToHour(LONDON_OPEN_KILLZONE_START), stringToMinutes(LONDON_OPEN_KILLZONE_START)),
- killzoneHighPrice,
- hours(stringToHour(LONDON_OPEN_KILLZONE_END), stringToMinutes(LONDON_OPEN_KILLZONE_END)),
- killzoneHighPrice, xloc=xloc.bar_time, color=killzoneLondonOpenColorInput, style=line.style_solid, width=4)
- kzLoLine2 := line.copy(kzLoLine1) //draw london open killzone lines from it's start to end
- if killzoneNyToggleInput //is new york killzone enabled?
- kzNYLine1 := line.new(hours(stringToHour(NY_OPEN_KILLZONE_START), stringToMinutes(NY_OPEN_KILLZONE_START)),
- killzoneHighPrice,
- hours(stringToHour(NY_OPEN_KILLZONE_END), stringToMinutes(NY_OPEN_KILLZONE_END)),
- killzoneHighPrice, xloc=xloc.bar_time, color=killzoneNyColorInput, style=line.style_solid, width=4)
- kzNYLine2 := line.copy(kzNYLine1) //draw new york open killzone lines from it's start to end
- if killzoneLondonCloseToggleInput //is london close killzone enabled?
- kzLCLine1 := line.new(hours(stringToHour(LONDON_CLOSE_KILLZONE_START), stringToMinutes(LONDON_CLOSE_KILLZONE_START)),
- killzoneHighPrice,
- hours(stringToHour(LONDON_CLOSE_KILLZONE_END), stringToMinutes(LONDON_CLOSE_KILLZONE_END)),
- killzoneHighPrice, xloc=xloc.bar_time, color=killzoneLondonCloseColorInput, style=line.style_solid, width=4)
- kzLCLine2 := line.copy(kzLCLine1) //draw london close killzone lines from it's start to end
- if midnightToggleInput //draw the new york midnight price level line if it's enabled
- midnightLine := line.new(time, open, dayofweek(time) == 6 ? hours(72) : hours(24), open, xloc=xloc.bar_time, color=midnightColorInput, style=midnightStyle, width=midnightWidthInput)
- if truedayToggleInput //draw the true day deliniation if enabled
- truedayLine := line.new(time, open, time, open+1, xloc=xloc.bar_time, extend=extend.both, color=truedayColorInput, style=truedayStyle, width=truedayWidthInput)
- //}
- //{ Draw stuff
- if cbdrStart and cbdrBoxToggleInput
- cbdrBox := box.new(bar_index, na, na, na, cbdrBorderColorInput, cbdrBorderSizeInput, cbdrBorderStyle, bgcolor=cbdrBoxColorInput)
- cbdrLabel := label.new(bar_index, high, "", style=label.style_none, textcolor=cbdrLabelColorInput, textalign=text.align_center)
- if cbdrProjectionToggleInput
- s = dayofweek == 6 ? hours(54) : hours(6)
- h = dayofweek == 6 ? hours(72) : hours(24)
- addLines(cbdrLinesHi, s, h, high, cbdrProjectionColorInput, 4)
- addLines(cbdrLinesLo, s, h, high, cbdrProjectionColorInput, 4)
- if floutStart and floutToggleInput
- floutBox := box.new(bar_index, na, na, na, floutBorderColorInput, floutBorderSizeInput, floutBorderStyle, bgcolor=floutBoxColorInput)
- floutLabel := label.new(bar_index, high, "", xloc.bar_time, style=label.style_none, textcolor=floutLabelColorInput, textalign=text.align_center)
- if floutProjectionToggleInput
- s = dayofweek == 6 ? hours(57) : hours(9)
- h = dayofweek == 6 ? hours(71) : hours(23)
- floutLineMid :=line.new(s, high, h, high, xloc.bar_time, color=floutProjectionColorInput, style=line.style_dashed, width=1)
- addLines(floutLinesHi, s, h, high, floutProjectionColorInput, 4)
- addLines(floutLinesLo, s, h, high, floutProjectionColorInput, 4)
- if asiaStart and asiaToggleInput
- asiaBox := box.new(bar_index, na, na, na, asiaBorderColorInput, asiaBorderSizeInput, asiaBorderStyle, bgcolor=asiaBoxColorInput)
- asiaLabel := label.new(bar_index, high, "", style=label.style_none, textcolor=asiaLabelColorInput, textalign=text.align_center)
- if asiaProjectionToggle
- s = hours(4) // length of asian range session in hours
- h = dayofweek == 6 ? hours(66) : hours(18) // hours until next asian rage session
- addLines(asiaLinesHi, s, h, high, asiaProjectionColorInput, 4)
- addLines(asiaLinesLo, s, h, high, asiaProjectionColorInput, 4)
- //}
- //{ Update drawn stuff
- if inCbdrSession and cbdrBoxToggleInput
- true_cbdr = cbdrHighPrice-cbdrLowPrice
- box.set_top(cbdrBox, cbdrHighPrice)
- box.set_bottom(cbdrBox, cbdrLowPrice)
- box.set_right(cbdrBox, bar_index + 1)
- label.set_text(cbdrLabel, cbdrRangeToggleInput ? cbdrLabelText + str.tostring(cbdrRange) : cbdrLabelText)
- label.set_x(cbdrLabel, bar_index)
- label.set_y(cbdrLabel, cbdrHighPrice)
- setLineArrayY(cbdrLinesHi, cbdrHighPrice, true_cbdr, 1)
- setLineArrayY(cbdrLinesLo, cbdrLowPrice, true_cbdr, -1)
- if inFloutSession and floutToggleInput
- true_flout = (floutHighPrice-floutLowPrice)/2
- box.set_top(floutBox, floutHighPrice)
- box.set_bottom(floutBox, floutLowPrice)
- box.set_right(floutBox, bar_index + 1)
- label.set_text(floutLabel, floutRangeToggleInput ? floutLabelText + str.tostring(floutRange) : floutLabelText)
- label.set_x(floutLabel, hours(-1))
- label.set_y(floutLabel, floutHighPrice)
- lineset_y(floutLineMid, floutHighPrice-true_flout)
- setLineArrayY(floutLinesHi, floutHighPrice, true_flout, 1)
- setLineArrayY(floutLinesLo, floutLowPrice, true_flout, -1)
- if inasiaSession and asiaToggleInput
- true_asia = asiaHighPrice-asiaLowPrice
- box.set_top(asiaBox, asiaHighPrice)
- box.set_bottom(asiaBox, asiaLowPrice)
- box.set_right(asiaBox, bar_index + 1)
- label.set_text(asiaLabel, asiaRangeToggleInput ? asiaLabelText + str.tostring(asiaRange) : asiaLabelText)
- label.set_x(asiaLabel, bar_index-1)
- label.set_y(asiaLabel, asiaHighPrice)
- setLineArrayY(asiaLinesHi, asiaHighPrice, true_asia, 1)
- setLineArrayY(asiaLinesLo, asiaLowPrice, true_asia, -1)
- //}
- //{ Killzone lines
- killzoneHighPrice := math.max(killzoneHighPrice, high)
- killzoneLowPrice := math.min(killzoneLowPrice, low)
- lineset_y(kzLoLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
- lineset_y(kzLoLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
- lineset_y(kzNYLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
- lineset_y(kzNYLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
- lineset_y(kzLCLine1, killzoneHighPrice+(killzoneHighPrice-killzoneLowPrice)/4)
- lineset_y(kzLCLine2, killzoneLowPrice-(killzoneHighPrice-killzoneLowPrice)/4)
- //}
- //{ ADR Table
- averageDailyRangeRounded = math.round(request.security(syminfo.tickerid, "1D", averageRange(high, low, adrLookbackInput)),1) //set average daily range for the past 'adrLookbackInput' number of days and round it
- [currentDailyLow, currentDailyHigh] = request.security(syminfo.tickerid, "1D", [low, high]) //get current daily high and low
- currentDailyRangeRounded = math.round(PIP*(currentDailyHigh-currentDailyLow),1) //set current daily range and round it
- if tableToggleInput
- tablePosition = tableLocInput == "Top Left" ? position.top_left : tableLocInput == "Bottom Left" ? position.bottom_left : tableLocInput == "Top Right" ? position.top_right : position.bottom_right
- adrTable = table.new(tablePosition, 2, 4, tableBgInput, border_width = 1)
- bgBrightness = getBrightness(tableBgInput)
- color staticTextColor = bgBrightness > 130 ? color.black : color.white
- color dynamicGreen = staticTextColor
- color dynamicRed = staticTextColor
- color dynamicOrange = staticTextColor
- color currentDailyRangeColor = staticTextColor
- if tableDynamicTextInputToggle
- dynamicGreen := bgBrightness > 130 ? color.green : color.rgb(0, 255, 0)
- dynamicRed := bgBrightness > 130 ? color.rgb(155, 0, 0) : color.rgb(255, 0, 0)
- dynamicOrange := bgBrightness > 130 ? color.rgb(255, 152, 0) : color.rgb(255, 200, 0)
- currentDailyRangeColor := currentDailyRangeRounded/averageDailyRangeRounded < 0.5 ? dynamicGreen : currentDailyRangeRounded/averageDailyRangeRounded < 1.0 ? dynamicOrange : dynamicRed
- if adrLookbackInput and barstate.islast
- table.cell(adrTable, 0, 0, str.tostring(adrLookbackInput) + "ADR:", text_color=staticTextColor, text_halign = text.align_right)
- table.cell(adrTable, 1, 0, str.tostring(averageDailyRangeRounded), text_color=staticTextColor, text_halign = text.align_left)
- table.cell(adrTable, 0, 1, "CDR:", text_color=currentDailyRangeColor, text_halign = text.align_right)
- table.cell(adrTable, 1, 1, str.tostring(currentDailyRangeRounded), text_color=currentDailyRangeColor, text_halign = text.align_left)
- table.cell(adrTable, 0, 2, "CBDR:", text_color=cbdrRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_right)
- table.cell(adrTable, 1, 2, str.tostring(cbdrRange), text_color=cbdrRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_left)
- table.cell(adrTable, 0, 3, "AR:", text_color=asiaRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_right)
- table.cell(adrTable, 1, 3, asiaRange == 0.0 ? "n/a" : str.tostring(asiaRange), text_color=asiaRange <= 40 ? dynamicGreen : dynamicRed, text_halign = text.align_left)
- //}
- //{ DEBUGGING
- //debugTable = table.new(position.bottom_left, 1, 1, tableBgInput, border_width = 1)
- //debugText = str.tostring(getBrightness(color.green))
- //table.cell(debugTable, 0, 0, debugText, text_halign = text.align_left)
- //}
Advertisement
Add Comment
Please, Sign In to add comment