Forex Session Volume Explorer
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EmpiricalFX

//@version=4
study("Forex Session Vol Explorer",overlay=false)
//Groups
gp0 = "Introduction"
gp1 = "Forex Trading Sessions"
gp2 = "Session Configuration"
//Tooltips
t1 = "This indicator is an exploration of how Forex Sessions affect volume. The colored plots below represent the accumulative volume during each of the four major trading sessions: London, New York, Tokyo, and Sydney. Plots have been normalized as a percentage of total volume, i.e. London = 34.2 signifies that 34.2% of all volume occurs during the London Session.Trading the session with the highest volume will greatly benefit your Win Rate, especially when using \"typical\" indicators and strategies."
//Intro
dummy0 = input(true,"Hover over ( ! ) for Introduction",group=gp0, tooltip=t1)
//Sessions
london = input(title="London Session", type=input.session, defval="0300-1200",group=gp1)
ny = input(title="New York Session", type=input.session, defval="0800-1700",group=gp1)
tokyo = input(title="Tokyo Session", type=input.session, defval="2000-0400",group=gp1)
sydney = input(title="Sydney Session", type=input.session, defval="1700-0200",group=gp1)
//Config
input_src = input("Volume","Accumulation Data Source",options=["Volatility","Volume"],group=gp2,tooltip="Volume accumulates intrabar volume.\nVolatility accumulates intrabar true range.")
London = input(title="Show London Session", type=input.bool, defval=true,group=gp2)
LondonColor = input(color.blue,"London Color",input.color,group=gp2)
NY = input(title="Show New York Session", type=input.bool, defval=true,group=gp2)
NYColor = input(color.red,"New York Color",input.color,group=gp2)
Tokyo = input(title="Show Tokyo Session", type=input.bool, defval=true,group=gp2)
TokyoColor = input(color.yellow,"Tokyo Color", input.color,group=gp2)
Sydney = input(title="Show Sydney Session", type=input.bool, defval=true,group=gp2)
SydneyColor = input(color.green,"Sydney Color",input.color,group=gp2)

//Returns true if given session is current
is_session(sess) =>
    not na(time("D", sess))

//Data Curation
var London_accum = 0.0
var NY_accum = 0.0
var Tokyo_accum = 0.0
var Sydney_accum = 0.0
var Vol_accum = 0.0
src = input_src == "Volume" ? nz(volume) :
      input_src == "Volatility" ? nz(tr) : na

if(timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly)
    var notice = label.new(bar_index,1,"Sorry! Session analysis only\nworks on Intraday Charts!",color=color.white,style=label.style_label_center,size=size.huge)
    label.set_x(notice,bar_index)
if(not(timeframe.isdaily or timeframe.isweekly or timeframe.ismonthly))
    if(London and is_session(london))
        London_accum += src
    if(NY and is_session(ny))
        NY_accum += src
    if(Tokyo and is_session(tokyo))
        Tokyo_accum += src
    if(Sydney and is_session(sydney))
        Sydney_accum += src
Vol_accum := (London_accum + NY_accum + Tokyo_accum + Sydney_accum)
    
plot(London?100*London_accum/Vol_accum:na,"London Session Accumulated Volume",LondonColor,2,editable=false)
plot(NY?100*NY_accum/Vol_accum:na,"New York Session Accumulated Volume",NYColor,2,editable=false)
plot(Tokyo?100*Tokyo_accum/Vol_accum:na,"Tokyo Session Accumulated Volume",TokyoColor,2,editable=false)
plot(Sydney?100*Sydney_accum/Vol_accum:na,"Sydney Session Accumulated Volume",SydneyColor,2,editable=false)