HomePine Script Snippets › First Minutes Filter

Pine Script First X Minutes Filter

Blocks — or exclusively allows — entries during the first X minutes after the open, where spreads and slippage are at their worst.

//@version=6
strategy("First Minutes Filter", overlay=true, calc_on_every_tick=false)

// ── Inputs ──────────────────────────────────────────────
skipMins = input.int(5, "Minutes After Open", minval=1, maxval=120)
onlyMode = input.bool(false, "Only Trade This Window",
     tooltip="Off = skip the first X minutes. On = trade ONLY the first X minutes.")
openHr   = input.int(9,  "Session Open Hour (ET)", minval=0, maxval=23)
openMin  = input.int(30, "Session Open Minute", minval=0, maxval=59)

// ── Minutes since session open (NY clock) ────────────────
nyMins        = hour(time, "America/New_York") * 60 + minute(time, "America/New_York")
minsSinceOpen = nyMins - (openHr * 60 + openMin)
inOpenWindow  = minsSinceOpen >= 0 and minsSinceOpen < skipMins
pastOpen      = minsSinceOpen >= skipMins

tradeOK = onlyMode ? inOpenWindow : pastOpen

// ── Entry logic (replace with your own conditions) ───────
longCondition  = ta.crossover(ta.ema(close, 9), ta.ema(close, 21)) and tradeOK
shortCondition = ta.crossunder(ta.ema(close, 9), ta.ema(close, 21)) and tradeOK

if longCondition
    strategy.entry("Long", strategy.long)
    strategy.exit("Long Exit", "Long", profit=20, loss=10)

if shortCondition
    strategy.entry("Short", strategy.short)
    strategy.exit("Short Exit", "Short", profit=20, loss=10)

// Visual
bgcolor(inOpenWindow ? color.new(color.yellow, 92) : na, title="Opening Window")

Settings

How to use

Frequently Asked Questions

How do I skip the first 5 minutes after open in Pine Script?

Compute minutes since the session open on the NY clock and require it to be at least 5 before entries can fire. This snippet does that with a skipMins input, so you can push it to 15 or 30 minutes without touching code.

Why avoid trading the market open on a prop account?

The first minutes after 9:30 ET have the widest spreads, heaviest slippage, and most erratic price action of the session. On an eval account a bad fill in the opening burst can consume a large share of the daily loss budget before your edge has a chance to work. Most systematic prop traders either skip the open or trade it with a dedicated opening strategy — not a generic one.

Related

Want a complete eval-ready strategy with open handling solved?

This snippet is a building block. Our paid scripts are complete strategies — entries, timing filters, kill switch, and EOD flatten verified on 3 years of MES/NQ data. Instant delivery from $50.

View Plans — From $50