OPEN-SOURCE SCRIPT
Weekday Close vs Open — Last N (per weekday)

# Weekday Close vs Open - Last N Occurrences
This indicator distills every weekday's historical open-to-close behavior into a compact table so you can see how "typical" the current session is before the day even closes. It runs independently of your chart timeframe by pulling daily OHLCV data under the hood, tracking the last **N** completed occurrences for each weekday, and refreshing only when a daily bar closes. On daily charts you can also shade every past bar that matches today's weekday (excluding the in-progress session) to reinforce the pattern visually while the table remains non-repainting.
## What It Shows
- **Win/Loss/Tie counts** - how many of the last `N` occurrences closed above the open (wins), below (losses), or inside the tie threshold you define as "flat".
- **Win % heatmap** - the win column is color-coded (deep green > deep red) so you immediately recognize strong or weak weekdays.
- **Advanced metrics (optional)** - average daily volume plus the average percentage excursion above/below the open (`AvgUp%`, `AvgDn%`) for that weekday.
- **Totals row** - aggregates every weekday into one row to estimate overall hit rate and average stats across the entire data set.
- **Weekday shading (optional)** - on daily charts you can tint every bar that matches today's weekday (all Mondays, all Fridays, etc.) for instant pattern recognition.
## How It Works
1. The script requests daily OHLCV data (non-repainting) regardless of the chart timeframe.
2. When a new daily bar confirms, it packs that day's data into one of seven arrays (one per weekday). Each day contributes five floats (O/H/L/C/V) so trimming and statistics stay in lockstep.
3. A helper function (`f_dayMetrics`) scans daily history to compute average volume, average excursion above/below the open, and win/loss/tie counts for the requested weekday.
4. The table populates on the last bar of the chart session, respecting your advanced/totals toggles and keeping text at `size.normal`.
## Reading the Table
- **Win/Loss/Tie columns**: raw counts taken from your chosen `N`.
- **Win %***: excludes ties from the denominator so it reflects only decisive closes.
- **AvgUp% / AvgDn%**: typical intraday extension (high vs open, open vs low) in percent.
- **Avg Vol**: arithmetic mean of daily volume for that weekday.
- **TOTAL row**: provides a global win rate plus volume/up/down averages weighted by how many samples each weekday contributed.
## Practical Uses
- Spot weekdays that historically trend higher or lower before entering a trade.
- Compare current price action against the typical intraday range (`AvgUp%` vs today's move).
- Filter mean-reversion vs breakout setups based on the most reliable weekday patterns.
- Quickly gauge whether today is behaving "in character" by referencing the highlighted row or the optional whole-chart weekday shading.
> **Tip:** Use smaller `N` values (e.g., 10-20) for adaptive, recent behavior and larger values (50+) to capture longer-term seasonality. Tighten the tie threshold if you want almost every candle to register as win/loss, or widen it to focus only on meaningful moves.
This indicator distills every weekday's historical open-to-close behavior into a compact table so you can see how "typical" the current session is before the day even closes. It runs independently of your chart timeframe by pulling daily OHLCV data under the hood, tracking the last **N** completed occurrences for each weekday, and refreshing only when a daily bar closes. On daily charts you can also shade every past bar that matches today's weekday (excluding the in-progress session) to reinforce the pattern visually while the table remains non-repainting.
## What It Shows
- **Win/Loss/Tie counts** - how many of the last `N` occurrences closed above the open (wins), below (losses), or inside the tie threshold you define as "flat".
- **Win % heatmap** - the win column is color-coded (deep green > deep red) so you immediately recognize strong or weak weekdays.
- **Advanced metrics (optional)** - average daily volume plus the average percentage excursion above/below the open (`AvgUp%`, `AvgDn%`) for that weekday.
- **Totals row** - aggregates every weekday into one row to estimate overall hit rate and average stats across the entire data set.
- **Weekday shading (optional)** - on daily charts you can tint every bar that matches today's weekday (all Mondays, all Fridays, etc.) for instant pattern recognition.
## How It Works
1. The script requests daily OHLCV data (non-repainting) regardless of the chart timeframe.
2. When a new daily bar confirms, it packs that day's data into one of seven arrays (one per weekday). Each day contributes five floats (O/H/L/C/V) so trimming and statistics stay in lockstep.
3. A helper function (`f_dayMetrics`) scans daily history to compute average volume, average excursion above/below the open, and win/loss/tie counts for the requested weekday.
4. The table populates on the last bar of the chart session, respecting your advanced/totals toggles and keeping text at `size.normal`.
## Reading the Table
- **Win/Loss/Tie columns**: raw counts taken from your chosen `N`.
- **Win %***: excludes ties from the denominator so it reflects only decisive closes.
- **AvgUp% / AvgDn%**: typical intraday extension (high vs open, open vs low) in percent.
- **Avg Vol**: arithmetic mean of daily volume for that weekday.
- **TOTAL row**: provides a global win rate plus volume/up/down averages weighted by how many samples each weekday contributed.
## Practical Uses
- Spot weekdays that historically trend higher or lower before entering a trade.
- Compare current price action against the typical intraday range (`AvgUp%` vs today's move).
- Filter mean-reversion vs breakout setups based on the most reliable weekday patterns.
- Quickly gauge whether today is behaving "in character" by referencing the highlighted row or the optional whole-chart weekday shading.
> **Tip:** Use smaller `N` values (e.g., 10-20) for adaptive, recent behavior and larger values (50+) to capture longer-term seasonality. Tighten the tie threshold if you want almost every candle to register as win/loss, or widen it to focus only on meaningful moves.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน