luxalgo session
luxalgo session
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Sessions [LuxAlgo]", "LuxAlgo - Sessions", overlay = true, max_bars_back
= 500, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
//Session A
show_sesa = input(true, '', inline = 'sesa', group = 'Session A')
sesa_txt = input('New York', '', inline = 'sesa', group = 'Session A')
sesa_ses = input.session('1300-2200', '', inline = 'sesa', group = 'Session A')
sesa_css = input.color(#ff5d00, '', inline = 'sesa', group = 'Session A')
//Session B
show_sesb = input(true, '', inline = 'sesb', group = 'Session B')
sesb_txt = input('London', '', inline = 'sesb', group = 'Session B')
sesb_ses = input.session('0700-1600', '', inline = 'sesb', group = 'Session B')
sesb_css = input.color(#2157f3, '', inline = 'sesb', group = 'Session B')
//Session C
show_sesc = input(true, '', inline = 'sesc', group = 'Session C')
sesc_txt = input('Tokyo', '', inline = 'sesc', group = 'Session C')
sesc_ses = input.session('0000-0900', '', inline = 'sesc', group = 'Session C')
sesc_css = input.color(#e91e63, '', inline = 'sesc', group = 'Session C')
//Session D
show_sesd = input(true, '', inline = 'sesd', group = 'Session D')
sesd_txt = input('Sydney', '', inline = 'sesd', group = 'Session D')
sesd_ses = input.session('2100-0600', '', inline = 'sesd', group = 'Session D')
sesd_css = input.color(#ffeb3b, '', inline = 'sesd', group = 'Session D')
//Timezones
tz_incr = input.int(0, 'UTC (+/-)', group = 'Timezone')
use_exchange = input(false, 'Use Exchange Timezone', group = 'Timezone')
//Ranges Options
bg_transp = input.float(90, 'Range Area Transparency', group = 'Ranges Settings')
show_outline = input(true, 'Range Outline', group = 'Ranges Settings')
show_txt = input(true, 'Range Label', group = 'Ranges Settings')
//Dashboard
show_dash = input(false, 'Show Dashboard', group = 'Dashboard')
advanced_dash = input(false, 'Advanced Dashboard', group = 'Dashboard')
dash_loc = input.string('Top Right', 'Dashboard Location', options = ['Top Right',
'Bottom Right', 'Bottom Left'], group = 'Dashboard')
text_size = input.string('Small', 'Dashboard Size', options = ['Tiny', 'Small',
'Normal'], group = 'Dashboard')
//Divider
show_ses_div = input(false, 'Show Sessions Divider', group = 'Dividers')
show_day_div = input(true, 'Show Daily Divider', group = 'Dividers')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
sma
var float y1 = na
var float y2 = na
var float stdev = na
var float r2 = na
y1 := 4 * sma - 3 * wma
y2 := 3 * wma - 2 * sma
//Session Vwap
get_vwap(session) =>
var float num = na
var float den = na
[num, den]
//Set line
set_line(session, y1, y2, session_css)=>
var line tl = na
if show_txt
lbl := label.new(t, max, session_name
, xloc = xloc.bar_time
, textcolor = session_css
, style = label.style_label_down
, color = color.new(color.white, 100)
, size = size.tiny)
box.set_top(bx, max)
box.set_rightbottom(bx, n, min)
if show_txt
label.set_xy(lbl, int(math.avg(t, time)), max)
//-----------------------------------------------------------------------------}
//Sessions
//-----------------------------------------------------------------------------{
tf = timeframe.period
//-----------------------------------------------------------------------------}
//Dashboard
//-----------------------------------------------------------------------------{
var table_position = dash_loc == 'Bottom Left' ? position.bottom_left
: dash_loc == 'Top Right' ? position.top_right
: position.bottom_right
var tb = table.new(table_position, 5, 6
, bgcolor = #1e222d
, border_color = #373a46
, border_width = 1
, frame_color = #373a46
, frame_width = 1)
if advanced_dash
table.cell(tb, 0, 1, 'Session', text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Overlays
//-----------------------------------------------------------------------------{
var float max_sesa = na
var float min_sesa = na
var float max_sesb = na
var float min_sesb = na
var float max_sesc = na
var float min_sesc = na
var float max_sesd = na
var float min_sesd = na
//Ranges
if show_sesa and sesa_range
[max, min] = get_range(is_sesa, sesa_txt, sesa_css)
max_sesa := max
min_sesa := min
//Trendlines
if show_sesa and (sesa_tl or advanced_dash)
[y1, y2, stdev, r2] = get_linreg(is_sesa)
if advanced_dash
table.cell(tb, 2, 2, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
if sesa_tl
set_line(is_sesa, y1, y2, sesa_css)
if advanced_dash
table.cell(tb, 2, 3, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
if sesb_tl
set_line(is_sesb, y1, y2, sesb_css)
if sesc_tl
set_line(is_sesc, y1, y2, sesc_css)
if advanced_dash
table.cell(tb, 2, 5, str.tostring(r2, '#.##')
, bgcolor = r2 > 0 ? #089981 : #f23645
, text_color = color.white
, text_size = table_size)
if sesd_tl
set_line(is_sesd, y1, y2, sesd_css)
//Mean
if show_sesa and sesa_avg
avg = get_avg(is_sesa)
set_line(is_sesa, avg, avg, sesa_css)
//VWAP
var float vwap_a = na
var float vwap_b = na
var float vwap_c = na
var float vwap_d = na
if sesa_vwap
vwap_a := num / den
if advanced_dash
table.cell(tb, 3, 2, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if sesb_vwap
vwap_b := num / den
if advanced_dash
table.cell(tb, 3, 3, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if sesc_vwap
vwap_c := num / den
if advanced_dash
table.cell(tb, 3, 4, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
if sesd_vwap
vwap_d := num / den
if advanced_dash
table.cell(tb, 3, 5, str.tostring(den, format.volume)
, text_color = color.white
, text_size = table_size)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
//Plot max/min
plot(sesa_maxmin ? max_sesa : na, 'Session A Maximum', sesa_css, 1,
plot.style_linebr)
plot(sesa_maxmin ? min_sesa : na, 'Session A Minimum', sesa_css, 1,
plot.style_linebr)
//Plot vwaps
plot(vwap_a, 'Session A VWAP', sesa_css, 1, plot.style_linebr)
plot(vwap_b, 'Session B VWAP', sesb_css, 1, plot.style_linebr)
plot(vwap_c, 'Session C VWAP', sesc_css, 1, plot.style_linebr)
plot(vwap_d, 'Session D VWAP', sesd_css, 1, plot.style_linebr)
//Plot Divider A
plotshape(is_sesa and show_ses_div and show_sesa, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesa_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider B
plotshape(is_sesb and show_ses_div and show_sesb, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesb_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider C
plotshape(is_sesc and show_ses_div and show_sesc, "·"
, shape.square
, location.bottom
, na
, text = "."
, textcolor = sesc_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//Plot Divider D
plotshape(is_sesd and show_ses_div and show_sesd, "·"
, shape.labelup
, location.bottom
, na
, text = "."
, textcolor = sesd_css
, size = size.tiny
, display = display.all - display.status_line
, editable = false)
//-----------------------------------------------------------------------------}
//Plots daily dividers
//-----------------------------------------------------------------------------{
day = dayofweek
//-----------------------------------------------------------------------------}