Pine Script Day of Week Filter

Five independent weekday toggles gate every entry, so a strategy can skip the days you'd rather sit out.

Pine Script v6 Free · TradingView free plan
Pine Script
//@version=6
strategy("Target Filled - Day of Week Filter Example", overlay=true, calc_on_every_tick=false)

// --- Inputs ---------------------------------------------------
allowMon = input.bool(true,  "Trade Monday")
allowTue = input.bool(true,  "Trade Tuesday")
allowWed = input.bool(true,  "Trade Wednesday")
allowThu = input.bool(true,  "Trade Thursday")
allowFri = input.bool(false, "Trade Friday")

// --- Weekday check on the NY clock --------------------------------
today = dayofweek(time, "America/New_York")
dayAllowed = (today == dayofweek.monday    and allowMon) or
             (today == dayofweek.tuesday   and allowTue) or
             (today == dayofweek.wednesday and allowWed) or
             (today == dayofweek.thursday  and allowThu) or
             (today == dayofweek.friday    and allowFri)

// --- Sample signal — replace with your own entry logic ---------
fastMA = ta.ema(close, 9)
slowMA = ta.ema(close, 21)
canLong  = ta.crossover(fastMA, slowMA)  and dayAllowed
canShort = ta.crossunder(fastMA, slowMA) and dayAllowed

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

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

// Visual: gray shading marks disabled weekdays
bgcolor(not dayAllowed ? color.new(color.gray, 92) : na, title="Day Disabled")

Settings

InputDefaultPurpose
allowMon … allowThuonOne toggle per weekday, Monday through Thursday.
allowFrioffFriday toggle, defaulted off.

How to use

  • Paste into the Pine Editor and swap the EMA-crossover placeholder for your own entry conditions.
  • The weekday is read on the NY clock — for US futures the trading day flips at 6:00 PM ET, so an overnight bar can belong to the next calendar day.
  • Check the per-weekday breakdown in a backtest before disabling a day; let the data make the call rather than a hunch.
  • Gray shading on the chart marks bars that fall on a disabled day.

Frequently Asked Questions

How do I stop a Pine Script strategy from trading on Fridays?
Read dayofweek(time, "America/New_York"), compare the result to dayofweek.friday, and require that comparison to be false inside every entry condition. This snippet wires that check to one input.bool per weekday, so days get toggled from the settings panel instead of editing the script each time.
How does the dayofweek() function work in Pine Script?
dayofweek(time, timezone) hands back a constant you compare against dayofweek.monday through dayofweek.sunday. Always pass an explicit timezone argument — for US futures the trading day rolls over at 6:00 PM ET, so an overnight bar can land on a different weekday than a trader's local clock would suggest.

Get a Pine Script tuned to your prop firm.

Invite-only on TradingView within 24 hours. From $19/mo, cancel anytime.