Worldclassedge [Patrick nill]

anchor = input.string("Session", title="Anchor Period")
MILLIS_IN_DAY = 86400000
dwmBarTime = timeframe.isdwm ? time : request.security(syminfo.tickerid, "D", time)
dwmBarTime := na(dwmBarTime) ? nz(dwmBarTime[1]) : dwmBarTime
var periodStart = time - time
makeMondayZero(dayOfWeek) => (dayOfWeek + 5) % 7
isMidnight(t) => hour(t) == 0 and minute(t) == 0
isSameDay(t1, t2) => dayofmonth(t1) == dayofmonth(t2) and month(t1) == month(t2) and year(t1) == year(t2)
isOvernight() => not (isMidnight(dwmBarTime) or request.security(syminfo.tickerid, "D", isSameDay(time, time_close), lookahead=barmerge.lookahead_on))
tradingDayStart(t) => timestamp(year(t), month(t), dayofmonth(t), 0, 0)
numDaysBetween(t1, t2) =>
diff = math.abs(tradingDayStart(t1) - tradingDayStart(t2))
diff / MILLIS_IN_DAY
tradingDay = isOvernight() ? tradingDayStart(dwmBarTime + MILLIS_IN_DAY) : tradingDayStart(dwmBarTime)
isNewPeriod() =>
var isNew = false
if tradingDay != nz(tradingDay[1])
isNew := switch anchor
"Session" => na(tradingDay[1]) or tradingDay > tradingDay[1]
"Week" => makeMondayZero(dayofweek(periodStart)) + numDaysBetween(periodStart, tradingDay) >= 7
"Month" => month(periodStart) != month(tradingDay) or year(periodStart) != year(tradingDay)
"Year" => year(periodStart) != year(tradingDay)
=> false
isNew
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact AI-user directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.
Author's instructions
Disclaimer
Invite-only script
Only users approved by the author can access this script. You'll need to request and get permission to use it. This is typically granted after payment. For more details, follow the author's instructions below or contact AI-user directly.
TradingView does NOT recommend paying for or using a script unless you fully trust its author and understand how it works. You may also find free, open-source alternatives in our community scripts.