Indicator · Pine Script v5 · On the chart

Market Sessions

by benso87

This indicator highlights major regional trading sessions directly on the price chart, including Asia, Europe, and America.

View on GitHub

GitHub stars24on the repository
Pine versionv5runs as is
Lines of code108
Settings20inputs
LicenceMPL-2.0
Last update4 years ago5 Oct 2022

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

108 lines of Pine Script v5 from Market Sessions.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

Market Sessions.pine
//@version=5
//
// Author: benso87
// benso87.com
//
//
indicator('Market Sessions', shorttitle='Markets', overlay=true, precision=2, max_bars_back=500)


////////////////////////////////////////////////////////////
// Inputs

// Plot Ahead
plotEarly = input.bool(true, title='Show sessions 1 day in advance', group='Plot Ahead')

// Weekends
useWknd = input.bool(false, title='Include weekends?', group='Weekends')

// Asia
showAsia = input.bool(true, title='Show Asia', group='Asia')
startAsiaH = input.int  (23, title='Start (UTC)', minval=0, maxval=23, group='Asia', inline='start')
startAsiaM = input.int  (0, title=':', minval=0, maxval=59, group='Asia', inline='start')
stopAsiaH  = input.int  (8, title='Stop (UTC)', minval=0, maxval=23, group='Asia', inline='stop')
stopAsiaM  = input.int  (0, title=':', minval=0, maxval=59, group='Asia', inline='stop')
colorAsia = input.color(color.new(color.red, transp=90), title='Color', group='Asia', inline='color')

// Europe
showEurope = input.bool(true, title='Show Europe', group='Europe')
startEuropeH = input.int  (7, title='Start (UTC)', minval=0, maxval=23, group='Europe', inline='start')
startEuropeM = input.int  (0, title=':', minval=0, maxval=59, group='Europe', inline='start')
stopEuropeH  = input.int  (16, title='Stop (UTC)', minval=0, maxval=23, group='Europe', inline='stop')
stopEuropeM  = input.int  (0, title=':', minval=0, maxval=59, group='Europe', inline='stop')
colorEurope = input.color(color.new(color.yellow, transp=90), title='Color', group='Europe', inline='color')

// North America
showAmerica = input.bool(true, title='Show America', group='America')
startAmericaH = input.int  (12, title='Start (UTC)', minval=0, maxval=23, group='America', inline='start')
startAmericaM = input.int  (0, title=':', minval=0, maxval=59, group='America', inline='start')
stopAmericaH  = input.int  (20, title='Stop (UTC)', minval=0, maxval=23, group='America', inline='stop')
stopAmericaM  = input.int  (0, title=':', minval=0, maxval=59, group='America', inline='stop')
colorAmerica = input.color(color.new(color.green, transp=90), title='Color', group='America', inline='color')


///////////////////////////////////////////////////////////////////////////////
// Functions

nocolor=color.new(color.white, transp=100)

// Time session
f_timeSession (H, M) =>
    h = H < 10 ? '0' + str.tostring(H) : str.tostring(H)
    m = M < 10 ? '0' + str.tostring(M) : str.tostring(M)
    t = h + m

// Time period number
f_earlyOffset (P) =>
    p = str.tonumber(P) / 60
    o = 24 / p
    

////////////////////////////////////////////////////////////
// Calculations

// Plot ahead
earlyOffset = timeframe.isintraday ? math.round(f_earlyOffset(timeframe.period)) : 0

// Weekends
isWkndNormal = dayofweek == dayofweek.saturday or dayofweek == dayofweek.sunday
isWkndOffset = dayofweek == dayofweek.friday or dayofweek == dayofweek.saturday

isWknd = plotEarly ? isWkndOffset : isWkndNormal

// Asia
startAsia = startAsiaH * 100 + startAsiaM
startAsiaStr = f_timeSession(startAsiaH, startAsiaM)
stopAsia = stopAsiaH * 100 + stopAsiaM
stopAsiaStr = f_timeSession(stopAsiaH, stopAsiaM)

asiaOpen = startAsia <= stopAsia ? time(timeframe.period, session=startAsiaStr + '-' + stopAsiaStr) : time(timeframe.period, session='0000-' + stopAsiaStr + ',' + startAsiaStr + '-2359')

// Europe
startEurope = startEuropeH * 100 + startEuropeM
startEuropeStr = f_timeSession(startEuropeH, startEuropeM)
stopEurope = stopEuropeH * 100 + stopEuropeM
stopEuropeStr = f_timeSession(stopEuropeH, stopEuropeM)

europeOpen = startEurope <= stopEurope ? time(timeframe.period, session=startEuropeStr + '-' + stopEuropeStr) : time(timeframe.period, session='0000-' + stopEuropeStr + ',' + startEuropeStr + '-2359')

// America
startAmerica = startAmericaH * 100 + startAmericaM
startAmericaStr = f_timeSession(startAmericaH, startAmericaM)
stopAmerica = stopAmericaH * 100 + stopAmericaM
stopAmericaStr = f_timeSession(stopAmericaH, stopAmericaM)

americaOpen = startAmerica <= stopAmerica ? time(timeframe.period, session=startAmericaStr + '-' + stopAmericaStr) : time(timeframe.period, session='0000-' + stopAmericaStr + ',' + startAmericaStr + '-2359')


////////////////////////////////////////////////////////////
// Plots


bgcolor(timeframe.isintraday and showAsia and asiaOpen and (not isWknd or useWknd) ? colorAsia : na, offset=plotEarly ? earlyOffset : 0)
bgcolor(timeframe.isintraday and showEurope and europeOpen and (not isWknd or useWknd) ? colorEurope : na, offset=plotEarly ? earlyOffset : 0)
bgcolor(timeframe.isintraday and showAmerica and americaOpen and (not isWknd or useWknd) ? colorAmerica : na, offset=plotEarly ? earlyOffset : 0)


////////////////////////////////////////////////////////////
// Alerts

Overview

Users can customize the exact start and stop times in UTC for each region, as well as the background fill colors. Additional settings allow traders to include weekend sessions and project market session hours up to one day in advance. It operates primarily on intraday timeframes to visually separate daily trading hours.

Details

Published by

benso87 on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Sessions & time

Markets

Forex, Crypto, Indices

Timeframes

M1-M5, M15-H1

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.

Settings

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

SettingTypeDefaultVariable
Show sessions 1 day in advancebooltrueplotEarly
Include weekends?boolfalseuseWknd
Show AsiabooltrueshowAsia
Start (UTC)int23startAsiaH
:int0startAsiaM
Stop (UTC)int8stopAsiaH
:int0stopAsiaM
Colorcolorcolor.new(color.red, transp=90)colorAsia
Show EuropebooltrueshowEurope
Start (UTC)int7startEuropeH
:int0startEuropeM
Stop (UTC)int16stopEuropeH
Show all 20 settings
SettingTypeDefaultVariable
:int0stopEuropeM
Colorcolorcolor.new(color.yellow, transp=90)colorEurope
Show AmericabooltrueshowAmerica
Start (UTC)int12startAmericaH
:int0startAmericaM
Stop (UTC)int20stopAmericaH
:int0stopAmericaM
Colorcolorcolor.new(color.green, transp=90)colorAmerica
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

948 stars

This indicator counts down to a fixed Litecoin halving timestamp in August 2019, using Greenwich Mean Time. It subtracts the current time from that stamp and formats the remaining days, hours, minutes, and seconds. The day, hour, and minute of the target are u

Indicator v4 Sessions & time
Updated 10 days ago · GPL-3.0 GitHub repository of Litecoin Halving UTC Countdown
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

This indicator identifies and plots key options expiration dates on the price chart. It calculates monthly OpEx (the third Friday of each month), quarterly OpEx (March, June, September, December), and corresponding VIX expiration dates, drawing vertical lines

Indicator v6 Sessions & time
Updated 2 months ago · MIT GitHub repository of Expiration Highlights: Opex, Quarterly Opex & VIX with Vanna/Charm
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
219 stars

This indicator plots reference levels for previous daily high and low prices directly on the price chart. It requests daily timeframe data using the security function and plots the offset values as continuous lines, displaying resistance in red and support in

Indicator v4 Support & resistanceSessions & time
Updated 5 years ago · None stated GitHub repository of 昨日高低點標示

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

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