本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Deweinn
//@version=6
indicator('ICT_Deweinn_Tool', overlay=true, max_lines_count=500, max_boxes_count=500, max_labels_count=500)
import PineCoders/VisibleChart/4 as PCchart
// ============================================================
// CONSTANTS & OPTIONS
// ============================================================
LS0 = 'Solid'
LS1 = 'Dashed'
LS2 = 'Dotted'
TIMEZONE = 'America/New_York'
ONE_HOUR = 3600 * 1000
ONE_DAY = 24 * ONE_HOUR
MAX_HISTORY_DAYS = 5
// ============================================================
// INPUTS — ASIAN & MIDNIGHT RANGE
// ============================================================
var GRP1 = 'Time Settings — Adjust to 5m to get the correct time'
exchangeOffset = input.int(0, "Exchange Offset (hours)", group=GRP1)
AsiaTime = input.session('2000-2345', 'Asia Time', group=GRP1)
AsiaExtend = input.session('2000-2355', 'Asia H&L Line', group=GRP1)
MidnightTime = input.session('0000-0035', 'Midnight Range Time', group=GRP1)
MidnightExtend = input.session('0000-1505', 'Midnight H&L Line', group=GRP1)
asiaLineEndHour = input.int(17, "Asia lines extension end (NY hour)", minval=0, maxval=23, group=GRP1)
var GRP2 = "General Settings (Asia & Midnight)"
showAsia = input.bool(true, 'Asia Range', group=GRP2, inline='session', tooltip='Show Asia and/or Midnight Range')
showMidnight = input.bool(true, 'Midnight Range', group=GRP2, inline='session')
RHLlines = input.bool(true, 'Show Range Lines', group=GRP2)
middleRHLline = input.bool(true, 'Show Middle Range Line', group=GRP2)
showBackground = input.bool(true, 'Show Box', group=GRP2)
extendRHLLines = input.bool(true, 'Extend Range Lines', group=GRP2)
showAllHistory = input.bool(false, 'Show complete history', 'Might cause a slight drawing delay when panning/moving/zooming the chart.', group=GRP2)
extendToEndOfRHL = input.bool(false, 'Extend lines of all ranges to end of most recent session', group=GRP2)
showAsiaHLLines = input.bool(true, 'Show independent Asian High / Low lines', group=GRP2)
showAsiaLabels = input.bool(true, 'Show Asian High / Low labels', group=GRP2)
var GRP3 = "Styles (Asia & Midnight)"
linesWidth = input.int(1, 'Box And Lines Width', minval=1, maxval=4, group=GRP3)
RHLLineColor = input.color(#747e99, 'H&L Line Color', group=GRP3, inline='H&Lline')
RHLLineStyle = input.string(LS0, 'Style', options=[LS0, LS1, LS2], group=GRP3, inline='H&Lline')
middleLineColor = input.color(#089981, 'Middle Line Color', group=GRP3, inline='midline')
middleLineStyle = input.string(LS2, 'Style', options=[LS0, LS1, LS2], group=GRP3, inline='midline')
backgroundColor = input.color(color.new(#747e99, 85), 'Box Background Color', group=GRP3)
boxBorderSize = input.int(0, title="Box border size", minval=0, group=GRP3)
asiaHLLineColor = input.color(#747e99, 'Asian High/Low Line Color', group=GRP3)
asiaHLLineStyle = input.string(LS0, 'Asian High/Low Style', options=[LS0, LS1, LS2], group=GRP3)
labelTextColor = input.color(color.gray, 'Asian High/Low text color', group=GRP3)
labelTextSize = input.string("Small", "Asian High/Low text size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group=GRP3)
// ============================================================
// INPUTS — ICT KILLZONES & PREMARKET
// ============================================================
var GRP_KZ = "ICT Killzones (LKZ / NKZ)"
showKillzones = input.bool(true, "Show LKZ & NKZ boxes", group=GRP_KZ)
showPremarket = input.bool(true, "Show PreMarket boxes", group=GRP_KZ)
atrLength = input.int(14, "ATR Period", minval=1, group=GRP_KZ)
offsetATR = input.float(0.8, "Offset (× ATR)", minval=0.1, step=0.1, group=GRP_KZ)
heightATR = input.float(0.35, "Box height (× ATR)", minval=0.1, step=0.05, group=GRP_KZ)
preHeightATR = input.float(0.20, "PreMKT box height (× ATR)", minval=0.05, step=0.05, group=GRP_KZ)
kzBoxesTransparency = input.int(85, "Boxes transparency (%)", minval=0, maxval=100, group=GRP_KZ)
kzBorderTransparency = input.int(100, "Borders transparency (%)", minval=0, maxval=100, group=GRP_KZ)
kzBorderWidth = input.int(0, "Border width", minval=0, maxval=4, group=GRP_KZ)
kzBorderStyle = input.string("Solid", "Border style", options=["Solid", "Dotted", "Dashed"], group=GRP_KZ)
kzTextSize = input.string("Small", "Text size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group=GRP_KZ)
kzTextColor = input.color(color.black, "Text color", group=GRP_KZ)
// London Kill Zone (1H - 5H)
london_name = input.string("London Kill Zone", "London session name", group=GRP_KZ)
london_start = input.int(1, "London session start (hour)", minval=0, maxval=23, group=GRP_KZ)
london_end = input.int(5, "London session end (hour)", minval=0, maxval=23, group=GRP_KZ)
london_color = input.color(color.new(#747e99, 0), "London session color", group=GRP_KZ)
london_above = input.bool(false, "London above price", group=GRP_KZ)
// London PreMarket (1H - 2H)
london_pre_name = input.string("PreMKT", "London PreMarket name", group=GRP_KZ)
london_pre_start = input.int(1, "London PreMarket start (hour)", minval=0, maxval=23, group=GRP_KZ)
london_pre_end = input.int(2, "London PreMarket end (hour)", minval=0, maxval=23, group=GRP_KZ)
london_pre_color = input.color(color.new(#5b9bd5, 0), "London PreMarket color", group=GRP_KZ)
// New-York Kill Zone (7H - 10H)
ny_name = input.string("New-York Kill Zone", "New York session name", group=GRP_KZ)
ny_start = input.int(7, "New York session start (hour)", minval=0, maxval=23, group=GRP_KZ)
ny_end = input.int(10, "New York session end (hour)", minval=0, maxval=23, group=GRP_KZ)
ny_color = input.color(color.new(#747e99, 0), "New York session color", group=GRP_KZ)
ny_above = input.bool(true, "NY above price", group=GRP_KZ)
// NY PreMarket (7H - 8H30)
ny_pre_name = input.string("PreMKT", "New York PreMarket name", group=GRP_KZ)
ny_pre_start_h = input.int(7, "NY PreMarket start (hour)", minval=0, maxval=23, group=GRP_KZ)
ny_pre_start_m = input.int(0, "NY PreMarket start (minute)", minval=0, maxval=59, group=GRP_KZ)
ny_pre_end_h = input.int(8, "NY PreMarket end (hour)", minval=0, maxval=23, group=GRP_KZ)
ny_pre_end_m = input.int(30, "NY PreMarket end (minute)", minval=0, maxval=59, group=GRP_KZ)
ny_pre_color = input.color(color.new(#5b9bd5, 0), "New York PreMarket color", group=GRP_KZ)
// ============================================================
// INPUTS — ADR
// ============================================================
grp_calc = "ADR Calculation"
show_adr = input.bool(true, "Enable ADR Plotting", group=grp_calc)
adr_len = input.int(5, "ADR Period (Days)", minval=1, group=grp_calc)
grp_hist = "ADR History & Display"
history_mode = input.string("1 Semaine (5j)", "Display Range", options=["Jour actuel", "1 Semaine (5j)", "1 Mois (22j)"], group=grp_hist)
grp_adr_style = "ADR Styles & Colors"
c_adr_full = input.color(color.black, "ADR Full Line (+/- ADR)", group=grp_adr_style)
c_adr_third = input.color(#787b86, "1/3 ADR Dotted lline", group=grp_adr_style)
c_mid_open = input.color(#787b86, "Midnight Open Level", group=grp_adr_style)
c_v_00 = input.color(#747e99, "Vertical Line 00:00 (NY)", group=grp_adr_style)
c_v_17 = input.color(#2962ff, "Vertical Line 17:00 (NY)", group=grp_adr_style)
grp_lbl = "ADR Labels"
show_adr_labels = input.bool(true, "Show ADR Labels", group=grp_lbl)
grp_tbl = "ADR Audit Table"
show_adr_table = input.bool(true, "Show Audit Table", group=grp_tbl)
max_days_back = switch history_mode
"Jour actuel" => 1
"1 Semaine (5j)" => 5
"1 Mois (22j)" => 22
=> 5
// ============================================================
// FUNCTIONS & STYLES
// ============================================================
f_insession(_session) =>
not na(time(timeframe.period, _session, TIMEZONE))
f_timestrToHM(_timeStr) =>
var int hourInt = na
var int minuteInt = na
if str.length(_timeStr) == 4
hourInt := int(str.tonumber(str.substring(_timeStr, 0, 2)))
minuteInt := int(str.tonumber(str.substring(_timeStr, 2, 4)))
[hourInt, minuteInt]
f_sessionTime(_session, _timezone=syminfo.timezone, _part=0) =>
var int ts = na
if str.length(_session) == 9 and (_part == 0 or _part == 1)
arraySessionSplit = str.split(_session, '-')
timeStrTo = array.get(arraySessionSplit, _part)
[hourTo, minuteTo] = f_timestrToHM(timeStrTo)
ts := timestamp(_timezone, year, month, dayofmonth, hourTo, minuteTo)
ts
f_sessionStartTime(_session, _timezone=syminfo.timezone) => f_sessionTime(_session, _timezone, 0)
f_sessionStopTime(_session, _timezone=syminfo.timezone) => f_sessionTime(_session, _timezone, 1)
f_timestamp_to_date(int _ts=na, string _tz=na) => timestamp(_tz, year(_ts, _tz), month(_ts, _tz), dayofmonth(_ts, _tz))
f_lineStyle(_inputOption) =>
switch _inputOption
LS0 => line.style_solid
LS1 => line.style_dashed
LS2 => line.style_dotted
=> line.style_solid
exchangeOffsetMS = exchangeOffset * 3600000
f_newline(_color, _style) => line.new(na, na, na, na, xloc=xloc.bar_time, color=_color, style=_style, width=linesWidth)
f_newRHLline() => f_newline(RHLLineColor, f_lineStyle(RHLLineStyle))
f_newmdline() => f_newline(middleLineColor, f_lineStyle(middleLineStyle))
f_newbox() => box.new(na, na, na, na, xloc=xloc.bar_time, bgcolor=backgroundColor, border_width=boxBorderSize)
f_moveLine(_line, _x1, _y, _x2) =>
line.set_xy1(_line, _x1 + exchangeOffsetMS, _y)
line.set_xy2(_line, _x2 + exchangeOffsetMS, _y)
_line
f_movebox(_box, _left, _top, _right, _bottom, _bordercolor, _bgcolor) =>
box.set_lefttop(_box, _left + exchangeOffsetMS, _top)
box.set_rightbottom(_box, _right + exchangeOffsetMS, _bottom)
box.set_border_color(_box, _bordercolor)
box.set_bgcolor(_box, _bgcolor)
getBorderStyle(style) =>
switch style
"Solid" => line.style_solid
"Dotted" => line.style_dotted
"Dashed" => line.style_dashed
=> line.style_solid
getTextSize(size) =>
switch size
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
"Huge" => size.huge
=> size.small
f_trimBoxArray(array<box> arr) =>
while array.size(arr) > MAX_HISTORY_DAYS
box old = array.shift(arr)
if not na(old)
box.delete(old)
f_trimLineArray(array<line> arr) =>
while array.size(arr) > MAX_HISTORY_DAYS
line old = array.shift(arr)
if not na(old)
line.delete(old)
f_trimLabelArray(array<label> arr) =>
while array.size(arr) > MAX_HISTORY_DAYS
label old = array.shift(arr)
if not na(old)
label.delete(old)
atr = ta.atr(atrLength)
updateAutoBox(box existingBox, int startT, int endT, float sessHigh, float sessLow, color col, string title, bool placeAbove, float hATR) =>
offset = atr * offsetATR
height = atr * hATR
float top = na
float bottom = na
if placeAbove
top := sessHigh + offset + height
bottom := sessHigh + offset
else
top := sessLow - offset
bottom := sessLow - offset - height
box result = na
if na(existingBox)
result := box.new(left=startT, right=endT, top=top, bottom=bottom,
xloc=xloc.bar_time,
bgcolor=color.new(col, kzBoxesTransparency),
border_color=color.new(col, kzBorderTransparency),
border_width=kzBorderWidth,
border_style=getBorderStyle(kzBorderStyle),
text=title,
text_color=kzTextColor,
text_size=getTextSize(kzTextSize),
text_halign=text.align_center,
text_valign=text.align_center)
else
box.set_lefttop(existingBox, startT, top)
box.set_rightbottom(existingBox, endT, bottom)
box.set_bgcolor(existingBox, color.new(col, kzBoxesTransparency))
box.set_border_color(existingBox, color.new(col, kzBorderTransparency))
box.set_text(existingBox, title)
result := existingBox
result
// ============================================================
// DATA REQUESTS
// ============================================================
var bool use_m5 = false
if barstate.isfirst
use_m5 := timeframe.in_seconds() < 300
[m5_open, m5_high, m5_low, m5_close] = request.security(syminfo.tickerid, '5', [open, high, low, close], lookahead=barmerge.lookahead_on)
open_value = use_m5 ? m5_open : open
high_value = use_m5 ? m5_high : high
low_value = use_m5 ? m5_low : low
close_value = use_m5 ? m5_close : close
// ADR Data
daily_adr = request.security(syminfo.tickerid, "D", ta.sma(high - low, adr_len)[1], lookahead = barmerge.lookahead_on)
[d_r1, d_t1, d_r2, d_t2, d_r3, d_t3, d_r4, d_t4, d_r5, d_t5] = request.security(
syminfo.tickerid,
"D",
[
high[1] - low[1], time[1],
high[2] - low[2], time[2],
high[3] - low[3], time[3],
high[4] - low[4], time[4],
high[5] - low[5], time[5]
],
lookahead = barmerge.lookahead_on
)
// ============================================================
// LOGIC: ASIA & MIDNIGHT RANGE
// ============================================================
var int startTime = na
var int endTime = na
var string currentSession = na
var line lowAsial = na
var line highAsial = na
var line middleAsial = na
var box bgBox = na
var float Asialow = na
var float Asiahigh = na
var float Asiamiddle = na
var float sessionOpen = na
var float regAsialow = na
var float regAsiahigh = na
var float sessionHigh = na
var float sessionLow = na
var int AsiaLinesStartTime = na
var int AsiaLinesStopTime = na
// 5-Day Memory Asian High/Low Lines
var array<line> asiaHighLines = array.new_line()
var array<line> asiaLowLines = array.new_line()
var array<label> asiaHighLabels = array.new_label()
var array<label> asiaLowLabels = array.new_label()
var array<float> asiaHighLevels = array.new_float()
var array<float> asiaLowLevels = array.new_float()
var array<int> asiaStartTimes = array.new_int()
var array<int> asiaEndTimes = array.new_int()
var array<bool> asiaHighBrokens = array.new_bool()
var array<bool> asiaLowBrokens = array.new_bool()
var array<int> asiaHighBreakTs = array.new_int()
var array<int> asiaLowBreakTs = array.new_int()
var float lockedAsiaHigh = na
var float lockedAsiaLow = na
var int asiaSessionStartTime = na
var int asiaSessionEndTime = na
var bool asiaHighBroken = false
var bool asiaLowBroken = false
var int asiaHighBreakTime = na
var int asiaLowBreakTime = na
var line curAsiaHighLine = na
var line curAsiaLowLine = na
var label curAsiaHighLabel = na
var label curAsiaLowLabel = na
inAsiaSession = f_insession(AsiaTime) and showAsia
inAsiaExtend = f_insession(AsiaExtend) and showAsia
inMidnightSession = f_insession(MidnightTime) and showMidnight
inMidnightExtend = f_insession(MidnightExtend) and showMidnight
inSession = inAsiaSession or inMidnightSession
inExtend = inAsiaExtend or inMidnightExtend
enterSession = inSession and not inSession[1]
enterExtend = inExtend and not inExtend[1]
leaveRegularSession = not inAsiaSession and inAsiaSession[1]
enterRegularExtend = inAsiaExtend and not inAsiaExtend[1]
if timeframe.isintraday
if enterSession
currentSession := inAsiaSession ? AsiaTime : inMidnightSession ? MidnightTime : na
else if enterExtend
currentSession := inAsiaExtend ? AsiaExtend : inMidnightSession ? MidnightExtend : na
if inSession
if not inSession[1]
startTime := time
sessionOpen := open_value
Asiahigh := high_value
Asialow := low_value
Asialow := math.min(open_value, close_value)
Asiahigh := math.max(open_value, close_value)
if showBackground
bgBox := f_newbox()
if RHLlines
highAsial := f_newRHLline()
lowAsial := f_newRHLline()
if middleRHLline
middleAsial := f_newmdline()
Asiahigh := math.max(high_value, Asiahigh)
Asialow := math.min(low_value, Asialow)
Asiahigh := math.max(open_value, close_value, Asiahigh)
Asialow := math.min(open_value, close_value, Asialow)
Asiamiddle := math.avg(Asiahigh, Asialow)
if leaveRegularSession
regAsiahigh := Asiahigh
regAsialow := Asialow
if inAsiaExtend
AsiaLinesStartTime := f_sessionStartTime(AsiaExtend, TIMEZONE)
AsiaLinesStopTime := f_sessionStopTime(MidnightExtend, TIMEZONE) + ONE_DAY * (dayofweek == dayofweek.friday and syminfo.type != 'crypto' ? 3 : 1)
if enterRegularExtend
sessionHigh := high_value
sessionLow := low_value
sessionHigh := math.max(sessionHigh, high_value)
sessionLow := math.min(sessionLow, low_value)
if showBackground and inSession
boxHigh = Asiahigh
boxLow = Asialow
f_movebox(bgBox, startTime, boxHigh, time, boxLow, backgroundColor, backgroundColor)
if extendToEndOfRHL
if syminfo.type == 'warrant' or syminfo.type == 'structured' or syminfo.type == 'right'
endTime := time
else if time > (timenow - 2 * ONE_DAY)
if f_timestamp_to_date(f_sessionStopTime(currentSession, TIMEZONE), TIMEZONE) == f_timestamp_to_date(timenow, TIMEZONE)
endTime := f_sessionStopTime(AsiaExtend, TIMEZONE)
else
endTime := time
else
endTime := time
else
endTime := time
if RHLlines and (inSession or (extendRHLLines and inExtend))
f_moveLine(highAsial, startTime, Asiahigh, endTime)
f_moveLine(lowAsial, startTime, Asialow, endTime)
if middleRHLline
f_moveLine(middleAsial, startTime, Asiamiddle, endTime)
// Independent Asian High / Low
if showAsiaHLLines and timeframe.isintraday
if inAsiaSession and not inAsiaSession[1]
if not na(curAsiaHighLine)
array.push(asiaHighLines, curAsiaHighLine)
array.push(asiaLowLines, curAsiaLowLine)
array.push(asiaHighLabels, curAsiaHighLabel)
array.push(asiaLowLabels, curAsiaLowLabel)
array.push(asiaHighLevels, lockedAsiaHigh)
array.push(asiaLowLevels, lockedAsiaLow)
array.push(asiaStartTimes, asiaSessionStartTime)
array.push(asiaEndTimes, nz(asiaSessionEndTime, time))
array.push(asiaHighBrokens, asiaHighBroken)
array.push(asiaLowBrokens, asiaLowBroken)
array.push(asiaHighBreakTs, asiaHighBreakTime)
array.push(asiaLowBreakTs, asiaLowBreakTime)
f_trimLineArray(asiaHighLines)
f_trimLineArray(asiaLowLines)
f_trimLabelArray(asiaHighLabels)
f_trimLabelArray(asiaLowLabels)
while array.size(asiaHighLevels) > MAX_HISTORY_DAYS
array.shift(asiaHighLevels)
array.shift(asiaLowLevels)
array.shift(asiaStartTimes)
array.shift(asiaEndTimes)
array.shift(asiaHighBrokens)
array.shift(asiaLowBrokens)
array.shift(asiaHighBreakTs)
array.shift(asiaLowBreakTs)
asiaSessionStartTime := time
lockedAsiaHigh := high
lockedAsiaLow := low
asiaHighBroken := false
asiaLowBroken := false
asiaHighBreakTime := na
asiaLowBreakTime := na
asiaSessionEndTime := na
curAsiaHighLine := line.new(time, high, time, high, xloc=xloc.bar_time, color=asiaHLLineColor, style=f_lineStyle(asiaHLLineStyle), width=linesWidth)
curAsiaLowLine := line.new(time, low, time, low, xloc=xloc.bar_time, color=asiaHLLineColor, style=f_lineStyle(asiaHLLineStyle), width=linesWidth)
if showAsiaLabels
float labelOffsetHigh = atr * 0.25
float labelOffsetLow = atr * 0.50
int labelX = bar_index >= 15 ? time[15] : time
curAsiaHighLabel := label.new(labelX, high + labelOffsetHigh, "Asian High", xloc=xloc.bar_time, yloc=yloc.price,
style=label.style_none, textcolor=labelTextColor, size=getTextSize(labelTextSize), textalign=text.align_center)
curAsiaLowLabel := label.new(labelX, low - labelOffsetLow, "Asian Low", xloc=xloc.bar_time, yloc=yloc.price,
style=label.style_none, textcolor=labelTextColor, size=getTextSize(labelTextSize), textalign=text.align_center)
if inAsiaSession and not na(asiaSessionStartTime)
lockedAsiaHigh := math.max(nz(lockedAsiaHigh, high), high)
lockedAsiaLow := math.min(nz(lockedAsiaLow, low), low)
if not na(curAsiaHighLine)
line.set_xy1(curAsiaHighLine, asiaSessionStartTime, lockedAsiaHigh)
line.set_xy2(curAsiaHighLine, time, lockedAsiaHigh)
if not na(curAsiaLowLine)
line.set_xy1(curAsiaLowLine, asiaSessionStartTime, lockedAsiaLow)
line.set_xy2(curAsiaLowLine, time, lockedAsiaLow)
if showAsiaLabels
float labelOffsetHigh = atr * 0.25
float labelOffsetLow = atr * 0.50
int labelX = bar_index >= 15 ? time[15] : time
if not na(curAsiaHighLabel)
label.set_xy(curAsiaHighLabel, labelX, lockedAsiaHigh + labelOffsetHigh)
if not na(curAsiaLowLabel)
label.set_xy(curAsiaLowLabel, labelX, lockedAsiaLow - labelOffsetLow)
if leaveRegularSession and not na(asiaSessionStartTime)
asiaSessionEndTime := time
if not na(lockedAsiaHigh) and not na(asiaSessionEndTime) and not inAsiaSession
int maxEndTime = timestamp(TIMEZONE, year, month, dayofmonth, asiaLineEndHour, 0)
if not asiaHighBroken and high > lockedAsiaHigh
asiaHighBroken := true
asiaHighBreakTime := time
if not asiaLowBroken and low < lockedAsiaLow
asiaLowBroken := true
asiaLowBreakTime := time
int highEnd = asiaHighBroken and not na(asiaHighBreakTime) ? asiaHighBreakTime : math.min(time, maxEndTime)
int lowEnd = asiaLowBroken and not na(asiaLowBreakTime) ? asiaLowBreakTime : math.min(time, maxEndTime)
if time > maxEndTime and not asiaHighBroken
highEnd := maxEndTime
if time > maxEndTime and not asiaLowBroken
lowEnd := maxEndTime
if not na(curAsiaHighLine)
line.set_xy1(curAsiaHighLine, asiaSessionStartTime, lockedAsiaHigh)
line.set_xy2(curAsiaHighLine, highEnd, lockedAsiaHigh)
if not na(curAsiaLowLine)
line.set_xy1(curAsiaLowLine, asiaSessionStartTime, lockedAsiaLow)
line.set_xy2(curAsiaLowLine, lowEnd, lockedAsiaLow)
if showAsiaLabels
float labelOffsetHigh = atr * 0.25
float labelOffsetLow = atr * 0.50
int barDurationMs = timeframe.in_seconds() * 1000
int labelXHigh = math.max(highEnd - 15 * barDurationMs, asiaSessionStartTime)
int labelXLow = math.max(lowEnd - 15 * barDurationMs, asiaSessionStartTime)
if not na(curAsiaHighLabel)
label.set_xy(curAsiaHighLabel, labelXHigh, lockedAsiaHigh + labelOffsetHigh)
label.set_text(curAsiaHighLabel, "Asian High")
if not na(curAsiaLowLabel)
label.set_xy(curAsiaLowLabel, labelXLow, lockedAsiaLow - labelOffsetLow)
label.set_text(curAsiaLowLabel, "Asian Low")
// ============================================================
// LOGIC: ICT KILLZONES + PREMARKET
// ============================================================
var array<box> londonBoxes = array.new_box()
var array<box> nyBoxes = array.new_box()
var array<box> londonPreBoxes = array.new_box()
var array<box> nyPreBoxes = array.new_box()
var float londonHigh = na
var float londonLow = na
var int londonStartTime = na
var box londonBox = na
var bool inLondonSession = false
var float nyHigh = na
var float nyLow = na
var int nyStartTime = na
var box nyBox = na
var bool inNySession = false
var float londonPreHigh = na
var float londonPreLow = na
var int londonPreStartTime = na
var box londonPreBox = na
var bool inLondonPre = false
var float nyPreHigh = na
var float nyPreLow = na
var int nyPreStartTime = na
var box nyPreBox = na
var bool inNyPre = false
if showKillzones
// London Kill Zone
bool londonStartCond = hour(time, TIMEZONE) == london_start and minute(time, TIMEZONE) == 0
bool londonEndCond = hour(time, TIMEZONE) == london_end and minute(time, TIMEZONE) == 0
if londonStartCond
if not na(londonBox) and not inLondonSession
array.push(londonBoxes, londonBox)
f_trimBoxArray(londonBoxes)
londonHigh := high
londonLow := low
londonStartTime := time
inLondonSession := true
londonBox := updateAutoBox(box(na), londonStartTime, time, londonHigh, londonLow, london_color, london_name, london_above, heightATR)
if inLondonSession and not na(londonStartTime)
londonHigh := math.max(nz(londonHigh, high), high)
londonLow := math.min(nz(londonLow, low), low)
londonBox := updateAutoBox(londonBox, londonStartTime, time, londonHigh, londonLow, london_color, london_name, london_above, heightATR)
if londonEndCond and inLondonSession
londonBox := updateAutoBox(londonBox, londonStartTime, time, londonHigh, londonLow, london_color, london_name, london_above, heightATR)
inLondonSession := false
array.push(londonBoxes, londonBox)
f_trimBoxArray(londonBoxes)
londonBox := na
// NY Kill Zone
bool nyStartCond = hour(time, TIMEZONE) == ny_start and minute(time, TIMEZONE) == 0
bool nyEndCond = hour(time, TIMEZONE) == ny_end and minute(time, TIMEZONE) == 0
if nyStartCond
if not na(nyBox) and not inNySession
array.push(nyBoxes, nyBox)
f_trimBoxArray(nyBoxes)
nyHigh := high
nyLow := low
nyStartTime := time
inNySession := true
nyBox := updateAutoBox(box(na), nyStartTime, time, nyHigh, nyLow, ny_color, ny_name, ny_above, heightATR)
if inNySession and not na(nyStartTime)
nyHigh := math.max(nz(nyHigh, high), high)
nyLow := math.min(nz(nyLow, low), low)
nyBox := updateAutoBox(nyBox, nyStartTime, time, nyHigh, nyLow, ny_color, ny_name, ny_above, heightATR)
if nyEndCond and inNySession
nyBox := updateAutoBox(nyBox, nyStartTime, time, nyHigh, nyLow, ny_color, ny_name, ny_above, heightATR)
inNySession := false
array.push(nyBoxes, nyBox)
f_trimBoxArray(nyBoxes)
nyBox := na
if showPremarket
// London PreMarket
bool londonPreStartCond = hour(time, TIMEZONE) == london_pre_start and minute(time, TIMEZONE) == 0
bool londonPreEndCond = hour(time, TIMEZONE) == london_pre_end and minute(time, TIMEZONE) == 0
if londonPreStartCond
if not na(londonPreBox) and not inLondonPre
array.push(londonPreBoxes, londonPreBox)
f_trimBoxArray(londonPreBoxes)
londonPreHigh := high
londonPreLow := low
londonPreStartTime := time
inLondonPre := true
londonPreBox := updateAutoBox(box(na), londonPreStartTime, time, londonPreHigh, londonPreLow, london_pre_color, london_pre_name, not london_above, preHeightATR)
if inLondonPre and not na(londonPreStartTime)
londonPreHigh := math.max(nz(londonPreHigh, high), high)
londonPreLow := math.min(nz(londonPreLow, low), low)
londonPreBox := updateAutoBox(londonPreBox, londonPreStartTime, time, londonPreHigh, londonPreLow, london_pre_color, london_pre_name, not london_above, preHeightATR)
if londonPreEndCond and inLondonPre
londonPreBox := updateAutoBox(londonPreBox, londonPreStartTime, time, londonPreHigh, londonPreLow, london_pre_color, london_pre_name, not london_above, preHeightATR)
inLondonPre := false
array.push(londonPreBoxes, londonPreBox)
f_trimBoxArray(londonPreBoxes)
londonPreBox := na
// NY PreMarket
bool nyPreStartCond = hour(time, TIMEZONE) == ny_pre_start_h and minute(time, TIMEZONE) == ny_pre_start_m
bool nyPreEndCond = hour(time, TIMEZONE) == ny_pre_end_h and minute(time, TIMEZONE) == ny_pre_end_m
if nyPreStartCond
if not na(nyPreBox) and not inNyPre
array.push(nyPreBoxes, nyPreBox)
f_trimBoxArray(nyPreBoxes)
nyPreHigh := high
nyPreLow := low
nyPreStartTime := time
inNyPre := true
nyPreBox := updateAutoBox(box(na), nyPreStartTime, time, nyPreHigh, nyPreLow, ny_pre_color, ny_pre_name, not ny_above, preHeightATR)
if inNyPre and not na(nyPreStartTime)
nyPreHigh := math.max(nz(nyPreHigh, high), high)
nyPreLow := math.min(nz(nyPreLow, low), low)
nyPreBox := updateAutoBox(nyPreBox, nyPreStartTime, time, nyPreHigh, nyPreLow, ny_pre_color, ny_pre_name, not ny_above, preHeightATR)
if nyPreEndCond and inNyPre
nyPreBox := updateAutoBox(nyPreBox, nyPreStartTime, time, nyPreHigh, nyPreLow, ny_pre_color, ny_pre_name, not ny_above, preHeightATR)
inNyPre := false
array.push(nyPreBoxes, nyPreBox)
f_trimBoxArray(nyPreBoxes)
nyPreBox := na
// ============================================================
// LOGIC: ADR BY DEWEINN
// ============================================================
ny_d = dayofweek(time, TIMEZONE)
ny_h = hour(time, TIMEZONE)
is_new_day = (dayofmonth(time, TIMEZONE) != dayofmonth(time[1], TIMEZONE)) and (ny_d >= 2 and ny_d <= 6)
is_1700 = (ny_h == 17 and hour(time[1], TIMEZONE) != 17) and (ny_d >= 2 and ny_d <= 6)
in_adr_session = (ny_d >= 2 and ny_d <= 6) and (ny_h >= 0 and ny_h < 17)
var float midnight_open = na
var int adr_start_time= na
var float adr_stored = na
var float adr_third = na
var line l_plus_adr = na
var line l_plus_third = na
var line l_open = na
var line l_min_third = na
var line l_min_adr = na
var label lb_plus_adr = na
var label lb_plus_third = na
var label lb_open = na
var label lb_min_third = na
var label lb_min_adr = na
var line[] adr_lines = array.new_line()
var label[] adr_labels = array.new_label()
if show_adr and timeframe.isintraday
if is_new_day
midnight_open := open
adr_start_time := time
adr_stored := daily_adr
adr_third := daily_adr / 3.0
line v00 = line.new(
x1 = time, y1 = low, x2 = time, y2 = high,
xloc = xloc.bar_time, extend = extend.both,
color = c_v_00, style = line.style_dotted, width = 1
)
array.push(adr_lines, v00)
p_plus_adr = midnight_open + adr_stored
p_plus_third = midnight_open + adr_third
p_min_third = midnight_open - adr_third
p_min_adr = midnight_open - adr_stored
l_plus_adr := line.new(adr_start_time, p_plus_adr, time, p_plus_adr, xloc = xloc.bar_time, color = c_adr_full, width = 1, style = line.style_solid)
l_plus_third := line.new(adr_start_time, p_plus_third, time, p_plus_third, xloc = xloc.bar_time, color = c_adr_third, width = 1, style = line.style_dotted)
l_open := line.new(adr_start_time, midnight_open, time, midnight_open, xloc = xloc.bar_time, color = c_mid_open, width = 1, style = line.style_dotted)
l_min_third := line.new(adr_start_time, p_min_third, time, p_min_third, xloc = xloc.bar_time, color = c_adr_third, width = 1, style = line.style_dotted)
l_min_adr := line.new(adr_start_time, p_min_adr, time, p_min_adr, xloc = xloc.bar_time, color = c_adr_full, width = 1, style = line.style_solid)
array.push(adr_lines, l_plus_adr)
array.push(adr_lines, l_plus_third)
array.push(adr_lines, l_open)
array.push(adr_lines, l_min_third)
array.push(adr_lines, l_min_adr)
if show_adr_labels
lb_plus_adr := label.new(time, p_plus_adr, "ADR+", xloc = xloc.bar_time, style = label.style_none, textcolor = c_adr_full, size = size.small)
lb_plus_third := label.new(time, p_plus_third, "1/3ADR+", xloc = xloc.bar_time, style = label.style_none, textcolor = c_adr_third, size = size.small)
lb_open := label.new(time, midnight_open, "Midnight Open", xloc = xloc.bar_time, style = label.style_none, textcolor = c_mid_open, size = size.small)
lb_min_third := label.new(time, p_min_third, "1/3ADR-", xloc = xloc.bar_time, style = label.style_none, textcolor = c_adr_third, size = size.small)
lb_min_adr := label.new(time, p_min_adr, "ADR-", xloc = xloc.bar_time, style = label.style_none, textcolor = c_adr_full, size = size.small)
array.push(adr_labels, lb_plus_adr)
array.push(adr_labels, lb_plus_third)
array.push(adr_labels, lb_open)
array.push(adr_labels, lb_min_third)
array.push(adr_labels, lb_min_adr)
max_adr_elements = max_days_back * 7
while array.size(adr_lines) > max_adr_elements
line.delete(array.shift(adr_lines))
while array.size(adr_labels) > (max_days_back * 5)
label.delete(array.shift(adr_labels))
if in_adr_session and not na(l_plus_adr)
line.set_x2(l_plus_adr, time)
line.set_x2(l_plus_third, time)
line.set_x2(l_open, time)
line.set_x2(l_min_third, time)
line.set_x2(l_min_adr, time)
if show_adr_labels and not na(lb_plus_adr)
label.set_x(lb_plus_adr, time)
label.set_x(lb_plus_third, time)
label.set_x(lb_open, time)
label.set_x(lb_min_third, time)
label.set_x(lb_min_adr, time)
if is_1700
line v17 = line.new(
x1 = time, y1 = low, x2 = time, y2 = high,
xloc = xloc.bar_time, extend = extend.both,
color = c_v_17, style = line.style_solid, width = 1
)
array.push(adr_lines, v17)
if not na(l_plus_adr)
line.set_x2(l_plus_adr, time)
line.set_x2(l_plus_third, time)
line.set_x2(l_open, time)
line.set_x2(l_min_third, time)
line.set_x2(l_min_adr, time)
if show_adr_labels and not na(lb_plus_adr)
label.set_x(lb_plus_adr, time)
label.set_x(lb_plus_third, time)
label.set_x(lb_open, time)
label.set_x(lb_min_third, time)
label.set_x(lb_min_adr, time)
// ============================================================
// ADR AUDIT TABLE
// ============================================================
var table audit_tbl = table.new(position.top_right, 3, 8, bgcolor = color.new(#1e222d, 10), border_color = #363c4e, border_width = 1)
pip_factor = syminfo.type == "forex" ? (syminfo.mintick * 10) : syminfo.mintick
f_format_row(int row_idx, int t, float r) =>
str_date = str.format_time(t, "yyyy-MM-dd (E)", TIMEZONE)
str_val = str.tostring(r / pip_factor, "#.##")
table.cell(audit_tbl, 0, row_idx, "J-" + str.tostring(row_idx), text_color = color.gray, text_size = size.small)
table.cell(audit_tbl, 1, row_idx, str_date, text_color = color.white, text_size = size.small)
table.cell(audit_tbl, 2, row_idx, str_val, text_color = color.yellow, text_size = size.small)
if barstate.islast and show_adr and show_adr_table
unit_label = syminfo.type == "forex" ? "Pips" : "Pts"
table.cell(audit_tbl, 0, 0, "Rang", bgcolor = #2a2e39, text_color = color.white, text_size = size.small)
table.cell(audit_tbl, 1, 0, "Séance (NY)", bgcolor = #2a2e39, text_color = color.white, text_size = size.small)
table.cell(audit_tbl, 2, 0, "Range (" + unit_label + ")", bgcolor = #2a2e39, text_color = color.white, text_size = size.small)
f_format_row(1, d_t1, d_r1)
f_format_row(2, d_t2, d_r2)
f_format_row(3, d_t3, d_r3)
f_format_row(4, d_t4, d_r4)
f_format_row(5, d_t5, d_r5)
adr_pip_str = str.tostring(daily_adr / pip_factor, "#.##")
third_pip_str = str.tostring((daily_adr / 3.0) / pip_factor, "#.##")
table.cell(audit_tbl, 0, 6, "ADR " + str.tostring(adr_len) + "J", bgcolor = #2a2e39, text_color = color.white, text_size = size.small)
table.cell(audit_tbl, 1, 6, "Moyenne", bgcolor = #2a2e39, text_color = color.white, text_size = size.small)
table.cell(audit_tbl, 2, 6, adr_pip_str + " " + unit_label, bgcolor = #2a2e39, text_color = color.green, text_size = size.small)
table.cell(audit_tbl, 0, 7, "1/3 ADR", bgcolor = #2a2e39, text_color = color.gray, text_size = size.small)
table.cell(audit_tbl, 1, 7, "Niveau tiers", bgcolor = #2a2e39, text_color = color.gray, text_size = size.small)
table.cell(audit_tbl, 2, 7, third_pip_str + " " + unit_label, bgcolor = #2a2e39, text_color = color.orange, text_size = size.small)