OPEN-SOURCE SCRIPT

Trading Sessions [QuantAlgo]

248
๐ŸŸข Overview

The Trading Sessions indicator tracks and displays the four major global trading sessions: Sydney, Tokyo, London, and New York. It provides session-based background highlighting, real-time price change tracking from session open, and a data table with session status. The script works across all markets (forex, equities, commodities, crypto) and helps traders identify when specific geographic markets are active, which directly correlates with changes in liquidity and volatility patterns. Default session times are set to major financial center hours in UTC but are fully adjustable to match your trading methodology.
snapshot
๐ŸŸข Key Features

โ†’ Session Background Color Coding
Each trading session gets a distinct background color on your chart:

1. Sydney Session - Default orange, 22:00-07:00 UTC
2. Tokyo Session - Default red, 00:00-09:00 UTC
3. London Session - Default green, 08:00-16:00 UTC
4. New York Session - Default blue, 13:00-22:00 UTC
snapshot
When sessions overlap, the color priority is New York > London > Tokyo > Sydney. This means if London and New York are both active, the background shows New York's color. The priority matches typical liquidity and volatility patterns where later sessions generally show higher volume.

โ†’ Color Customization
All session colors are configurable in the Color Settings panel:
snapshot
1. Click any session color input to open the color picker
2. Select your preferred color for that session
3. Use the "Background Transparency" slider (0-100) to adjust opacity. Lower values = more visible, higher values = more subtle
4. Enable "Color Price Bars" to color candlesticks themselves according to the active session instead of just the background

The Color column in the info table shows a block (โ–ˆ) in each session's assigned color, matching what you see on the chart background.

โ†’ Information Table Breakdown
snapshot
โ†’ Timeframe Warning
snapshot
If you're viewing a timeframe of 12 hours or higher, a red warning label appears center-screen. Session boundaries don't render accurately on high timeframes because the time() function in Pine Script can't detect intra-bar session changes when each bar spans multiple sessions. The warning tells you to switch to sub-12H timeframes (e.g., 4H, 1H, 30m, 15m, etc.) for proper session detection. You can disable this warning in Color Settings if needed, but session highlighting can be unreliable on 12H+ charts regardless.

โ†’ Time Range Configuration
Every session's time range is editable in Session Settings:
snapshot
1. Click the time input field next to each session
2. Enter time as HHMM-HHMM in 24-hour format
3. All times are interpreted as UTC
4. Modify these to account for daylight saving shifts or to define custom session periods based on your backtested optimal trading windows

For example, if your strategy performs best during London/NY overlap specifically, you could set London to 08:00-17:00 and New York to 13:00-22:00 to ensure you see the full overlap highlighted.

โ†’ Weekdays Filter
The "Weekdays Only (Mon-Fri)" toggle controls whether sessions display on weekends:
  • Enabled: Sessions only show Monday-Friday and hide on Saturday-Sunday. Use this for markets that close on weekends (most equities, forex).
  • Disabled: Sessions display 24/7 including weekends. Use this for markets that trade continuously (crypto).


โ†’ Table Display Options
The info table has several configuration options in Table Settings:
  • Visibility: Toggle "Show Info Table" on/off to display or hide the entire table.
  • Position: Nine position options (Top/Middle/Bottom + Left/Center/Right) let you place the table wherever it doesn't block your price action or other indicators.
  • Text Size: Four size options (Tiny, Small, Normal, Large) to match your screen resolution and visual preferences.

โ†’ Color Schemes:
  • Mono: Black background, gray header, white text
  • Light: White background, light gray header, black text
  • Blue: Dark blue background, medium blue header, white text
  • Custom: Manual selection of all five color components (table background, header background, header text, data text, borders)

โ†’ Alert Functionality
The indicator includes ten alert conditions you can access via TradingView's alert system:

Session Opens:
1. Sydney Session Started
2. Tokyo Session Started
3. London Session Started
4. New York Session Started
5. Any Session Started

Session Closes:
6. Sydney Session Ended
7. Tokyo Session Ended
8. London Session Ended
9. New York Session Ended
10. Any Session Ended
snapshot
These alerts fire when sessions transition based on your configured time ranges, letting you automate monitoring of session changes without watching the chart continuously. Useful for strategies that trade specific session opens/closes or need to adjust position sizing when volatility regime shifts between sessions.

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 TradingView. Read more in the Terms of Use.