Indicator · Pine Script v6 · On the chart

Session Stats

by jayadevrana

Session Stats highlights Asia, London, and New York trading sessions on the chart with distinct background colors while tracking performance metrics.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code105
Settings1inputs
LicenceMPL-2.0
Last update2 days ago26 Oct 2026

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

105 lines of Pine Script v6 from scripts/enum-method-map.pine.txt, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

enum-method-map.pine.txt
//@version=6
indicator("Session Stats", overlay = true)

enum Session
    asia = "Asia"
    london = "London"
    newYork = "New York"

focus = input.enum(Session.london, "Highlight session")
tz = "America/New_York"

type SessionStats
    int days = 0
    float rangeSum = 0.0
    int highs = 0
    int lows = 0

method update(SessionStats this, float span, bool hi, bool lo) =>
    this.days += 1
    this.rangeSum += span
    this.highs += hi ? 1 : 0
    this.lows += lo ? 1 : 0
    this

method avgRange(SessionStats this) =>
    this.days > 0 ? this.rangeSum / this.days : na

h = hour(time, tz)
Session sess = h >= 17 or h < 3 ? Session.asia :
  h < 8 ? Session.london : Session.newYork
newSess = bar_index > 0 and sess != sess[1]
newDay = newSess and sess == Session.asia

col = switch sess
    Session.asia => color.blue
    Session.london => color.orange
    => color.purple
bgcolor(color.new(col, sess == focus ? 75 : 92), title = "Session")

var stats = map.new<Session, SessionStats>()
if barstate.isfirst
    stats.put(Session.asia, SessionStats.new())
    stats.put(Session.london, SessionStats.new())
    stats.put(Session.newYork, SessionStats.new())
var today = map.new<Session, float>()

var float sessHigh = na
var float sessLow = na
var float dayHigh = na
var float dayLow = na
var Session highSess = na
var Session lowSess = na
var int totalDays = 0

if newSess and not na(sessHigh)
    today.put(sess[1], sessHigh - sessLow)
if newDay
    if not na(dayHigh)
        for [k, r] in today
            stats.get(k).update(r, k == highSess, k == lowSess)
        totalDays += 1
    today.clear()
    dayHigh := high
    dayLow := low
    highSess := sess
    lowSess := sess

if newSess
    sessHigh := high
    sessLow := low
else
    sessHigh := math.max(sessHigh, high)
    sessLow := math.min(sessLow, low)
if high > dayHigh
    dayHigh := high
    highSess := sess
if low < dayLow
    dayLow := low
    lowSess := sess
plot(newSess ? na : sessHigh, "Session high", color.gray, 1,
  plot.style_linebr)
plot(newSess ? na : sessLow, "Session low", color.gray, 1,
  plot.style_linebr)

pct(int n) =>
    totalDays > 0 ? str.tostring(100.0 * n / totalDays, "#") + "%" : "-"
var table panel = table.new(position.top_right, 5, 4,
  bgcolor = color.new(color.black, 15), border_width = 1,
  frame_width = 1, frame_color = color.gray)
if barstate.islast
    heads = array.from("session", "days", "avg range", "day high",
      "day low")
    for i = 0 to 4
        table.cell(panel, i, 0, heads.get(i), text_color = color.white,
          bgcolor = color.new(color.teal, 0))
    row = 1
    for [k, s] in stats
        tc = k == focus ? color.yellow : color.white
        rng = s.days > 0 ? str.tostring(s.avgRange(), "#.00") : "-"
        table.cell(panel, 0, row, str.tostring(k), text_color = tc)
        table.cell(panel, 1, row, str.tostring(s.days), text_color = tc)
        table.cell(panel, 2, row, rng, text_color = tc)
        table.cell(panel, 3, row, pct(s.highs), text_color = tc)
        table.cell(panel, 4, row, pct(s.lows), text_color = tc)
        row += 1

Overview

Session Stats plots session high and low lines directly on price action and presents a summary table displaying average session ranges and the frequency with which each session sets the daily high or low. The main setting selects a focus session for visual emphasis.

Details

Published by

jayadevrana on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Sessions & time, Screeners & dashboards, Support & resistance

Markets

Forex

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.

Topics

algorithmic-tradingbacktestingema-crossoverpine-scriptpine-script-v6pinescriptrsitechnical-analysistrading-automationtrading-indicators

Settings

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

SettingTypeDefaultVariable
Highlight sessionenumSession.londonfocus
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 overlays an intraday SPX and ES chart with a midnight session range, regular-trading-hours opening levels, and a VWAP projection box. It draws the midnight high, mid, and low, flags edge rejections within an absolute tolerance, and plots optiona

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of SPX Midnight Box + Snag Logic

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

Session Edge Probabilities

by TraderOracle
61 stars

Session Edge Probabilities tracks eight session-based trading rules using statistical probabilities evaluated on historical chart data. It utilizes a fixed calculation timeframe to evaluate opening ranges, midnight levels, afternoon reversal windows, and price

Indicator v6 Sessions & timeScreeners & dashboards
Updated 9 days ago · None stated GitHub repository of Session Edge Probabilities
56 stars

This indicator marks forex trading sessions and opening ranges on the price chart. It can draw Sydney, Tokyo, Frankfurt, London, and New York session boxes or five- and fifteen-minute opening ranges, plus an optional opening channel and a day-open range. Day r

Indicator v5 Sessions & timeSupport & resistance Repaints
Updated 2 months ago · None stated GitHub repository of Day Trading Booster by DGT

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