Daily range
EBTURK
plain_text
a year ago
2.5 kB
17
Indexable
//@version=5
// © EBTURK
strategy("daily range", overlay=true)
// input
session = input.session("0000-0000", title="Trading Session")
timeZone = input.string("UTC", title="Time Zone")
monSession = input.bool(true, title="Mon ", group="Trading Session", inline="d1")
tuesSession = input.bool(true, title="Tue ", group="Trading Session", inline="d1")
wedSession = input.bool(true, title="Wed ", group="Trading Session", inline="d1")
thuSession = input.bool(true, title="Thu ", group="Trading Session", inline="d1")
friSession = input.bool(true, title="Fri ", group="Trading Session", inline="d1")
SessionLow(sessionTime, sessionTimeZone=syminfo.timezone) =>
insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
var float sessionLowPrice = na
if insideSession and not insideSession[1]
sessionLowPrice := low
else if insideSession
sessionLowPrice := math.min(sessionLowPrice, low)
sessionLowPrice
SessionHigh(sessionTime, sessionTimeZone=syminfo.timezone) =>
insideSession = not na(time(timeframe.period, sessionTime, sessionTimeZone))
var float sessionHighPrice = na
if insideSession and not insideSession[1]
sessionHighPrice := high
else if insideSession
sessionHighPrice := math.max(sessionHighPrice, high)
sessionHighPrice
InSession(sessionTimes, sessionTimeZone=syminfo.timezone) =>
not na(time(timeframe.period, sessionTimes, sessionTimeZone))
// days of the week
sessionDays = ""
if monSession
sessionDays += "2"
if tuesSession
sessionDays += "3"
if wedSession
sessionDays += "4"
if thuSession
sessionDays += "5"
if friSession
sessionDays += "6"
tradingSession = session + ":" + sessionDays
// h and l
sessLow = SessionLow(tradingSession, timeZone)
sessHigh = SessionHigh(tradingSession, timeZone)
// Plot the session low and high
plot(sessLow, color=#09e43f, title="Session Low")
plot(sessHigh, color=color.red, title="Session High")
// Open long when the price crosses below the session low and returns within the range
if (low < sessLow) and (close > sessLow)
strategy.entry("Long", strategy.long)
// Open short when the price crosses above the session high and returns within the range
if (high > sessHigh) and (close < sessHigh)
strategy.entry("Short", strategy.short)
// Highlight the session background
bgcolor(InSession(tradingSession, timeZone) ? color.new(color.aqua, 90) : na)Editor is loading...