π
BTCUSDT Β· 30m Β· 31 Oct 202631 Oct
Session RangesOpen in chart
View code
Session Ranges
indicator("Session Ranges", overlay = true, max_boxes_count = 300, max_labels_count = 300)
import MarkudaDev/CryptoCalendar/1 as cal
showAsia = input.bool(true, "Asia session")
showEurope = input.bool(true, "Europe session")
showUS = input.bool(true, "US session")
showOpens = input.bool(true, "Weekly and monthly opens")
showFunding = input.bool(true, "Funding times")
fundingHours = input.int(8, "Funding interval (hours)", options = [1, 4, 8])
ASIA = "#6d7cff"
EUROPE = "#e3b341"
US = "#c084fc"
intraday = timeframe.isintraday
rangeText(string name, float hi, float lo) => name + " " + formatNumber((hi - lo) / lo * 100, 2) + "%"
asiaStart = cal.sessionStarted(cal.Session.Asia)
asiaIn = cal.inSessionOf(cal.Session.Asia)
asiaEnd = cal.sessionEnded(cal.Session.Asia)
asiaHi = cal.sessionHigh(cal.Session.Asia)
asiaLo = cal.sessionLow(cal.Session.Asia)
var asiaBox = na
if showAsia and intraday {
if asiaStart {
asiaBox := boxNew(barIndex, asiaHi, barIndex, asiaLo, ASIA, bgcolor = ASIA + "1f", border_width = 1)
} else if asiaIn and not na(asiaBox) {
boxSetRight(asiaBox, barIndex)
boxSetTop(asiaBox, asiaHi)
boxSetBottom(asiaBox, asiaLo)
}
if asiaEnd and not na(asiaBox) {
labelNew(asiaHi, rangeText("Asia", asiaHi, asiaLo), boxGetLeft(asiaBox), ASIA, style = "label_down", size = "small")
}
}
euStart = cal.sessionStarted(cal.Session.Europe)
euIn = cal.inSessionOf(cal.Session.Europe)
euEnd = cal.sessionEnded(cal.Session.Europe)
euHi = cal.sessionHigh(cal.Session.Europe)
euLo = cal.sessionLow(cal.Session.Europe)
var euBox = na
if showEurope and intraday {
if euStart {
euBox := boxNew(barIndex, euHi, barIndex, euLo, EUROPE, bgcolor = EUROPE + "1f", border_width = 1)
} else if euIn and not na(euBox) {
boxSetRight(euBox, barIndex)
boxSetTop(euBox, euHi)
boxSetBottom(euBox, euLo)
}
if euEnd and not na(euBox) {
labelNew(euHi, rangeText("Europe", euHi, euLo), boxGetLeft(euBox), EUROPE, style = "label_down", size = "small")
}
}
usStart = cal.sessionStarted(cal.Session.US)
usIn = cal.inSessionOf(cal.Session.US)
usEnd = cal.sessionEnded(cal.Session.US)
usHi = cal.sessionHigh(cal.Session.US)
usLo = cal.sessionLow(cal.Session.US)
var usBox = na
if showUS and intraday {
if usStart {
usBox := boxNew(barIndex, usHi, barIndex, usLo, US, bgcolor = US + "1f", border_width = 1)
} else if usIn and not na(usBox) {
boxSetRight(usBox, barIndex)
boxSetTop(usBox, usHi)
boxSetBottom(usBox, usLo)
}
if usEnd and not na(usBox) {
labelNew(usHi, rangeText("US", usHi, usLo), boxGetLeft(usBox), US, style = "label_down", size = "small")
}
}
plot(showOpens ? cal.weeklyOpen() : na, "Weekly open", "#818692", style = "stepline", linestyle = "dashed")
plot(showOpens ? cal.monthlyOpen() : na, "Monthly open", "#33d69f", style = "stepline", linestyle = "dashed")
plotshape(showFunding and intraday and cal.isFundingBar(fundingHours), "Funding", style = "circle", location = "bottom", color = "#fb5b6b", size = "tiny")
minutesLeft = cal.minutesToFunding(fundingHours)
now = cal.activeSessions()
if barstate.islast and intraday {
labelNew(high, (now == "" ? "Between sessions" : now) + " Β· next funding in " + str(floor(minutesLeft / 60)) + "h " + str(minutesLeft % 60) + "m", barIndex, "#818692", style = "label_left", size = "small")
}


