OPEN-SOURCE SCRIPT

Time

185
//version=5
indicator('Time', overlay=true, max_bars_back=1000, max_labels_count=500, max_lines_count=500, max_boxes_count=500)

// Asia
var GRP1 = "Asian Session"

extendLines = true
rangeTime = '1705-0101'
boxLineColor = input(color.new(color.rgb(212, 129, 4), int(80)), 'Line color', group=GRP1)
backgroundColor = input(color.new(color.rgb(221, 133, 0), int(90)), "Background color", group=GRP1)

// A session
inSession1 = not na(time(timeframe.period, rangeTime))
inExtend = not na(time(timeframe.period, "0100-0801"))
startTime = 0
startTime := inSession1 and not inSession1[1] ? time : startTime[1]

var line lowHLine = na
var line topHLine = na
var line leftVLine = na
var line rightVLine = na
var line middleHLine = na
var box bgBox = na

var low_val = float(0.0)
var high_val = 0.0
if inSession1 and not inSession1[1]
low_val := low
high_val := high
high_val

if inSession1 and timeframe.isintraday
if inSession1[1]
line.delete(lowHLine)
line.delete(topHLine)
line.delete(middleHLine)
box.delete(bgBox)

if low < low_val
low_val := low
low_val
if high > high_val
high_val := high
high_val

if true and timeframe.multiplier <= 60
bgBox := box.new(startTime, high_val, time, low_val, xloc=xloc.bar_time, bgcolor=backgroundColor, border_width=0)

if true and timeframe.multiplier <= 60
lowHLine := line.new(startTime, low_val, time, low_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)
topHLine := line.new(startTime, high_val, time, high_val, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)

if true and timeframe.multiplier <= 60
middleHLine := line.new(startTime, (high_val + low_val) / 2, time, (high_val + low_val) / 2, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)

else
if inExtend and extendLines and not inSession1 and timeframe.isintraday
time1 = line.get_x1(lowHLine)
time2 = line.get_x2(lowHLine)
price = line.get_y1(lowHLine)
line.delete(lowHLine)
lowHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)

time1 := line.get_x1(topHLine)
time2 := line.get_x2(topHLine)
price := line.get_y1(topHLine)
line.delete(topHLine)
topHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)

time1 := line.get_x1(middleHLine)
time2 := line.get_x2(middleHLine)
price := line.get_y1(middleHLine)
line.delete(middleHLine)
middleHLine := line.new(time1, price, time, price, xloc=xloc.bar_time, color=boxLineColor, style=line.style_solid, width=1)
middleHLine

// LDN & NY
remove(str, pos, length) =>
arr = str.split(str, "")
len = array.size(arr)

pos1 = pos >= 0 ? pos : len + pos
length_ = length >= 0 ? length : len - pos1
pos2 = pos1 + length_

if len > 0 and length_ > 0 and pos1 >= 0 and pos2 <= len
for i = 0 to length_ - 1
array.remove(arr, pos1)
res = array.join(arr, "")

CalcOffs(timeStr) =>
hourStartStr = remove(timeStr, 2, 7)
hourStart = str.tonumber(hourStartStr)

minStartTemp = remove(timeStr, 0, 2)
minStartStr = remove(minStartTemp, 2, 5)
minStart = str.tonumber(minStartStr)

timeEndStr = remove(timeStr, 0, 5)
hourEndStr = remove(timeEndStr, 2, 2)
hourEnd = str.tonumber(hourEndStr)
minEndStr = remove(timeEndStr, 0, 2)
minEnd = str.tonumber(minEndStr)

time_diff_minutes = str.tostring(math.abs((hourEnd * 60 + minEnd) - (hourStart * 60 + minStart)))

// Settings
isLondon = true
loSessionTime = input.session("0300-0400", title="Session", group = "London Session")
loBoxColor = input.color(color.new(#2962ff, 80), title="Background color", group = "London Session")

isNewYorkTrap = true
nytrapSessionTime = input.session("0900-1000", title="Session", group ="New York Trap Session")
nytrapBoxColor = input.color(color.new(#2962ff, 80), title="Background color", group = "New York Trap Session")

loOffs = math.round(str.tonumber(CalcOffs(loSessionTime)))
nytrapOffs = math.round(str.tonumber(CalcOffs(nytrapSessionTime)))
dayOffs = 1440

if timeframe.period == "S"
loOffs := loOffs * 60
nytrapOffs := nytrapOffs * 60
dayOffs := dayOffs * 60

if timeframe.period == "5S"
loOffs := loOffs * 60 / 5
nytrapOffs := nytrapOffs * 60/5
dayOffs := dayOffs * 60 / 5

if timeframe.period == "15S"
loOffs := loOffs * 60 / 15
nytrapOffs := nytrapOffs *60 / 15
dayOffs := dayOffs * 60 / 15

if timeframe.period == "30S"
loOffs := loOffs * 60 / 30
nytrapOffs := nytrapOffs *60 / 30
dayOffs := dayOffs * 60 / 30

if timeframe.period == "3"
loOffs := loOffs / 3
nytrapOffs := nytrapOffs /3
dayOffs := dayOffs / 3

if timeframe.period == "5"
loOffs := loOffs / 5
nytrapOffs := nytrapOffs / 5
dayOffs := dayOffs / 5

if timeframe.period == "15"
loOffs := loOffs / 15
nytrapOffs := nytrapOffs / 15
dayOffs := dayOffs / 15

if timeframe.period == "30"
loOffs := loOffs / 30
nytrapOffs := nytrapOffs / 30
dayOffs := dayOffs / 30

if timeframe.period == "45"
loOffs := loOffs / 45
nytrapOffs := nytrapOffs / 45
dayOffs := dayOffs / 45

if timeframe.period == "60"
loOffs := loOffs / 60
nytrapOffs := nytrapOffs / 60
dayOffs := dayOffs / 60

if timeframe.period == "120"
loOffs := loOffs / 120
nytrapOffs := nytrapOffs / 120
dayOffs := dayOffs / 120

if timeframe.period == "180"
loOffs := loOffs / 180
nytrapOffs := nytrapOffs / 180
dayOffs := dayOffs / 180

if timeframe.period == "240"
loOffs := loOffs / 240
nytrapOffs := nytrapOffs / 240
dayOffs := dayOffs / 240

if true and timeframe.multiplier <= 60

if isLondon
var sessionHighPrice = 0.0
var sessionLowPrice = 0.0
var sessionOpenPrice = 0.0
var box sessionBox = na
var line sessionTopLine = na
var line sessionLowLine = na

inSession = not na(time(timeframe.period, loSessionTime)) and timeframe.isintraday
sessionStart = inSession and not inSession[1]

if sessionStart
sessionHighPrice := high
sessionLowPrice := low
sessionOpenPrice := open
else if inSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionLowPrice := math.min(sessionLowPrice, low)
if sessionStart
sessionBox := box.new(left=bar_index, top=na, right=bar_index+loOffs, bottom=na, border_color = color.new(#ffffff, 100), bgcolor=loBoxColor)
sessionTopLine := line.new(x1=bar_index, y1=na, x2=bar_index+loOffs, y2=na, style=line.style_solid, width=0)
sessionLowLine := line.new(x1=bar_index, y1=na, x2=bar_index+loOffs, y2=na, style=line.style_solid, width=0)
if inSession
box.set_top(sessionBox, sessionHighPrice)
box.set_bottom(sessionBox, sessionLowPrice)

if isNewYorkTrap
var sessionHighPrice = 0.0
var sessionLowPrice = 0.0
var sessionOpenPrice = 0.0
var box sessionBox = na
var line sessionTopLine = na
var line sessionLowLine = na
inSession = not na(time(timeframe.period, nytrapSessionTime)) and timeframe.isintraday
sessionStart = inSession and not inSession[1]

if sessionStart
sessionHighPrice := high
sessionLowPrice := low
sessionOpenPrice := open
else if inSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionLowPrice := math.min(sessionLowPrice, low)
if sessionStart
sessionBox := box.new(left=bar_index, top=na, right=bar_index+nytrapOffs, bottom=na, border_color = color.new(#ffffff, 100), bgcolor=nytrapBoxColor)
sessionTopLine := line.new(x1= bar_index, y1=na, x2=bar_index+nytrapOffs, y2=na, style=line.style_solid, width=0)
sessionLowLine := line.new(x1= bar_index, y1=na, x2=bar_index+nytrapOffs, y2=na, style=line.style_solid, width=0)
if inSession
box.set_top(sessionBox, sessionHighPrice)
box.set_bottom(sessionBox, sessionLowPrice)

box.set_top(sessionBox, sessionHighPrice)
box.set_bottom(sessionBox, sessionLowPrice)

var GRPFF = 'Frankfurt Session'
ffsession = '0200-0201'
ffcolor = input.color(color.new(#787b86, 70), title='Line color', group=GRPFF)

var GRPMMM1 = 'Magic Manipulation Minute 1'
mmm1time = '0430-0431'
mmm1color = input.color(color.new(#787b86, 70), title="Line color",group=GRPMMM1)

var GRPMMM2 = 'Magic Manipulation Minute 2'
mmm2time = '0630-0631'
mmm2color = input.color(color.new(#787b86, 70), title="Line color", group=GRPMMM2)

var GRPNYO = 'New York Open'
nyosession = '0800-0801'
nyocolor = input.color(color.new(#787b86, 70),title="Line color", group=GRPNYO)

var GRPLC = 'London Close'
lcsession = '1100-1101'
lccolor = input.color(color.new(#787b86, 0),title="Line color", group=GRPLC)

asiansize = (high_val-low_val)/4

in_session_ff = time(timeframe.period, ffsession)
sessionffActive = in_session_ff and timeframe.multiplier <= 15
var line ff = na
if sessionffActive and sessionffActive[1] == false
ff := line.new(bar_index, high+asiansize, bar_index, low-asiansize, color=ffcolor, style=line.style_solid)

in_session_mmm1 = time(timeframe.period, mmm1time)
sessionmmm1Active = in_session_mmm1 and timeframe.multiplier <= 15
var line mmm1 = na
if sessionmmm1Active and sessionmmm1Active[1] == false
mmm1 := line.new(bar_index, high+asiansize, bar_index, low-asiansize, color=mmm1color, style=line.style_solid)

in_session_mmm2 = time(timeframe.period, mmm2time)
sessionmmm2Active = in_session_mmm2 and timeframe.multiplier <= 15
var line mmm2 = na
if sessionmmm2Active and sessionmmm2Active[1] == false
mmm2 := line.new(bar_index, high+asiansize, bar_index, low-asiansize, color=mmm2color, style=line.style_solid)

in_session_nyo = time(timeframe.period, nyosession)
sessionnyoActive = in_session_nyo and timeframe.multiplier <= 15
var line nyo = na
if sessionnyoActive and sessionnyoActive[1] == false
nyo := line.new(bar_index, high+asiansize, bar_index, low-asiansize, color=nyocolor, style=line.style_solid)

in_session_lc = time(timeframe.period, lcsession)
sessionlcActive = in_session_lc and timeframe.multiplier <= 15
var line lc = na
if sessionlcActive and sessionlcActive[1] == false
lc := line.new(bar_index, high+asiansize, bar_index, low-asiansize, color=lccolor, style=line.style_solid)

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.