Indicator Β· Pine Script v5 Β· On the chart

FX Market Sessions

by itmakesyousickΒ· code credited to boitoki

This overlay indicator draws up to four Forex trading sessions on the price chart, defaulting to London, New York, Tokyo, and Sydney.

View on GitHub

GitHub stars7on the repository
Pine versionv5runs as is
Lines of code588
Settings40inputs
LicenceNone statedfile: MPL-2.0
Last update3 years ago25 Jan 2023

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

588 lines of Pine Script v5 from v37.0.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

v37.0.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Β© boitoki

//@version=5
indicator('FX Market Sessions', overlay=true, max_bars_back=500)

import boitoki/AwesomeColor/4 as ac
import boitoki/Utilities/3 as util

///////////////
// Groups
///////////////
g0              = 'π‹‰πŠ€π‘ΏπŠ€πŠ―π‹Žπ‘–α‚½'
g1_01           = 'β™―1 α‚½πŠ€α‚½α‚½πŠ¦Ξ˜π‘Ώ'
g1_02           = 'β™―2 α‚½πŠ€α‚½α‚½πŠ¦Ξ˜π‘Ώ'
g1_03           = 'β™―3 α‚½πŠ€α‚½α‚½πŠ¦Ξ˜π‘Ώ'
g1_04           = 'β™―4 α‚½πŠ€α‚½α‚½πŠ¦Ξ˜π‘Ώ'
g4              = 'πŒ±Ξ˜π‹‚'
g6              = 'π‘–π‹ŽπŒ±πŠ€π‘–α‚½'
g5              = 'Ξ˜Ο·πŠ€π‘ΏπŠ¦π‘Ώπ‹‰ πŠ―π‹Žπ‘Ώπ‹‰πŠ€'
g7              = 'πŠ₯πŠ¦πŒ±Ξ˜π‘Ώπ‹ŽπŠ’πŠ’πŠ¦ π‘–πŠ€πŒ±πŠ€π‘–α‚½'
g8              = 'Ξ˜Ο·π¨πŠ¦Ξ˜π‘Ώα‚½'
g10             = 'Ξ˜α‚½πŠ’πŠ¦π‘–π‘–π‹Žπ¨Ξ˜πŠ― 𐊰Θᱚ𐊀'
g11             = 'πŠ’π‹Žπ‘Ώα±šπ‘–πŠ€'

///////////////
// Defined
///////////////
max_bars        = 500

option_yes      = 'Yes'
option_no       = 'Γ— No'
option_extend1  = 'Yes'
option_hide     = 'Γ— Hide'

fmt_price       = '{0,number,#.#####}'
fmt_pips        = '{0,number,#.#}'

icon_separator  = ' β€’ '

color_none      = color.new(color.black, 100)

///////////////
// Functions
///////////////
f_get_time_by_bar(bar_count) => timeframe.multiplier * bar_count * 60 * 1000

f_get_period (_session, _start, _lookback) =>
    result = math.max(_start, 1)
    for i = result to _lookback
        if na(_session[i+1]) and _session[i]
            result := i+1
            break
    result

f_get_label_position (_y, _side) =>
    switch _y
        'top'    => _side == 'outside' ? label.style_label_lower_left : label.style_label_upper_left
        'bottom' => _side == 'outside' ? label.style_label_upper_left : label.style_label_lower_left

f_get_started (_session) => na(_session[1]) and _session

f_get_ended (_session) => na(_session) and _session[1]

f_message_limit_bars (_v) => '⚠️ This box\'s right position exceeds 500 bars(' + str.tostring(_v) + '). This box is not displayed correctly.'

f_set_line_x1 (_line, _x) =>
    if (line.get_x1(_line) != _x)
        line.set_x1(_line, _x)

f_set_line_x2 (_line, _x) =>
    if (line.get_x2(_line) != _x)
        line.set_x2(_line, _x)

f_set_box_right (_box, _x) =>
    if box.get_right(_box) != _x
        box.set_right(_box, _x)

///////////////
// Inputs
///////////////
// Timezone
i_tz                    = input.string('GMT+1', title='Timezone', options=['GMT-11', 'GMT-10', 'GMT-9', 'GMT-8', 'GMT-7', 'GMT-6', 'GMT-5', 'GMT-4', 'GMT-3', 'GMT-2', 'GMT-1', 'GMT', 'GMT+1', 'GMT+2', 'GMT+3', 'GMT+330', 'GMT+4', 'GMT+430', 'GMT+5', 'GMT+530', 'GMT+6', 'GMT+7', 'GMT+8', 'GMT+9', 'GMT+10', 'GMT+11', 'GMT+12'], tooltip='e.g. \'America/New_York\', \'Asia/Tokyo\', \'GMT-4\', \'GMT+9\'...', group=g0)
i_history_period        = input.int(3, 'History', minval=0, maxval=100, group=g0)
i_show                  = i_history_period > 0
i_lookback              = 12 * 60

// Sessions
i_show_sess1            = input.bool(true, 'Session 1: ', group=g1_01, inline='session1_1') and i_show
i_sess1_label           = input.string('London', ' ', group=g1_01, inline='session1_1')
i_sess1_color           = input.color(#66D9EF, ' ', group=g1_01, inline='session1_1')
i_sess1                 = input.session('0800-1700', 'Time', group=g1_01)
i_sess1_extend          = input.string(option_no, 'Extend', options=[option_no, option_extend1], group=g1_01)
i_sess1_fib             = input.string(option_no, 'Fibonacci levels', group=g1_01, options=[option_yes, option_no]) != option_no
i_sess1_op              = input.string(option_no, 'Opening range', group=g1_01, options=[option_yes, option_no]) != option_no and i_show

i_show_sess2            = input.bool(true, 'Session 2: ', group=g1_02, inline='session2_1') and i_show
i_sess2_label           = input.string('New York', ' ', group=g1_02, inline='session2_1')
i_sess2_color           = input.color(#FD971F, ' ', group=g1_02, inline='session2_1')
i_sess2                 = input.session('1300-2200', 'Time', group=g1_02)
i_sess2_extend          = input.string(option_no, 'Extend', options=[option_no, option_extend1], group=g1_02)
i_sess2_fib             = input.string(option_no, 'Fibonacci levels', group=g1_02, options=[option_yes, option_no]) != option_no
i_sess2_op              = input.string(option_no, 'Opening range', group=g1_02, options=[option_yes, option_no]) != option_no and i_show

i_show_sess3            = input.bool(true, 'Session 3: ', group=g1_03, inline='session3_1') and i_show
i_sess3_label           = input.string('Tokyo', ' ', group=g1_03, inline='session3_1')
i_sess3_color           = input.color(#AE81FF, ' ', group=g1_03, inline='session3_1')
i_sess3                 = input.session('0100-1000', 'Time', group=g1_03)
i_sess3_extend          = input.string(option_no, 'Extend', options=[option_no, option_extend1], group=g1_03)
i_sess3_fib             = input.string(option_no, 'Fibonacci levels', group=g1_03, options=[option_yes, option_no]) != option_no
i_sess3_op              = input.string(option_no, 'Opening range', group=g1_03, options=[option_yes, option_no]) != option_no and i_show

i_show_sess4            = input.bool(true, 'Session 4: ', group=g1_04, inline='session4_1') and i_show
i_sess4_label           = input.string('Sydney', ' ', group=g1_04, inline='session4_1')
i_sess4_color           = input.color(#FB71A3, ' ', group=g1_04, inline='session4_1')
i_sess4                 = input.session('2200-0700', 'Time', group=g1_04)
i_sess4_extend          = input.string(option_no, 'Extend', options=[option_no, option_extend1], group=g1_04)
i_sess4_fib             = input.string(option_no, 'Fibonacci levels', group=g1_04, options=[option_yes, option_no]) != option_no
i_sess4_op              = input.string(option_no, 'Opening range', group=g1_04, options=[option_yes, option_no]) != option_no and i_show

// Show & Styles
i_sess_box_style        = input.string('Box', 'Style', options=['Box', 'Sandwich'], group=g4)
i_sess_border_style     = input.string(line.style_dashed, 'Line style', options=[line.style_solid, line.style_dotted, line.style_dashed], group=g4)
i_sess_border_width     = input.int(1, 'Thickness', minval=0, group=g4)
i_sess_bgopacity        = input.int(94, 'Transp', minval=0, maxval=100, step=1, group=g4, tooltip='Setting the 100 is no background color')

// Candle
option_candle_body      = 'Show (Body only)'
option_candle_wick      = 'Show'
i_candle                = input.string(option_hide, 'Display', options=[option_candle_wick, option_candle_body, option_hide], group=g11)
i_show_candle           = i_candle != option_hide
i_show_candle_wick      = i_candle == option_candle_wick
i_candle_border_width   = input.int(2, 'Thickness', minval=0, group=g11)
option_candle_color1    = 'Session\'s'
option_candle_color2    = 'Red/Green'
i_candle_color          = input.string(option_candle_color2, 'Candle color', options=[option_candle_color1, option_candle_color2], group=g11, inline='candle_color')
i_candle_color_g        = input.color(#A6E22E, '', group=g11, inline='candle_color')
i_candle_color_r        = input.color(#F92672, '', group=g11, inline='candle_color')

// Labels
i_label_show            = input.bool(true, 'Show labels', inline='label_show', group=g6) and i_show
i_label_size            = str.lower(input.string('Small', '', options=['Auto', 'Tiny', 'Small', 'Normal', 'Large', 'Huge'], inline='label_show', group=g6))
i_label_position_y      = str.lower(input.string('Top', '', options=['Top', 'Bottom'], inline='label_show', group=g6))
i_label_position_s      = str.lower(input.string('Outside', '', options=['Inside', 'Outside'], inline='label_show', group=g6))
i_label_position        = f_get_label_position(i_label_position_y, i_label_position_s)
i_label_format_name     = input.bool(true, 'Name', inline='label_format', group=g6)
i_label_format_day      = input.bool(false, 'Day', inline='label_format', group=g6)
i_label_format_price    = input.bool(false, 'Price', inline='label_format', group=g6)
i_label_format_pips     = input.bool(false, 'Pips', inline='label_format', group=g6)

// Fibonacci levels
i_f_linestyle           = input.string(line.style_solid, title="Style", options=[line.style_solid, line.style_dotted, line.style_dashed], group=g7)
i_f_linewidth           = input.int(1, title="Thickness", minval=1, group=g7)

// Opening range
i_o_minutes             = input.int(15, title='Periods (minutes)', minval=1, step=1, group=g5)
i_o_minutes            := math.max(i_o_minutes, timeframe.multiplier + 1)
i_o_transp              = input.int(88, title='Transp', minval=0, maxval=100, step=1, group=g5)

// Oscillator mode
i_osc                   = input.bool(false, 'Oscillator', inline='osc', group=g10)
i_osc_min               = input.float(0, '', inline='osc', group=g10)
i_osc_max               = input.float(100, '-', inline='osc', group=g10)

// ------------------------
// Drawing labels
// ------------------------
f_render_label (_show, _session, _is_started, _color, _top, _bottom, _text, _labels) =>
    var label my_label = na
    var int start_time = na

    v_position_y = (i_label_position_y == 'top') ? _top : _bottom
    v_label = array.new_string()
    v_chg = _top - _bottom
    
    if _is_started
        start_time := time
    
    if i_label_format_name and not na(_text)
        array.push(v_label, _text)

    if i_label_format_day
        array.push(v_label, util.get_day(dayofweek(start_time, i_tz)))

    if i_label_format_price
        array.push(v_label, str.format(fmt_price, v_chg))
    
    if i_label_format_pips
        array.push(v_label, str.format(fmt_pips, util.toPips(v_chg)) + ' pips')

    if _show
        if _is_started
            my_label := label.new(bar_index, v_position_y, array.join(v_label, icon_separator), textcolor=_color, color=color_none, size=i_label_size, style=i_label_position)
            
            array.push(_labels, my_label)

            util.clear_labels(_labels, i_history_period)

        else if _session
            label.set_y(my_label, v_position_y)
            label.set_text(my_label, array.join(v_label, icon_separator))

// ------------------------
// Drawing Fibonacci levels
// ------------------------
f_render_fibonacci (_show, _session, _is_started, _x1, _x2, _color, _top, _bottom, _level, _width, _style, _is_extend, _lines) =>
    var line my_line = na

    if _show
        y = (_top - _bottom) * _level + _bottom

        if _is_started
            my_line := line.new(_x1, y, _x2, y, width=_width, color=color.new(_color, 30), style=_style)
            array.push(_lines, my_line)

            if _is_extend
                line.set_extend(my_line, extend.right)

        else if _session
            line.set_y1(my_line, y)
            line.set_y2(my_line, y)

            f_set_line_x2(my_line, _x2)

// ------------------------
// Drawing Opening range
// ------------------------
f_render_oprange (_show, _session, _is_started, _x1, _x2, _color, _max, _is_extend, _boxes) =>
    var int start_time = na
    var box my_box = na

    top             = ta.highest(high, _max)
    bottom          = ta.lowest(low, _max)
    is_crossover    = ta.crossover(close, box.get_top(my_box))
    is_crossunder   = ta.crossunder(close, box.get_bottom(my_box))
    
    if _show
        if _is_started
            util.clear_boxes(_boxes, math.max(0, i_history_period - 1))

            start_time  := time
            my_box      := na

        else if _session
            time_op = start_time + (i_o_minutes * 60 * 1000)
            time_op_delay = time_op - f_get_time_by_bar(1)
            
            if time <= time_op and time > time_op_delay
                my_box := box.new(_x1, top, _x2, bottom, border_width=0, bgcolor=color.new(_color, i_o_transp))
                array.push(_boxes, my_box)

                if _is_extend
                    box.set_extend(my_box, extend.right)
                    my_box

            else
                f_set_box_right(my_box, _x2)

                if is_crossover
                    alert('Price crossed over the opening range', alert.freq_once_per_bar)

                if is_crossunder
                    alert('Price crossed under the opening range', alert.freq_once_per_bar)

                my_box


// ------------------------
// Drawing candle
// ------------------------
f_render_candle (_show, _session, _is_started, _is_ended, _color, _top, _bottom, _open, _x1, _x2, _boxes, _lines) =>
    var box body = na
    var line wick1 = na
    var line wick2 = na

    border_width = i_candle_border_width
    cx = math.round(math.avg(_x2, _x1)) - math.round(border_width / 2)
    
    body_color = i_candle_color == option_candle_color2 ? close > _open ? i_candle_color_g : i_candle_color_r : _color
    
    if _show
        if _is_started
            body    := box.new(_x1, _top, _x2, _bottom, body_color, border_width, line.style_solid, bgcolor=color.new(color.black, 100))
            wick1   := i_show_candle_wick ? line.new(cx, _top, cx, _top, color=_color, width=border_width, style=line.style_solid) : na
            wick2   := i_show_candle_wick ? line.new(cx, _bottom, cx, _bottom, color=_color, width=border_width, style=line.style_solid) : na

            array.push(_boxes, body)
            array.push(_lines, wick1)
            array.push(_lines, wick2)

            util.clear_boxes(_boxes, i_history_period)
            util.clear_lines(_lines, i_history_period * 2)

        else if _session
            top    = math.max(_open, close)
            bottom = math.min(_open, close)

            box.set_top(body, top)
            box.set_bottom(body, bottom)
            box.set_right(body, _x2)
            box.set_border_color(body, body_color)
            
            line.set_y1(wick1, _top)
            line.set_y2(wick1, top)
            f_set_line_x1(wick1, cx)
            f_set_line_x2(wick1, cx)
            line.set_color(wick1, body_color)

            line.set_y1(wick2, _bottom)
            line.set_y2(wick2, bottom)
            f_set_line_x1(wick2, cx)
            f_set_line_x2(wick2, cx)
            line.set_color(wick2, body_color)

        else if _is_ended
            box.set_right(body, bar_index)
        

// ------------------------
// Rendering limit message
// ------------------------
f_render_limitmessage (_show, _session, _is_started, _is_ended, _x, _y, _rightbars) =>
    var label my_note = na

    if _show
        if _is_started
            if _rightbars > max_bars
                my_note := label.new(_x, _y, f_message_limit_bars(_rightbars), style=label.style_label_upper_left, color=color.yellow, textalign=text.align_left, yloc=yloc.price)

        else if _session
            if _rightbars > max_bars
                label.set_y(my_note, _y)
                label.set_text(my_note, f_message_limit_bars(_rightbars))
            else
                label.delete(my_note)

        else if _is_ended
            label.delete(my_note)
    true

// Rendering session
// 
f_render_sessionrange (_show, _session, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2, _is_extend, _lines) =>
    var line above_line = na
    var line below_line = na

    if _show
        if _is_started
            above_line := line.new(_x1, _top, _x2, _top, width=i_sess_border_width, style=i_sess_border_style, color=_color)
            below_line := line.new(_x1, _bottom, _x2, _bottom, width=i_sess_border_width, style=i_sess_border_style, color=_color)
            linefill.new(above_line, below_line, color.new(_color, i_sess_bgopacity))

            array.push(_lines, above_line)
            array.push(_lines, below_line)

            util.clear_lines(_lines, i_history_period * 2)

            if _is_extend
                line.set_extend(above_line, extend.right)
                line.set_extend(below_line, extend.right)

        else if _session
            line.set_y1(above_line, _top)
            line.set_y2(above_line, _top)
            line.set_x2(above_line, _x2)

            line.set_y1(below_line, _bottom)
            line.set_y2(below_line, _bottom)
            line.set_x2(below_line, _x2)
            true
        else if _is_ended

            true
    true

// ------------------------
// Rendering session box
// ------------------------
f_render_session (_show, _session, _is_started, _is_ended, _color, _top, _bottom, _x1, _x2, _is_extend, _boxes) =>
    var box my_box = na

    if _show
        if _is_started
            my_box := box.new(_x1, _top, _x2, _bottom, _color, i_sess_border_width, i_sess_border_style, bgcolor=color.new(_color, i_sess_bgopacity))
            array.push(_boxes, my_box)

            util.clear_boxes(_boxes, i_history_period)

            if _is_extend
                box.set_extend(my_box, extend.right)

        else if _session
            box.set_top(my_box, _top)
            box.set_bottom(my_box, _bottom)
            f_set_box_right(my_box, _x2)

        else if _is_ended
            box.set_right(my_box, bar_index)

    my_box


// ------------------------
// Drawing market
// ------------------------
f_render_main (_show, _session, _is_started, _is_ended, _color, _top, _bottom) =>
    var box my_box = na
    var label my_note = na
    var x1 = 0
    var x2 = 0
    var session_open  = 0.0
    var session_high  = 0.0
    var session_low   = 0.0

    x0_1 = ta.valuewhen(na(_session[1]) and _session, bar_index, 1)
    x0_2 = ta.valuewhen(na(_session) and _session[1], bar_index, 0)
    x0_d = math.abs(x0_2 - x0_1)
    limit_bars = max_bars
    rightbars = x0_d

    if _show
        if _is_started
            x1 := bar_index
            x2 := bar_index + (math.min(x0_d, limit_bars))

            session_open := open
            session_high := _top
            session_low  := _bottom

        else if _session
            true_x2         = x1 + x0_d
            rightbars      := true_x2 - bar_index
            limit_bars     := bar_index + max_bars

            x2 := math.min(true_x2, limit_bars)

            session_high := _top
            session_low  := _bottom
        
        else if _is_ended
            session_open := na

    [x1, x2, session_open, session_high, session_low, rightbars]

// ------------------------
// Drawing
// ------------------------
draw (_show, _session, _color, _label, _extend, _show_fib, _show_op, _lookback, _boxes_session, _lines_session, _boxes_candle_body, _lines_candle_wick, _boxes_op, _lines_fib, _labels) =>
    max = f_get_period(_session, 1, _lookback)
    top = ta.highest(high, max)
    bottom = ta.lowest(low, max)
    
    if i_osc
        top     := i_osc_max
        bottom  := i_osc_min
    
    is_started = f_get_started(_session)
    is_ended = f_get_ended(_session)
    is_extend = _extend != option_no

    [x1, x2, _open, _high, _low, _rightbars] = f_render_main(_show, _session, is_started, is_ended, _color, top, bottom)

    if i_sess_box_style == 'Box'
        f_render_session(_show, _session, is_started, is_ended, _color, top, bottom, x1, x2, is_extend, _boxes_session)

    if i_sess_box_style == 'Sandwich'
        f_render_sessionrange(_show, _session, is_started, is_ended, _color, top, bottom, x1, x2, is_extend, _lines_session)

    if i_show_candle
        f_render_candle(_show, _session, is_started, is_ended, _color, top, bottom, _open, x1, x2, _boxes_candle_body, _lines_candle_wick)

    if i_label_show
        f_render_label(_show, _session, is_started, _color, top, bottom, _label, _labels)

    if _show_op
        f_render_oprange(_show, _session, is_started, x1, x2, _color, max, is_extend, _boxes_op)

    if _show_fib
        f_render_fibonacci(_show, _session, is_started, x1, x2, _color, top, bottom, 0.500, 2, line.style_solid, is_extend, _lines_fib)
        f_render_fibonacci(_show, _session, is_started, x1, x2, _color, top, bottom, 0.628, i_f_linewidth, i_f_linestyle, is_extend, _lines_fib)
        f_render_fibonacci(_show, _session, is_started, x1, x2, _color, top, bottom, 0.382, i_f_linewidth, i_f_linestyle, is_extend, _lines_fib)
        util.clear_lines(_lines_fib, i_history_period * 3)
    
    f_render_limitmessage(_show, _session, is_started, is_ended, x1, bottom, _rightbars)

    [_session, _open, _high, _low]

///////////////////
// Calculating
///////////////////
string tz = (i_tz == option_no or i_tz == '') ? na : i_tz
int sess1 = time(timeframe.period, i_sess1, tz)
int sess2 = time(timeframe.period, i_sess2, tz)
int sess3 = time(timeframe.period, i_sess3, tz)
int sess4 = time(timeframe.period, i_sess4, tz)

///////////////////
// Plotting
///////////////////
var sess1_box           = array.new<box>()
var sess2_box           = array.new<box>()
var sess3_box           = array.new<box>()
var sess4_box           = array.new<box>()
var sess1_line          = array.new<line>()
var sess2_line          = array.new<line>()
var sess3_line          = array.new<line>()
var sess4_line          = array.new<line>()
var sess1_op            = array.new<box>()
var sess2_op            = array.new<box>()
var sess3_op            = array.new<box>()
var sess4_op            = array.new<box>()
var sess1_fib           = array.new<line>()
var sess2_fib           = array.new<line>()
var sess3_fib           = array.new<line>()
var sess4_fib           = array.new<line>()
var sess1_candle_body   = array.new<box>()
var sess2_candle_body   = array.new<box>()
var sess3_candle_body   = array.new<box>()
var sess4_candle_body   = array.new<box>()
var sess1_candle_wick   = array.new<line>()
var sess2_candle_wick   = array.new<line>()
var sess3_candle_wick   = array.new<line>()
var sess4_candle_wick   = array.new<line>()
var sess1_labels        = array.new<label>()
var sess2_labels        = array.new<label>()
var sess3_labels        = array.new<label>()
var sess4_labels        = array.new<label>()

[is_sess1, sess1_open, sess1_high, sess1_low] = draw(i_show_sess1, sess1, i_sess1_color, i_sess1_label, i_sess1_extend, i_sess1_fib, i_sess1_op, i_lookback, sess1_box, sess1_line, sess1_candle_body, sess1_candle_wick, sess1_op, sess1_fib, sess1_labels)
[is_sess2, sess2_open, sess2_high, sess2_low] = draw(i_show_sess2, sess2, i_sess2_color, i_sess2_label, i_sess2_extend, i_sess2_fib, i_sess2_op, i_lookback, sess2_box, sess2_line, sess2_candle_body, sess2_candle_wick, sess2_op, sess2_fib, sess2_labels)
[is_sess3, sess3_open, sess3_high, sess3_low] = draw(i_show_sess3, sess3, i_sess3_color, i_sess3_label, i_sess3_extend, i_sess3_fib, i_sess3_op, i_lookback, sess3_box, sess3_line, sess3_candle_body, sess3_candle_wick, sess3_op, sess3_fib, sess3_labels)
[is_sess4, sess4_open, sess4_high, sess4_low] = draw(i_show_sess4, sess4, i_sess4_color, i_sess4_label, i_sess4_extend, i_sess4_fib, i_sess4_op, i_lookback, sess4_box, sess4_line, sess4_candle_body, sess4_candle_wick, sess4_op, sess4_fib, sess4_labels)


////////////////////
// Alerts
////////////////////
// Session alerts
sess1_started = is_sess1 and not is_sess1[1], sess1_ended = not is_sess1 and is_sess1[1]
sess2_started = is_sess2 and not is_sess2[1], sess2_ended = not is_sess2 and is_sess2[1]
sess3_started = is_sess3 and not is_sess3[1], sess3_ended = not is_sess3 and is_sess3[1]
sess4_started = is_sess4 and not is_sess4[1], sess4_ended = not is_sess4 and is_sess4[1]

alertcondition(sess1_started,   'Session #1 started')
alertcondition(sess1_ended,     'Session #1 ended')
alertcondition(sess2_started,   'Session #2 started')
alertcondition(sess2_ended,     'Session #2 ended')
alertcondition(sess3_started,   'Session #3 started')
alertcondition(sess3_ended,     'Session #3 ended')
alertcondition(sess4_started,   'Session #4 started')
alertcondition(sess4_ended,     'Session #4 ended')

alertcondition((not is_sess1) and ta.crossover(close, sess1_high), 'Session #1 High crossed (after session closed)')
alertcondition((not is_sess1) and ta.crossunder(close, sess1_low), 'Session #1 Low crossed (after session closed)')
alertcondition((not is_sess2) and ta.crossover(close, sess2_high), 'Session #2 High crossed (after session closed)')
alertcondition((not is_sess2) and ta.crossunder(close, sess2_low), 'Session #2 Low crossed (after session closed)')
alertcondition((not is_sess3) and ta.crossover(close, sess3_high), 'Session #3 High crossed (after session closed)')
alertcondition((not is_sess3) and ta.crossunder(close, sess3_low), 'Session #3 Low crossed (after session closed)')
alertcondition((not is_sess4) and ta.crossover(close, sess4_high), 'Session #4 High crossed (after session closed)')
alertcondition((not is_sess4) and ta.crossunder(close, sess4_low), 'Session #4 Low crossed (after session closed)')

// Alerts visualized
plotshape(sess1_started, 'sess1_started', color=i_sess1_color, text='Start', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess1_ended, 'sess1_ended', color=i_sess1_color, text='End', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess2_started, 'sess2_started', color=i_sess2_color, text='Start', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess2_ended, 'sess2_ended', color=i_sess2_color, text='End', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess3_started, 'sess3_started', color=i_sess3_color, text='Start', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess3_ended, 'sess3_ended', color=i_sess3_color, text='End', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess4_started, 'sess4_started', color=i_sess4_color, text='Start', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)
plotshape(sess4_ended, 'sess4_ended', color=i_sess4_color, text='End', style=shape.labeldown, location=location.bottom, size=size.small, textcolor=color.new(color.white, 0), display=display.none)

plot(sess1_high, 'sess1_high', style=plot.style_linebr, color=i_sess1_color, display=display.none)
plot(sess1_low, 'sess1_low', style=plot.style_linebr, linewidth=2, color=i_sess1_color, display=display.none)
plot(sess2_high, 'sess2_high', style=plot.style_linebr, color=i_sess2_color, display=display.none)
plot(sess2_low, 'sess2_low', style=plot.style_linebr, linewidth=2, color=i_sess2_color, display=display.none)
plot(sess3_high, 'sess3_high', style=plot.style_linebr, color=i_sess3_color, display=display.none)
plot(sess3_low, 'sess3_low', style=plot.style_linebr, linewidth=2, color=i_sess3_color, display=display.none)
plot(sess4_high, 'sess4_high', style=plot.style_linebr, color=i_sess4_color, display=display.none)
plot(sess4_low, 'sess4_low', style=plot.style_linebr, linewidth=2, color=i_sess4_color, display=display.none)

plotshape((not is_sess1) and ta.crossover(close, sess1_high), 'cross sess1_high', color=i_sess1_color, style=shape.triangleup, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess1) and ta.crossunder(close, sess1_low), 'cross sess1_low', color=i_sess1_color, style=shape.triangledown, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess2) and ta.crossover(close, sess2_high), 'cross sess2_high', color=i_sess2_color, style=shape.triangleup, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess2) and ta.crossunder(close, sess2_low), 'cross sess2_low', color=i_sess2_color, style=shape.triangledown, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess3) and ta.crossover(close, sess3_high), 'cross sess3_high', color=i_sess3_color, style=shape.triangleup, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess3) and ta.crossunder(close, sess3_low), 'cross sess3_low', color=i_sess3_color, style=shape.triangledown, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess4) and ta.crossover(close, sess4_high), 'cross sess3_high', color=i_sess4_color, style=shape.triangleup, location=location.bottom, size=size.tiny, display=display.none)
plotshape((not is_sess4) and ta.crossunder(close, sess4_low), 'cross sess3_low', color=i_sess4_color, style=shape.triangledown, location=location.bottom, size=size.tiny, display=display.none)

Overview

Each session uses a chosen timezone and clock range and can show a colored session range, an optional extension, Fibonacci levels, and an opening range. History controls how many past sessions remain visible. Labels can sit at the top or bottom, including a day option. Alerts fire after a session ends if price breaks that session high or low. Boxes that extend beyond 500 bars are not drawn correctly.

Details

Published by

itmakesyousick on GitHub

Code credit

boitoki, as written in the script's header

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Sessions & time, Support & resistance

Markets

Forex

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

pinescript

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
TimezonestringGMT+1i_tz
Historyint3i_history_period
Session 1: booltruei_show_sess1
stringLondoni_sess1_label
color#66D9EFi_sess1_color
Timesession0800-1700i_sess1
Extendstringoption_noi_sess1_extend
Fibonacci levelsstringoption_noi_sess1_fib
Opening rangestringoption_noi_sess1_op
Session 2: booltruei_show_sess2
stringNew Yorki_sess2_label
color#FD971Fi_sess2_color
Show all 40 settings
SettingTypeDefaultVariable
Timesession1300-2200i_sess2
Extendstringoption_noi_sess2_extend
Fibonacci levelsstringoption_noi_sess2_fib
Opening rangestringoption_noi_sess2_op
Session 3: booltruei_show_sess3
stringTokyoi_sess3_label
color#AE81FFi_sess3_color
Timesession0100-1000i_sess3
Extendstringoption_noi_sess3_extend
Fibonacci levelsstringoption_noi_sess3_fib
Opening rangestringoption_noi_sess3_op
Session 4: booltruei_show_sess4
stringSydneyi_sess4_label
color#FB71A3i_sess4_color
Timesession2200-0700i_sess4
Extendstringoption_noi_sess4_extend
Fibonacci levelsstringoption_noi_sess4_fib
Opening rangestringoption_noi_sess4_op
StylestringBoxi_sess_box_style
Line stylestringline.style_dashedi_sess_border_style
Thicknessint1i_sess_border_width
Transpint94i_sess_bgopacity
Displaystringoption_hidei_candle
Thicknessint2i_candle_border_width
Candle colorstringoption_candle_color2i_candle_color
i_candle_color_gcolor#A6E22Ei_candle_color_g
i_candle_color_rcolor#F92672i_candle_color_r
Show labelsbooltruei_label_show
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

575 stars

This indicator builds Market Profile Time Price Opportunity (TPO) structures across defined session timeframes directly on the main price chart. It visualizes the Point of Control (POC) and Value Area boundaries using dynamic box drawings. An integrated multi-

Indicator v5 Support & resistanceScreeners & dashboards
Updated 1 year ago Β· MPL-2.0 GitHub repository of Market Profile with Screener
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago Β· None stated GitHub repository of Auto Trade Futures ES

Golden Bullet Strategy

by TradersPost
218 stars

The Golden Bullet Strategy is an overlay signal indicator based on Smart Money Concepts and time-based liquidity models. It identifies liquidity sweeps of a designated reference session range during a specified hunt window. It then confirms Market Structure Sh

Indicator v6 SMC / ICT / price actionSessions & time
Updated 3 months ago Β· None stated GitHub repository of Golden Bullet Strategy

Moon Dev GEX Arrows

by moondevonyt
92 stars

This overlay indicator plots option strike walls and an optional session VWAP on the price chart for SPY or ES. It spaces major strikes by the selected instrument, draws a set number of strikes on each side, and marks wall-trap and sweep events after a cooldow

Indicator v5 Support & resistanceSessions & time
Updated 8 weeks ago Β· Custom licence GitHub repository of Moon Dev GEX Arrows

Key Levels

by cryptorife
75 stars

This indicator plots reference levels and session markers directly on the price chart. It calculates and draws lines for the daily open, weekly open, monthly open, previous day OHLC, and previous week extremes, along with a selectable day-of-week range and ini

Indicator v4 Support & resistanceSessions & time Repaints
Updated 3 years ago Β· GPL-3.0 GitHub repository of Key Levels

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers