Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Session Range Boxes", overlay=true)
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Inputs
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Seasonal Adjustment Input
- season = input(defval="Fall/Winter", options=["Spring/Summer", "Fall/Winter"], title="US Season")
- //Session Display Toggles
- show_asia = input(defval=true, title="Show Asian Session")
- show_lon = input(defval=false, title="Show London Session")
- show_usa = input(defval=false, title="Show US Session")
- //Pip Range Display Toggle
- show_pip_range = input(defval=true, title="Show Pip Ranges")
- //50 asian display toggle
- show_50_asian = input(defval=false, title="Show Asian 50%")
- show_50_london = input(defval=false, title="Show London 50%")
- show_50_usa = input(defval=false, title="Show US 50%")
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //USE THIS SECTION TO EDIT BOX AND LABEL COLORS
- asia_color = #0f45b0 //color.black
- lon_color = #0073f5 //color.black
- usa_color = #832721 //color.black
- //You can change the colors by either using the built in color variables:
- //color.aqua, color.black, color.blue, color.fuchsia, color.gray, color.green, color.lime, color.maroon, color.navy, color.olive, color.orange, color.purple, color.red, color.silver, color.teal, color.white, color.yellow
- //Alternatively, you can select a hex code for any color you want.
- //There are a number of online resources to find hex codes. My personal favorite is https://www.color-hex.com/color-wheel/
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Definitions
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Sessions
- t_asia = season=="Spring/Summer" ? time(timeframe.period, "1700-0200") : time(timeframe.period, "1900-0200")
- t_lon = time(timeframe.period, "0300-0700")
- t_usa = time(timeframe.period, "0800-1600")
- //Function to detect if time is in session
- time_in_range(sess)=> not na(sess) ? 1 : 0
- //Active Session Conditions
- asia_session_active = show_asia ? (time_in_range(t_asia)==1 ? 1 : 0) : na
- lon_session_active = show_lon ? (time_in_range(t_lon)==1 ? 1 : 0) : na
- usa_session_active = show_usa ? (time_in_range(t_usa)==1 ? 1 : 0) : na
- //Session Starting Points
- asia_start = (asia_session_active[1]==0) and (asia_session_active==1) ? 1 : 0
- lon_start = (lon_session_active[1]==0) and (lon_session_active==1) ? 1 : 0
- usa_start = (usa_session_active[1]==0) and (usa_session_active==1) ? 1 : 0
- //Session Ending Points
- asia_end = (asia_session_active[1]==1) and (asia_session_active==0) ? 1 : 0
- lon_end = (lon_session_active[1]==1) and (lon_session_active==0) ? 1 : 0
- usa_end = (usa_session_active[1]==1) and (usa_session_active==0) ? 1 : 0
- //Session High & Low Function
- sess_hh_ll(session_active, start)=>
- var hh = high
- var ll = low
- if session_active==1
- if (high > hh) or start
- hh := high
- if (low < ll) or start
- ll := low
- [hh, ll]
- //Session Highs & Lows
- [asia_h, asia_l] = sess_hh_ll(asia_session_active, asia_start)
- [lon_h, lon_l] = sess_hh_ll(lon_session_active, lon_start)
- [usa_h, usa_l] = sess_hh_ll(usa_session_active, usa_start)
- //Session Colors
- asia_line_color = color.new(asia_color, 0)
- lon_line_color = color.new(lon_color, 0)
- usa_line_color = color.new(usa_color, 0)
- //Session Box Drawing Function
- draw_session_box(session_active, start, end, h, l, line_color, show_50)=>
- bars = barssince(start)
- var line start_line_dev = na
- var line end_line_dev = na
- var line high_line_dev = na
- var line low_line_dev = na
- var line fifty_line_dev = na
- var line start_line = na
- var line end_line = na
- var line high_line = na
- var line low_line = na
- var line fifty_line = na
- if session_active
- line.delete(start_line_dev)
- line.delete(end_line_dev)
- line.delete(high_line_dev)
- line.delete(low_line_dev)
- line.delete(fifty_line_dev)
- start_line_dev := line.new(x1=bar_index[bars], y1=h, x2=bar_index[bars], y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- end_line_dev := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- high_line_dev := line.new(x1=bar_index[bars], y1=h, x2=bar_index, y2=h, xloc=xloc.bar_index, color=line_color, width=1)
- low_line_dev := line.new(x1=bar_index[bars], y1=l, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- if show_50
- fifty_line_dev := line.new(x1=bar_index[bars], y1=l+((h-l)/2), x2=bar_index, y2=l+((h-l)/2), xloc=xloc.bar_index, color=line_color, width=1)
- if end
- line.delete(start_line_dev)
- line.delete(end_line_dev)
- line.delete(high_line_dev)
- line.delete(low_line_dev)
- line.delete(fifty_line_dev)
- start_line := line.new(x1=bar_index[bars], y1=h, x2=bar_index[bars], y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- end_line := line.new(x1=bar_index, y1=h, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- high_line := line.new(x1=bar_index[bars], y1=h, x2=bar_index, y2=h, xloc=xloc.bar_index, color=line_color, width=1)
- low_line := line.new(x1=bar_index[bars], y1=l, x2=bar_index, y2=l, xloc=xloc.bar_index, color=line_color, width=1)
- if show_50
- fifty_line := line.new(x1=bar_index[bars], y1=l+((h-l)/2), x2=bar_index, y2=l+((h-l)/2), xloc=xloc.bar_index, color=line_color, width=1)
- //Session Label Printing Function
- print_session_label(session_active, h, l, start, end, label_color)=>
- bars = barssince(start)
- var label range_label_dev = na
- var label range_label = na
- if session_active
- label.delete(range_label_dev)
- range_label_dev := label.new(x=bar_index[bars/2], y=l, text="R = " + tostring((h - l)*10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_labelup, textcolor=label_color, size=size.normal)
- if end
- label.delete(range_label_dev)
- range_label := label.new(x=bar_index[bars/2], y=l, text="R = " + tostring((h - l)*10000), xloc=xloc.bar_index, yloc=yloc.price, color=color.new(color.white, 100), style=label.style_labelup, textcolor=label_color, size=size.normal)
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Outputs
- //-----------------------------------------------------------------------------------------------------------------------------------------------------------------
- //Session Range Boxes
- draw_session_box(asia_session_active, asia_start, asia_end, asia_h, asia_l, asia_line_color, show_50_asian)
- draw_session_box(lon_session_active, lon_start, lon_end, lon_h, lon_l, lon_line_color,show_50_london)
- draw_session_box(usa_session_active, usa_start, usa_end, usa_h, usa_l, usa_line_color,show_50_usa)
- //Session Range Labels
- if show_pip_range
- print_session_label(asia_session_active, asia_h, asia_l, asia_start, asia_end, asia_line_color)
- print_session_label(lon_session_active, lon_h, lon_l, lon_start, lon_end, lon_line_color)
- print_session_label(usa_session_active, usa_h, usa_l, usa_start, usa_end, usa_line_color)
Advertisement
Add Comment
Please, Sign In to add comment