Indicator · Pine Script v6 · On the chart

Session Filter

by jayadevrana

Session Filter is an overlay indicator that plots a fast and a slow exponential moving average on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code35
Settings4inputs
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

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

session-filter.pine.txt
//@version=6
indicator("Session Filter", overlay = true)

// 1. Settings: which hours you want to trade
sessionTime = input.session("0800-1600", "Trading session")
sessionZone = input.string("Europe/London", "Timezone")
fastLen     = input.int(9, "Fast average")
slowLen     = input.int(21, "Slow average")

// 2. Are we inside the session right now?
inSession = not na(time(timeframe.period, sessionTime, sessionZone))

// 3. Shade the background during the session
bgcolor(inSession ? color.new(color.blue, 92) : na)

// 4. The signal we want to filter
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
plot(fast, "Fast", color.aqua)
plot(slow, "Slow", color.orange)

// 5. The raw crossover, at any time of day
rawBuy = ta.crossover(fast, slow)

// 6. The same signal, but only inside your session
buySignal = rawBuy and inSession

// 7. Show both, so you can see what the filter removed
plotshape(rawBuy and not inSession, "Skipped", shape.xcross,
  location.belowbar, color.gray, size = size.tiny)
plotshape(buySignal, "Buy", shape.triangleup, location.belowbar,
  color.green, size = size.small)

// 8. Alert only for the filtered signal
alertcondition(buySignal, "Buy in session", "{{ticker}} buy inside session")

Overview

Session Filter marks a buy when the fast average crosses above the slow average only during a user-defined trading session, and it marks crossovers outside that window as skipped. A light blue background shades bars inside the session. The session hours, timezone, and both average lengths are adjustable. An alert fires only for the filtered buy. There is no sell signal or exit rule.

Details

Published by

jayadevrana on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Trend, Moving averages, Sessions & time

Markets

Any symbol

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

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
Trading sessionsession0800-1600sessionTime
TimezonestringEurope/LondonsessionZone
Fast averageint9fastLen
Slow averageint21slowLen
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

257 stars

Donald SPX - Options Trading is an overlay indicator designed for intraday SPX analysis. It plots a 200-period Weighted Moving Average (WMA) on the price chart while evaluating multi-timeframe market structure across Daily, 15-minute, 5-minute, and 2-minute ba

Indicator v5 Moving averagesTrend Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Market Monitor - 15m

by chris-c-thomas
14 stars

Market Monitor - 15m is a directional bias chart overlay designed for 15-minute intraday chart analysis. It calculates a triple exponential moving average ribbon with EMA cloud shading, session VWAP with multiplier bands, prior day levels, a 30-minute opening

Indicator v6 TrendMoving averages
Updated 6 months ago · MIT GitHub repository of Market Monitor - 15m

Pivot Trendlines

by g-moe
3 stars

This indicator identifies pivot highs and lows using a swing lookback period and connects them with trendlines on the price chart. It generates long and short entry signals when price moves through predefined percentage thresholds in three steps for buy and se

Indicator v5 TrendSupport & resistance
Updated 5 months ago · None stated GitHub repository of Pivot Trendlines

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