Futures Exchange Sessions

Delineates Future Sessions (Asian, London, NY) start and end times

TradingView Link

Add this useful indicator to your TradingView chart with the link below. Always free and open source!

  • Before going to TradingView check out the description and screenshots below
TradingView Link

Futures Exchange Sessions

This TradingView indicator is used to help the user keep track of the worldwide futures market opens & closes in a 24-hour trading day. The indicator also beautifully displays transparent backgrounds over time spans for sessions, killzones, and lunches so the user is never caught off guard in a futures trading day. And finally this indicator plots the last trading days highs & lows as lines so the user can visually see runs on liquidity.

In the 24-hour trading of the futures market, this indicator provides the user with full customization concerning the most important factor: time. This indicator is centered around three main visualizations: labels, backgrounds, and lines that minimalistically allows the user to keep track of the many time intervals that occur during a futures market 24-hour trading cycle. It also artfully displays the previous days highs and lows. And everything can be individually toggled and configured so the user can get exactly what they want.

Labels

There are three main futures market sessions in a 24-hour period: the London, New York, and Asian Sessions. Each session is given an independent label for the open and close times. The six labels (LO, LC , NYO, NYC, AO, AC ) can be individually toggled on or off, the label background color changed, the text switched between black or white, and the height can be lowered or raised. These customizations are intended to give the user full control of the session they are interested in at the moment.

Backgrounds

Backgrounds are the heart of this indicator. There are different colored transparent backgrounds for each of the futures sessions. So the user can clearly see the session they want to highlight without cluttering their chart and getting in the way of analyzing the candles.

If you are familiar with the London and New York killzones, these backgrounds are each individually configured.

If you are familiar with the Inner Circle Trader’s (ICT) NY Morning and Afternoon sessions, these are available. Also, most times weird price action occurs during the lunch hour of these sessions. The London and New York have a background for their respective lunch hours so the user is never caught of guard during these periods.

Lines

The markets are constantly looking for liquidity. To help the user see runs on liquidity, this indicator projects the previous days highs and lows on to the current day with a line and a price label. The line make it very easy to see where price may be headed. See the image below for the perfect example of this phenomenon. Each of the lines can be independently controlled by color, style, and width. And even the labels can be toggled on or off if the user would prefer just to see the lines. Lastly, there is a line that marks the midnight open price in EST.

Special Notes

  • This indicator is specifically designed for futures tickers.
  • All of the backgrounds are not designed to be turned on a once (there are many that overlap). They are designed to give the user ultimate control over exactly what timeframe backgrounds to display on their charts.
  • The labels only appear when timeframe is 1 hour or less.

Update 1

More comprehensive control of indicator features:

  • Ability to display last X days of transparent backgrounds & labels
  • Capability to move line labels to the right to prevent labels from covering up candles
  • Midnight Open EST label can now be toggled on/off
  • Reworded Settings Inputs descriptions to make them more clear
  • Added tooltips to some of the more advanced Setting Inputs to explain particular behaviors
  • Increased the number of labels displayed on a chart to the max allowable by TradingView (500)

Update 2

  • Added 8:30 AM EST Open line
  • Can now change label text color of horizontal lines
  • Input Settings adjustments

Code

// © Infinity_Trading_
// Last Modified: 5/2/2022

//@version=5
indicator(title="Futures Exchange Sessions", shorttitle="_Sessions", overlay=true, max_labels_count=500)

// Purpose: In the 24-hour trading of the futures market, this indicator provides the user with full customization concerning the most important factor: time.
//          This indicator is centered around three main visualizations: labels, backgrounds, and lines for
//          the three main futures market sessions in a 24-hour period: the London, New York, and Asian Sessions.


// Usage: Using the Input Settings toggle on or off any background, label, or line. The user can control the color of every background.
//        Also, every label can be configured by color, text color, and heighth. Finally, each line can be specified by color, wideth, and style.
//        Now, users can limit backgrounds and labels to most recent days back. And the line labels can be optionally shifted right to prevent the candles from blocking the candles.

// Labels only appear when timeframe is 1 hour or less


///////////////////////////////////////////////////////////////////////////////// INPUTS

i_label_multiplier = input.float(defval=1.5, minval=0.5, title="Label Open/Close Vertical Movement")
c_tooltip_1 = "'Limited Time' choice can sometimes paint background slivers of time for the previous day. This is purely a function of time. The algorithm for Days Back is divided by 24-hour periods, which depending on the time of day, can paint background slivers. The indicator is NOT broken."
i_show_all_time = input.string(defval="All-time", title="Display Previous Backgrounds & Labels", options=["All-time", "Limited Time"], tooltip=c_tooltip_1) == "All-time"
c_tooltip_2 = "If the user increments/decrements this integer field and nothing happens, that is because the user is moving throught a weekend or holiday. Please continue incrementing/decrementing and after 2-3 clicks the user will see backgrounds/labels appear or disappear. The algorithm for Days Back is counting every 24-hour period which is why this behavior occurs."
i_display_days_back = input.int(defval=3, minval=1, title="    ↪ Display Only 🔢 Days Back", tooltip=c_tooltip_2)


//------------------------------------
// LONDON
//------------------------------------

var string LONDON = "London Session"

i_london_open_label = input.bool(defval=false, title="London Open Label", group=LONDON, inline="london_open")
i_london_open_color = input.color(defval=color.rgb(16, 172, 132, 0), title="", group=LONDON, inline="london_open") // Dark Mountain Meadow = 16, 172, 132
i_london_open_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=LONDON, inline="london_open")

i_london_close_label = input.bool(defval=false, title="London Close Label", group=LONDON, inline="london_close")
i_london_close_color = input.color(defval=color.rgb(238, 82, 83, 0), title="", group=LONDON, inline="london_close") // Amour = 238, 82, 83
i_london_close_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=LONDON, inline="london_close")

i_london_session = input.bool(defval=false, title="London Session", group=LONDON, inline="london_session")
i_london_session_color = input.color(defval=color.rgb(251, 197, 49, 80), title="", group=LONDON, inline="london_session") // Rise-n-shine rgb(251, 197, 49)

i_london_open_kz = input.bool(defval=false, title="London Open Killzone Background", group=LONDON, inline="london_open_kz")
i_london_open_kz_color = input.color(defval=color.rgb(46, 134, 222, 80), title="", group=LONDON, inline="london_open_kz")

i_london_close_kz = input.bool(defval=false, title="London Close Killzone Background", group=LONDON, inline="london_close_kz")
i_london_close_kz_color = input.color(defval=color.rgb(46, 134, 222, 80), title="", group=LONDON, inline="london_close_kz")

i_london_lunch = input.bool(defval=false, title="London Lunch", group=LONDON, inline="london_lunch")
i_london_lunch_color = input.color(defval=color.rgb(131, 149, 167, 80), title="", group=LONDON, inline="london_lunch")


//------------------------------------
// NEW YORK
//------------------------------------

var string NEW_YORK = "New York Session"

i_new_york_open_label = input.bool(defval=false, title="New York Open Label", group=NEW_YORK, inline="new_york_open")
i_new_york_open_color = input.color(defval=color.rgb(16, 172, 132, 0), title="", group=NEW_YORK, inline="new_york_open") // Dark Mountain Meadow = 16, 172, 132
i_new_york_open_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=NEW_YORK, inline="new_york_open")

i_new_york_close_label = input.bool(defval=false, title="New York Close Label", group=NEW_YORK, inline="new_york_close")
i_new_york_close_color = input.color(defval=color.rgb(238, 82, 83, 0), title="", group=NEW_YORK, inline="new_york_close") // Amour = 238, 82, 83
i_new_york_close_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=NEW_YORK, inline="new_york_close")

i_new_york_session = input.bool(defval=false, title="New York Session", group=NEW_YORK, inline="ny_session")
i_new_york_session_color = input.color(defval=color.rgb(223, 230, 233, 80), title="", group=NEW_YORK, inline="ny_session") // City Lights rgb(223, 230, 233)

i_new_york_open_kz = input.bool(defval=false, title="New York Open Killzone Background", group=NEW_YORK, inline="ny_open_kz")
i_new_york_open_kz_color = input.color(defval=color.rgb(46, 134, 222, 80), title="", group=NEW_YORK, inline="ny_open_kz")



i_ny_ict_morning = input.bool(defval=false, title="ICT's Morning Session Background", group=NEW_YORK, inline="ict_morning")
i_ny_ict_morning_color = input.color(defval=color.rgb(46, 134, 222, 80), title="", group=NEW_YORK, inline="ict_morning")

i_ny_ict_afternoon = input.bool(defval=false, title="ICT's Afternoon Session Background", group=NEW_YORK, inline="ict_afternoon")
i_ny_ict_afternoon_color = input.color(defval=color.rgb(46, 134, 222, 80), title="", group=NEW_YORK, inline="ict_afternoon")

i_new_york_lunch = input.bool(defval=false, title="New York Lunch", group=NEW_YORK, inline="ny_lunch")
i_new_york_lunch_color = input.color(defval=color.rgb(131, 149, 167, 80), title="", group=NEW_YORK, inline="ny_lunch")


//------------------------------------
// ASIAN
//------------------------------------

var string ASIAN = "Asian Session"

i_asian_open_label = input.bool(defval=false, title="Asian Open Label", group=ASIAN, inline="asian_open")
i_asian_open_color = input.color(defval=color.rgb(16, 172, 132, 0), title="", group=ASIAN, inline="asian_open") // Dark Mountain Meadow = 16, 172, 132
i_asian_open_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=ASIAN, inline="asian_open")

i_asian_close_label = input.bool(defval=false, title="Asian Close Label", group=ASIAN, inline="asian_close")
i_asian_close_color = input.color(defval=color.rgb(238, 82, 83, 0), title="", group=ASIAN, inline="asian_close") // Amour = 238, 82, 83
i_asian_close_textcolor = input.string(defval="Black", title=" Text Color", options=["Black", "White"], group=ASIAN, inline="asian_close")

i_asian_session = input.bool(defval=false, title="Asian Session", group=ASIAN, inline="asian_session")
i_asian_session_color = input.color(defval=color.rgb(255, 107, 129, 80), title="", group=ASIAN, inline="asian_session") // Wild Watermelon rgb(255, 107, 129)

//------------------------------------
// LINES
//------------------------------------

var string GPL = "Lines"
i_line_label_toggle = input.bool(defval=false, title=" Labels On/Off", group=GPL, inline="line_labels")
c_tooltip_right_mov = "If the futures market is closed (every weekend & 5:00-6:00 pm EST weekdays) then the label right movement setting won't have any visible impact. Please wait for the market to open again and the right movement setting will resume. The reason the label doesn't move right during market closed hours is because the chart is removing those hours and thus something cannot be displayed during those times."
i_labels_right_mov = input.int(defval=0, title="➕ Right Movement", group=GPL, inline="line_labels", tooltip=c_tooltip_right_mov)


i_prev_days_high_toggle = input.bool(defval=false, title="", group=GPL, inline="prev_high")
i_prev_days_high_line_color = input.color(defval=color.new(#0984e3, 0), title=" Previous Days High", group=GPL, inline="prev_high") // electron blue
i_prev_days_high_line_style = input.string(defval="solid (─)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GPL, inline="prev_high")
i_prev_days_high_line_width = input.int(defval=2, title="   ", minval=1, maxval=20, group=GPL, inline="prev_high2")
i_prev_days_high_text_color = input.string(defval="Black", title="", options=["Black", "White"], group=GPL, inline="prev_high2")

i_prev_days_low_toggle = input.bool(defval=false, title="", group=GPL, inline="prev_low")
i_prev_days_low_line_color = input.color(defval=color.new(#ff793f, 0), title=" Previous Days Low", group=GPL, inline="prev_low") // synthetic pumpkin
i_prev_days_low_line_style = input.string(defval="solid (─)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GPL, inline="prev_low")
i_prev_days_low_line_width = input.int(defval=2, title="   ", minval=1, maxval=20, group=GPL, inline="prev_low2")
i_prev_days_low_text_color = input.string(defval="Black", title="", options=["Black", "White"], group=GPL, inline="prev_low2")

i_midnight_toggle = input.bool(defval=false, title="", group=GPL, inline="midnight")
i_midnight_line_color = input.color(defval=color.new(#131722, 0), title=" Midnight EST Open", group=GPL, inline="midnight") // off black
i_midnight_line_style = input.string(defval="dashed (╌)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GPL, inline="midnight")
i_midnight_line_width = input.int(defval=2, title="   ", minval=1, maxval=20, group=GPL, inline="midnight2")
i_midnight_text_color = input.string(defval="White", title="", options=["Black", "White"], group=GPL, inline="midnight2")

i_eight_thirty_toggle = input.bool(defval=false, title="", group=GPL, inline="eight_thirty")
i_eight_thirty_line_color = input.color(defval=color.new(#747d8c, 0), title=" 8:30 AM EST Open", group=GPL, inline="eight_thirty") // bay wharf
i_eight_thirty_line_style = input.string(defval="dashed (╌)", title="", options=["solid (─)", "dotted (┈)", "dashed (╌)"], group=GPL, inline="eight_thirty")
i_eight_thirty_line_width = input.int(defval=2, title="   ", minval=1, maxval=20, group=GPL, inline="eight_thirty2")
i_eight_thirty_text_color = input.string(defval="Black", title="", options=["Black", "White"], group=GPL, inline="eight_thirty2")


//------------------------------------
// CONTANTS
//------------------------------------

c_length = 20
c_mov_avg_function = "SMA"


c_london_open_time_est  = '0300-0301'
c_london_close_time_est = '1130-1131'
c_ny_open_time_est      = '0930-0931'
c_ny_close_time_est     = '1600-1601'
c_asia_open_time_est    = '1900-1901'
c_asia_close_time_est   = '0300-0301'

c_asian_session_est     = '1900-0259'
c_london_session_est    = '0300-1129'
c_new_york_session_est  = '0930-1559'

c_minutes_futures_trading_day = 1380
c_seconds_futures_trading_day = 82800
c_milliseconds_in_day = 24 * 60 * 60 * 1000

//------------------------------------
// NON-CONTANTS (VARIABLES)
//------------------------------------

// v_periods_futures_trading_day = c_minutes_futures_trading_day / timeframe.multiplier
// v_days_to_bars_back = i_background_days_back * v_periods_futures_trading_day


///////////////////////////////////////////////////////////////////////////////// DAYS BACK

// https://stackoverflow.com/a/61609961
lastBarDate = timestamp(year(timenow), month(timenow), dayofmonth(timenow), hour(timenow), minute(timenow), second(timenow))
thisBarDate = timestamp(year, month, dayofmonth, hour, minute, second)
daysLeft = math.floor((lastBarDate - thisBarDate) / c_milliseconds_in_day)
in_days_back_range = daysLeft < i_display_days_back



///////////////////////////////////////////////////////////////////////////////// HELPER FUNCTIONS

// Moving average helper function
ma_function(source, length) =>
	switch c_mov_avg_function
		"RMA" => ta.rma(source, length)
		"SMA" => ta.sma(source, length)
		"EMA" => ta.ema(source, length)
		=> ta.wma(source, length)


// Function the converts string inputs to line style code
line_style_function(input_var) =>
    switch input_var
        "dotted (┈)" => line.style_dotted
        "dashed (╌)" => line.style_dashed
        => line.style_solid

// Function that converts the words black/white to their code equivalents
text_color_function(string_color) =>
    switch string_color
        "Black" => color.black
        "White" => color.white
        => color.black


// Function that conditionally returns color based upon certain setting inputs
custom_background_color_function(show_all, back, t1, t2, return_color) =>
    if show_all
        if t1 and t2 > 0
            return_color
        else
            na
    else
        if back and t1 and t2 > 0
            return_color
        else
            na

// Functions for Security calls to get time or price on the number of periods back specified
timePeriod(tf, period) => request.security(syminfo.tickerid, tf, time[period])
highPeriod(tf, period) => request.security(syminfo.tickerid, tf, high[period])
lowPeriod(tf, period) => request.security(syminfo.tickerid, tf, low[period])
openPeriod(tf, period) => request.security(syminfo.tickerid, tf, open[period])

///////////////////////////////////////////////////////////////////////////////// Average True Range

// Use different moving average functions to calculate ATR
_atr = ma_function(ta.tr(true), c_length)


///////////////////////////////////////////////////////////////////////////////// LABELS


//------------------------------------
// LONDON SESSION
//------------------------------------

label label_london_open = na
label label_london_close = na

london_open_textcolor = text_color_function(i_london_open_textcolor)
london_close_textcolor = text_color_function(i_london_close_textcolor)

if timeframe.isminutes and timeframe.multiplier <= 60
    if i_london_open_label
        label_london_open := label.new(x=time(timeframe.period, c_london_open_time_est, "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="LO", style=label.style_label_down, color=i_london_open_color, textcolor=london_open_textcolor, tooltip="London Open")

    if i_london_close_label
        if timeframe.isminutes and timeframe.multiplier == 60
            label_london_close := label.new(x=time(timeframe.period, '1100-1101', "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="LC", style=label.style_label_down, color=i_london_close_color, textcolor=london_close_textcolor, tooltip="London Close")
        else
            label_london_close := label.new(x=time(timeframe.period, c_london_close_time_est, "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="LC", style=label.style_label_down, color=i_london_close_color, textcolor=london_close_textcolor, tooltip="London Close")

//------------------------------------
// NEW YORK SESSION
//------------------------------------

label label_new_york_open = na
label label_new_york_close = na

new_york_open_textcolor = text_color_function(i_new_york_open_textcolor)
new_york_close_textcolor = text_color_function(i_new_york_close_textcolor)

if timeframe.isminutes and timeframe.multiplier <= 60
    if i_new_york_open_label
        if timeframe.isminutes and timeframe.multiplier == 60
            label_new_york_open := label.new(x=time(timeframe.period, '0900-0901', "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="NYO", style=label.style_label_down, color=i_new_york_open_color, textcolor=new_york_open_textcolor, tooltip="New York Open")
        else
            label_new_york_open := label.new(x=time(timeframe.period, c_ny_open_time_est, "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="NYO", style=label.style_label_down, color=i_new_york_open_color, textcolor=new_york_open_textcolor, tooltip="New York Open")

    if i_new_york_close_label
        label_new_york_close := label.new(x=time(timeframe.period, c_ny_close_time_est, "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="NYC", style=label.style_label_down, color=i_new_york_close_color, textcolor=new_york_close_textcolor, tooltip="New York Close")

//------------------------------------
// ASIAN SESSION
//------------------------------------

label label_asian_open = na
label label_asian_close = na

asian_open_textcolor = text_color_function(i_asian_open_textcolor)
asian_close_textcolor = text_color_function(i_asian_close_textcolor)

if timeframe.isminutes and timeframe.multiplier <= 60
    if i_asian_open_label
        label_asian_open := label.new(x=time(timeframe.period, c_asia_open_time_est, "America/New_York"), y=high + _atr * i_label_multiplier, xloc=xloc.bar_time, text="AO", style=label.style_label_down, color=i_asian_open_color, textcolor=asian_open_textcolor, tooltip="Asian Open")
    if i_asian_close_label
        label_asian_close := label.new(x=time(timeframe.period, c_asia_close_time_est, "America/New_York"), y=high + _atr * i_label_multiplier * 3, xloc=xloc.bar_time, text="AC", style=label.style_label_down, color=i_asian_close_color, textcolor=asian_close_textcolor, tooltip="Asian Close")


//------------------------------------
// CONDITIONALLY DELETE LABELS
//------------------------------------

// Delete Session Open & Close labels if input is set to "Limited Time" and the day is priot to the x days back input
if i_show_all_time == false and in_days_back_range == false
    label.delete(label_london_open)
    label.delete(label_london_close)
    label.delete(label_new_york_open)
    label.delete(label_new_york_close)
    label.delete(label_asian_open)
    label.delete(label_asian_close)


///////////////////////////////////////////////////////////////////////////////// ASIAN BACKGROUNDS

// Default values
float asian_session = 0

if timeframe.isminutes and timeframe.multiplier <= 15
    asian_session := time(timeframe.period, c_asian_session_est, "America/New_York")

// Conditionally create vertical transparent backgrounds
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_asian_session, asian_session, i_asian_session_color), title="Asian Session")


///////////////////////////////////////////////////////////////////////////////// LONDON BACKGROUNDS

// Default values
float london_session = 0
float london_open_killzone = 0
float london_close_killzone = 0
float london_lunch = 0


if timeframe.isminutes and timeframe.multiplier <= 15

    london_session := time(timeframe.period, c_london_session_est, "America/New_York")
    london_open_killzone := time(timeframe.period, '0200-0359', "America/New_York")
    london_close_killzone := time(timeframe.period, '1000-1159', "America/New_York")
    london_lunch := time(timeframe.period, '0500-0559', "America/New_York")

// Conditionally create vertical transparent backgrounds
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_london_session, london_session, i_london_session_color), title="London Session")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_london_open_kz, london_open_killzone, i_london_open_kz_color), title="London Open Killzone")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_london_close_kz, london_close_killzone, i_london_close_kz_color), title="London Close Killzone")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_london_lunch, london_lunch, i_london_lunch_color), title="London Lunch")


///////////////////////////////////////////////////////////////////////////////// NEW YORK BACKGROUNDS

// Default values
float ny_york_session = 0
float ny_open_killzone = 0
float ict_morning = 0
float ict_afternoon = 0
float ny_lunch = 0

if timeframe.isminutes and timeframe.multiplier <= 15

    ny_york_session := time(timeframe.period, c_new_york_session_est, "America/New_York")
    ny_open_killzone := time(timeframe.period, '0700-0859', "America/New_York")
    ict_morning := time(timeframe.period, '0830-1159', "America/New_York")
    ict_afternoon := time(timeframe.period, '1300-1629', "America/New_York")
    ny_lunch := time(timeframe.period, '1200-1259', "America/New_York")

// Conditionally create vertical transparent backgrounds
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_new_york_session, ny_york_session, i_new_york_session_color), title="New York Session")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_new_york_open_kz, ny_open_killzone, i_new_york_open_kz_color), title="INew York Open Killzone")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_ny_ict_morning, ict_morning, i_ny_ict_morning_color), title="ICT's Morning Session")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_ny_ict_afternoon, ict_afternoon, i_ny_ict_afternoon_color), title="ICT's Afternoon Session")
bgcolor(custom_background_color_function(i_show_all_time, in_days_back_range, i_new_york_lunch, ny_lunch, i_new_york_lunch_color), title="New York Lunch")

///////////////////////////////////////////////////////////////////////////////// PREVIOUS DAYS HIGH & LOW LINES

// Move timebased labels right
dt = time + i_labels_right_mov * (time - time[1])


// Get last three daily highs, lows, and time periods
// Execute functions on global scope to prevent missing data
// https://stackoverflow.com/a/68261889
yestStart = timePeriod("D", 1)
yestHigh = highPeriod("D", 1)
yestLow = lowPeriod("D", 1)


// Line style variables
line_style_prev_high = line_style_function(i_prev_days_high_line_style)
line_style_prev_low = line_style_function(i_prev_days_low_line_style)
prev_days_high_text_color = text_color_function(i_prev_days_high_text_color)
prev_days_low_text_color = text_color_function(i_prev_days_low_text_color)


// Display daily previous days high as a line on intraday charts
label prev_days_high_label = na
if i_prev_days_high_toggle
    if timeframe.isintraday and barstate.islast
        line.new(x1=yestStart, y1=yestHigh, x2=time, y2=yestHigh, xloc=xloc.bar_time, color=i_prev_days_high_line_color, style=line_style_prev_high, width=i_prev_days_high_line_width)
        if i_line_label_toggle
            prev_days_high_label := label.new(x=dt, y=yestHigh, text=str.tostring(yestHigh), xloc=xloc.bar_time, color=i_prev_days_high_line_color, textcolor=prev_days_high_text_color, tooltip="Prev. Days High")
            label.delete(prev_days_high_label[1])

// Display daily previous days lows as a line on intraday charts
label prev_days_low_label = na
if i_prev_days_low_toggle
    if timeframe.isintraday and barstate.islast
        line.new(x1=yestStart, y1=yestLow, x2=time, y2=yestLow, xloc=xloc.bar_time, color=i_prev_days_low_line_color, style=line_style_prev_low, width=i_prev_days_low_line_width)
        if i_line_label_toggle
            prev_days_low_label := label.new(x=dt, y=yestLow, text=str.tostring(yestLow), xloc=xloc.bar_time, color=i_prev_days_low_line_color, textcolor=prev_days_low_text_color, tooltip="Prev. Days Low")
            label.delete(prev_days_low_label[1])


///////////////////////////////////////////////////////////////////////////////// MIDNIGHT OPEN LINE

line_style_midnight_open = line_style_function(i_midnight_line_style)
midnight_text_color = text_color_function(i_midnight_text_color)

// https://stackoverflow.com/questions/70419376/pine-script-draw-horizontal-line-for-open-price-at-a-certain-local-time
_d = 1  // Day 1
_h = 0  // Hour: 20
_m = 0  // Minute: 0
inWindow = (hour(time, "America/New_York") == _h) and (minute(time) == _m)

var line line_midnight = na
var label label_midnight = na

// Draw line starting at the midnight open EST candle
if i_midnight_toggle
    if (inWindow)
        line_midnight := line.new(x1=bar_index, y1=open, x2=bar_index + 1, extend=extend.right, y2=open, color=i_midnight_line_color, style=line_style_midnight_open, width=i_midnight_line_width)
        line.delete(line_midnight[1])

    // Draw label at midnight open EST candle
    if i_line_label_toggle and barstate.islast
        price_midnight_line = line.get_price(line_midnight, bar_index)
        label_midnight := label.new(x=dt, y=price_midnight_line, text=str.tostring(price_midnight_line), xloc=xloc.bar_time, color=i_midnight_line_color, textcolor=midnight_text_color, tooltip="Midnight Open Price EST")
        label.delete(label_midnight[1])

///////////////////////////////////////////////////////////////////////////////// 8:30 AM EST OPEN

line_style_eith_thirty_open = line_style_function(i_eight_thirty_line_style)
eight_thirty_text_color = text_color_function(i_eight_thirty_text_color)

// True when candle is 8:30 AM EST
eight_thirty_window = (hour(time, "America/New_York") == 8) and (minute(time) == 30)

var line line_eight_thirty = na
var label label_eight_thrity = na

// Draw line starting at the midnight open EST candle
if i_eight_thirty_toggle
    if (eight_thirty_window)
        line_eight_thirty := line.new(x1=bar_index, y1=open, x2=bar_index + 1, extend=extend.right, y2=open, color=i_eight_thirty_line_color, style=line_style_eith_thirty_open, width=i_eight_thirty_line_width)
        line.delete(line_eight_thirty[1])

    // Draw label at midnight open EST candle
    if i_line_label_toggle and barstate.islast
        price_eight_thirty_line = line.get_price(line_eight_thirty, bar_index)
        label_eight_thrity := label.new(x=dt, y=price_eight_thirty_line, text=str.tostring(price_eight_thirty_line), xloc=xloc.bar_time, color=i_eight_thirty_line_color, textcolor=eight_thirty_text_color, tooltip="8:30 AM EST Open Price")
        label.delete(label_eight_thrity[1])


/////////////////////////////////////////////////////////////////////////////////

You May Also Like

essential