You are on page 1of 7

//@version=5

indicator("Sessions and High/Low", overlay=true, max_lines_count=500,


max_boxes_count=500)

// Constants and One-Time-Init Vars {


transpLine = 0
transpFill = 90

// calc bar in min


var bar_time = 0

if bar_index == 3
timeDiff1 = (time - time[1]) / 60000
timeDiff2 = (time[2] - time[3]) / 60000

bar_time := math.min(timeDiff1, timeDiff2)


// }

// Inputs {
i_showHighLow = input(false, "Show Highs/Lows")
i_hideSessiontf = input.int(59, "Hide Session on TF above (Minutes)", 1)
i_showMidLine = input.bool(true, "Show Session Mid Lines")

grpAsia = "Asia Session"


i_showAsiaSession = input.bool(true, "Session", inline="asia session",
group=grpAsia)
i_asiaSession = input.session("1700-0100", "", inline="asia session",
group=grpAsia)
i_useAsiaLineCl = input.bool(true, "Border Color", inline="asia line",
group=grpAsia)
i_asiaLineCl = i_useAsiaLineCl ? input.color(color.new(color.blue, transpLine), "",
inline="asia line", group=grpAsia) : na
i_useAsiaFill = input.bool(false, "Fill Color", inline="asia fill", group=grpAsia)
i_asiaFillCl = i_useAsiaFill ? input.color(color.new(color.blue, transpFill), "",
inline="asia fill", group=grpAsia) : na

grpFrankfurt = "Frankfurt Session"


i_showFrankfurtSession = input.bool(true, "Session", inline="frankfurt session",
group=grpFrankfurt)
i_frankfurtSession = input.session("0200-0300", "", inline="frankfurt session",
group=grpFrankfurt)
i_useFrankfurtLineCl = input.bool(true, "Border Color", inline="frankfurt line",
group=grpFrankfurt)
i_frankfurtLineCl = i_useFrankfurtLineCl ? input.color(color.new(color.orange,
transpLine), "", inline="frankfurt line", group=grpFrankfurt) : na
i_useFrankfurtFillCl = input.bool(false, "Fill Color", inline="frankfurt fill",
group=grpFrankfurt)
i_frankfurtFillCl = i_useFrankfurtFillCl ? input.color(color.new(color.orange,
transpFill), "", inline="frankfurt fill", group=grpFrankfurt) : na

grpLondon = "London Session"


i_showLondonSession = input.bool(true, "Session", inline="london session",
group=grpLondon)
i_londonSession = input.session("0300-0400", "", inline="london session",
group=grpLondon)
i_useLondonLineCl = input.bool(true, "Border Color", inline="london line",
group=grpLondon)
i_londonLineCl = i_useLondonLineCl ? input.color(color.new(color.green,
transpLine), "", inline="london line", group=grpLondon) : na
i_useLondonFillCl = input.bool(false, "Fill Color", inline="london fill",
group=grpLondon)
i_londonFillCl = i_useLondonFillCl ? input.color(color.new(color.green,
transpFill), "", inline="london fill", group=grpLondon) : na

grpNewYork = "New York Session"


i_showNewYorkSession = input.bool(true, "Session", inline="newyork session",
group=grpNewYork)
i_newYorkSession = input.session("0900-1000", "", inline="newyork session",
group=grpNewYork)

i_useNewYorkLineCl = input.bool(true, "Border Color", inline="newyork line",


group=grpNewYork)
i_newYorkLineCl = i_useNewYorkLineCl ? input.color(color.new(color.white,
transpLine), "", inline="newyork line", group=grpNewYork) : na
i_useNewYorkFillCl = input.bool(false, "Fill Color", inline="newyork fill",
group=grpNewYork)
i_newYorkFillCl = i_useNewYorkFillCl ? input.color(color.new(color.white,
transpFill), "", inline="newyork fill", group=grpNewYork) : na

grpMMM = "MMM"
i_MMMlength = input.int(200, "MMM Lenght", 0, group=grpMMM)
i_hideMMMtf = input.int(59, "Hide MMM on TF above (Minutes)", 1, group=grpMMM)

i_showMMM1 = input.bool(true, "MMM 1", inline="mmm1", group=grpMMM)


i_MMM1color = input.color(color.red, "", inline="mmm1", group=grpMMM)
i_MMM1hour = input.int(4, "", 0, 23, inline="mmm1", group=grpMMM)
i_MMM1minute = input.int(30, ":", 0, 59, inline="mmm1", group=grpMMM)
i_MMM1width = input.int(1, "MMM 1 Width", 1, 10, group=grpMMM)

i_showMMM2 = input.bool(true, "MMM 2", inline="mmm2", group=grpMMM)


i_MMM2color = input.color(color.red, "", inline="mmm2", group=grpMMM)
i_MMM2hour = input.int(6, "", 0, 23, inline="mmm2", group=grpMMM)
i_MMM2minute = input.int(30, ":", 0, 59, inline="mmm2", group=grpMMM)
i_MMM2width = input.int(1, "MMM 2 Width", 1, 10, group=grpMMM)

i_showMMM3 = input.bool(true, "MMM 3", inline="mmm3", group=grpMMM)


i_MMM3color = input.color(color.red, "", inline="mmm3", group=grpMMM)
i_MMM3hour = input.int(11, "", 0, 23, inline="mmm3", group=grpMMM)
i_MMM3minute = input.int(00, ":", 0, 59, inline="mmm3", group=grpMMM)
i_MMM3width = input.int(1, "MMM 3 Width", 1, 10, group=grpMMM)
// }

// Functions {
//Bars
isNewBar(sess) =>
t = time("D", sess)
na(t[1]) and not na(t) or t[1] < t

isSession(sess) =>
not na(time("D", sess))

f_getSession(newbar, session, currentLow, currentHigh, currentStart, currentEnd) =>


newLow = currentLow
newHigh = currentHigh
newStart = currentStart
newEnd = currentEnd

newLow := if session
if newbar
low
else
math.min(newLow[1],low)
else
newLow[1]

newHigh := if session
if newbar
high
else
math.max(newHigh[1],high)
else
newHigh[1]

newStart := if session
if newbar
time
else
math.min(newStart[1],time)
else
na

newEnd := if session
if newbar
time_close
else
math.max(newEnd[1],time_close)
else
na

[newLow, newHigh, newStart, newEnd]

f_newBox(left, top, right, bottom, borderCl, backgroundCl) =>


box.new(left, top, right, bottom, borderCl, xloc=xloc.bar_time,
bgcolor=backgroundCl )

f_changeBox(box_, low_, high_, end) =>


box.set_right(box_, end)
box.set_top(box_, high_)
box.set_bottom(box_, low_)

f_drawVertical(cl, width_) =>


low_ = hl2 - (syminfo.mintick) * i_MMMlength
high_ = hl2 + (syminfo.mintick) * i_MMMlength
line.new(time, low_, time, high_, xloc.bar_time, extend.none, cl, width=width_)

f_tfShow(hideValue) =>
hide = bar_time <= hideValue
hide

f_newMidLine(start, yVal, end) =>


line.new(start, yVal, end, yVal, xloc.bar_time, color=color.orange,
style=line.style_dotted)

f_changeMidLine(midLine, yVal, end) =>


line.set_y1(midLine, yVal)
line.set_y2(midLine, yVal)
line.set_x2(midLine, end)
// }

// Calcutations {
pricehigh_daily = request.security(syminfo.tickerid, 'D', high[1])
pricelow_daily = request.security(syminfo.tickerid, 'D', low[1])

pricehigh_weekly = request.security(syminfo.tickerid, 'W', high[1])


pricelow_weekly = request.security(syminfo.tickerid, 'W', low[1])

pricehigh_monthly = request.security(syminfo.tickerid, 'M', high[1])


pricelow_monthly = request.security(syminfo.tickerid, 'M', low[1])

pricehigh_yearly = request.security(syminfo.tickerid, '12M', high[1])


pricelow_yearly = request.security(syminfo.tickerid, '12M', low[1])

// Asia
asiaLow = float(na)
asiaHigh = float(na)
asiaStart = int(na)
asiaEnd = int(na)

asiaNewbar = isNewBar(i_asiaSession)
asiaSession = isSession(i_asiaSession)

[asiaLow_, asiaHigh_, asiaStart_, asiaEnd_] = f_getSession(asiaNewbar, asiaSession,


asiaLow, asiaHigh, asiaStart, asiaEnd)

asiaLow := asiaLow_
asiaHigh := asiaHigh_
asiaStart := asiaStart_
asiaEnd := asiaEnd_

if i_showAsiaSession and asiaSession and f_tfShow(i_hideSessiontf)


asiaBox = if asiaNewbar
f_newBox(asiaStart, asiaHigh, asiaEnd, asiaLow, i_asiaLineCl, i_asiaFillCl)

asiaMidLine = if asiaNewbar and i_showMidLine


yValue = math.avg(asiaHigh, asiaLow)
f_newMidLine(asiaStart, yValue, asiaEnd)

if not asiaNewbar
f_changeBox(asiaBox[1], asiaLow, asiaHigh, asiaEnd)

if i_showMidLine
yValue = math.avg(asiaHigh, asiaLow)
f_changeMidLine(asiaMidLine[1], yValue, asiaEnd)

// Frankfut
frankfurtLow = float(na)
frankfurtHigh = float(na)
frankfurtStart = int(na)
frankfurtEnd = int(na)

frankfurtNewbar = isNewBar(i_frankfurtSession)
frankfurtSession = isSession(i_frankfurtSession)

[frankfurtLow_, frankfurtHigh_, frankfurtStart_, frankfurtEnd_] =


f_getSession(frankfurtNewbar, frankfurtSession, frankfurtLow, frankfurtHigh,
frankfurtStart, frankfurtEnd)

frankfurtLow := frankfurtLow_
frankfurtHigh := frankfurtHigh_
frankfurtStart := frankfurtStart_
frankfurtEnd := frankfurtEnd_

if i_showFrankfurtSession and frankfurtSession and f_tfShow(i_hideSessiontf)


frankfurtBox = if frankfurtNewbar
f_newBox(frankfurtStart, frankfurtHigh, frankfurtEnd, frankfurtLow,
i_frankfurtLineCl, i_frankfurtFillCl)

frankfurtMidLine = if frankfurtNewbar and i_showMidLine


yValue = math.avg(frankfurtHigh, frankfurtLow)
f_newMidLine(frankfurtStart, yValue, frankfurtEnd)

if not frankfurtNewbar
f_changeBox(frankfurtBox[1], frankfurtLow, frankfurtHigh, frankfurtEnd)

if i_showMidLine
yValue = math.avg(frankfurtHigh, frankfurtLow)
f_changeMidLine(frankfurtMidLine[1], yValue, frankfurtEnd)

// London
londonLow = float(na)
londonHigh = float(na)
londonStart = int(na)
londonEnd = int(na)

londonNewbar = isNewBar(i_londonSession)
londonSession = isSession(i_londonSession)

[londonLow_, londonHigh_, londonStart_, londonEnd_] = f_getSession(londonNewbar,


londonSession, londonLow, londonHigh, londonStart, londonEnd)

londonLow := londonLow_
londonHigh := londonHigh_
londonStart := londonStart_
londonEnd := londonEnd_

if i_showLondonSession and londonSession and f_tfShow(i_hideSessiontf)


londonBox = if londonNewbar
f_newBox(londonStart, londonHigh, londonEnd, londonLow, i_londonLineCl,
i_londonFillCl)
londonMidLine = if londonNewbar and i_showMidLine
yValue = math.avg(londonHigh, londonLow)
f_newMidLine(londonStart, yValue, londonEnd)

if not londonNewbar
f_changeBox(londonBox[1], londonLow, londonHigh, londonEnd)

if i_showMidLine
yValue = math.avg(londonHigh, londonLow)
f_changeMidLine(londonMidLine[1], yValue, londonEnd)

// New York
newYorkLow = float(na)
newYorkHigh = float(na)
newYorkStart = int(na)
newYorkEnd = int(na)

newYorkNewbar = isNewBar(i_newYorkSession)
newYorkSession = isSession(i_newYorkSession)

[newYorkLow_, newYorkHigh_, newYorkStart_, newYorkEnd_] =


f_getSession(newYorkNewbar, newYorkSession, newYorkLow, newYorkHigh, newYorkStart,
newYorkEnd)

newYorkLow := newYorkLow_
newYorkHigh := newYorkHigh_
newYorkStart := newYorkStart_
newYorkEnd := newYorkEnd_

if i_showNewYorkSession and newYorkSession and f_tfShow(i_hideSessiontf)


newYorkBox = if newYorkNewbar
f_newBox(newYorkStart, newYorkHigh, newYorkEnd, newYorkLow,
i_newYorkLineCl, i_newYorkFillCl)

newYorkMidLine = if newYorkNewbar and i_showMidLine


yValue = math.avg(newYorkHigh, newYorkLow)
f_newMidLine(newYorkStart, yValue, newYorkEnd)

if not newYorkNewbar
f_changeBox(newYorkBox[1], newYorkLow, newYorkHigh, newYorkEnd)

if i_showMidLine
yValue = math.avg(newYorkHigh, newYorkLow)
f_changeMidLine(newYorkMidLine[1], yValue, newYorkEnd)

// MMMs
if i_showMMM1 and hour == i_MMM1hour and minute == i_MMM1minute and
f_tfShow(i_hideMMMtf)
f_drawVertical(i_MMM1color, i_MMM1width)

if i_showMMM2 and hour == i_MMM2hour and minute == i_MMM2minute and


f_tfShow(i_hideMMMtf)
f_drawVertical(i_MMM2color, i_MMM2width)

if i_showMMM3 and hour == i_MMM3hour and minute == i_MMM3minute and


f_tfShow(i_hideMMMtf)
f_drawVertical(i_MMM3color, i_MMM3width)
// }
// Plots {

//Daily Plots
plot(i_showHighLow and pricehigh_daily ? pricehigh_daily : na, "Previous Daily
High", style=plot.style_linebr, color=color.white)
plot(i_showHighLow and pricelow_daily ? pricelow_daily : na, "Previous Daily Low",
style=plot.style_linebr, color=color.white)

plot(i_showHighLow and pricehigh_weekly ? pricehigh_weekly : na, "Previous Weekly


High", style=plot.style_linebr, color=color.white)
plot(i_showHighLow and pricelow_weekly ? pricelow_weekly : na, "Previous Weekly
Low", style=plot.style_linebr, color=color.white)

plot(i_showHighLow and pricehigh_monthly ? pricehigh_monthly : na, "Previous


Monthly High", style=plot.style_linebr, color=color.white)
plot(i_showHighLow and pricelow_monthly ? pricelow_monthly : na, "Previous Monthly
Low", style=plot.style_linebr, color=color.white)

plot(i_showHighLow and pricehigh_yearly ? pricehigh_yearly : na, "Previous Yearly


High", style=plot.style_linebr, color=color.white)
plot(i_showHighLow and pricelow_yearly ? pricelow_yearly : na, "Previous Yearly
Low", style=plot.style_linebr, color=color.white)
// }

// Alerts {

// }

You might also like