← All Analyses
O
XAUUSD
neutral

FXN-ASIAN SESSION RANGE

Sidhu HYS
1w ago
FXN-ASIAN SESSION RANGE

//@version=5
indicator("FXN - Asian Session Range (Clone)", overlay=true, max_boxes_count=500, max_lines_count=500)

// --- Inputs ---
string i_session = input.session("2000-0200:23456", title="Asian Session Time (EST)", tooltip="Format: HHMM-HHMM followed by days (2=Mon, 3=Tue...)")
string i_timezone = input.string("America/New_York", title="Session Timezone")

// Color Customizations
color c_box_bg = input.color(color.new(#2196F3, 90), title="Session Box Background")
color c_high_line = input.color(#2196F3, title="Asian High Line Color")
color c_mid_line = input.color(#FF9800, title="Asian Midline Color")
color c_low_line = input.color(#F44336, title="Asian Low Line Color")

// Style Options
int i_line_width = input.int(1, minval=1, title="Line Width")
string i_line_style = input.string("Dashed", title="Line Style", options=["Solid", "Dashed", "Dotted"])

// --- Helper function for line style ---
get_line_style(style_str) =>
style_str == "Solid" ? line.style_solid : style_str == "Dashed" ? line.style_dashed : line.style_dotted

// --- Logic to check if we are inside the session ---
in_session = not na(time(timeframe.period, i_session, i_timezone))
session_changed = in_session and not in_session[1]

// --- Persistent variables across bars ---
var int start_bar_index = na
var float session_high = na
var float session_low = na

var box session_box = na
var line high_ext_line = na
var line mid_ext_line = na
var line low_ext_line = na

// --- Script Execution ---
if session_changed
// Triggered on the very first bar of a new Asian session
start_bar_index := bar_index
session_high := high
session_low := low

// Create new visual components for the day
session_box := box.new(left=bar_index, top=session_high, right=bar_index, bottom=session_low, bgcolor=c_box_bg, border_color=color.new(c_high_line, 50))
high_ext_line := line.new(x1=bar_index, y1=session_high, x2=bar_index, y2=session_high, color=c_high_line, width=i_line_width, style=get_line_style(i_line_style))
mid_ext_line := line.new(x1=bar_index, y1=(session_high + session_low) / 2, x2=bar_index, y2=(session_high + session_low) / 2, color=c_mid_line, width=i_line_width, style=get_line_style(i_line_style))
low_ext_line := line.new(x1=bar_index, y1=session_low, x2=bar_index, y2=session_low, color=c_low_line, width=i_line_width, style=get_line_style(i_line_style))

else if in_session
// Continuous updating while the Asian session is active
session_high := math.max(high, session_high)
session_low := math.min(low, session_low)
float session_mid = (session_high + session_low) / 2

// Update the box boundaries and lines dynamically
box.set_top(session_box, session_high)
box.set_bottom(session_box, session_low)
box.set_right(session_box, bar_index)

line.set_xy1(high_ext_line, start_bar_index, session_high)
line.set_xy2(high_ext_line, bar_index, session_high)

line.set_xy1(mid_ext_line, start_bar_index, session_mid)
line.set_xy2(mid_ext_line, bar_index, session_mid)

line.set_xy1(low_ext_line, start_bar_index, session_low)
line.set_xy2(low_ext_line, bar_index, session_low)

else if not na(start_bar_index)
// When the session ends, keep extending lines to the right (into London/NY sessions)
box.set_right(session_box, bar_index)
line.set_x2(high_ext_line, bar_index)
line.set_x2(mid_ext_line, bar_index)
line.set_x2(low_ext_line, bar_index)

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by GoCharting. Read more in the Terms of Use.

Comments (0)

Loading comments…