OPEN-SOURCE SCRIPT
Seasonality DOW Combined

Overall Purpose
This script analyzes historical daily returns based on two specific criteria:
Month of the year (January through December)
Day of the week (Sunday through Saturday)
It summarizes and visually displays the average historical performance of the selected asset by these criteria over multiple years.
Step-by-Step Breakdown
1. Initial Settings:
Defines minimum year (i_year_start) from which data analysis will start.
Ensures the user is using a daily timeframe, otherwise prompts an error.
Sets basic display preferences like text size and color schemes.
2. Data Collection and Variables:
Initializes matrices to store and aggregate returns data:
month_data_ and month_agg_: store monthly performance.
dow_data_ and dow_agg_: store day-of-week performance.
COUNT tracks total number of occurrences, and COUNT_POSITIVE tracks positive-return occurrences.
3. Return Calculation:
Calculates daily percentage change (chg_pct_) in price:
chg_pct_ = close / close[1] - 1
Ensures it captures this data only for the specified years (year >= i_year_start).
4. Monthly Performance Calculation:
Each daily return is grouped by month:
matrix.set updates total returns per month.
The script tracks:
Monthly cumulative returns
Number of occurrences (how many days recorded per month)
Positive occurrences (days with positive returns)
5. Day-of-Week Performance Calculation:
Similarly, daily returns are also grouped by day-of-the-week (Sunday to Saturday):
Daily return values are summed per weekday.
The script tracks:
Cumulative returns per weekday
Number of occurrences per weekday
Positive occurrences per weekday
6. Visual Display (Tables):
The script creates two visual tables:
Left Table: Monthly Performance.
Right Table: Day-of-the-Week Performance.
For each table, it shows:
Yearly data for each month/day.
Summaries at the bottom:
SUM row: Shows total accumulated returns over all selected years for each month/day.
+ive row: Shows percentage (%) of times the month/day had positive returns, along with a tooltip displaying positive occurrences vs total occurrences.
Cells are color-coded:
Green for positive returns.
Red for negative returns.
Gray for neutral/no change.
7. Interpreting the Tables:
Monthly Table (left side):
Helps identify seasonal patterns (e.g., historically bullish/bearish months).
Day-of-Week Table (right side):
Helps detect recurring weekday patterns (e.g., historically bullish Mondays or bearish Fridays).
Practical Use:
Traders use this to:
Identify patterns based on historical data.
Inform trading strategies, e.g., avoiding historically bearish days/months or leveraging historically bullish periods.
Example Interpretation:
If the table shows consistently green (positive) for March and April, historically the asset tends to perform well during spring. Similarly, if the "Friday" column is often red, historically Fridays are bearish for this asset.
This script analyzes historical daily returns based on two specific criteria:
Month of the year (January through December)
Day of the week (Sunday through Saturday)
It summarizes and visually displays the average historical performance of the selected asset by these criteria over multiple years.
Step-by-Step Breakdown
1. Initial Settings:
Defines minimum year (i_year_start) from which data analysis will start.
Ensures the user is using a daily timeframe, otherwise prompts an error.
Sets basic display preferences like text size and color schemes.
2. Data Collection and Variables:
Initializes matrices to store and aggregate returns data:
month_data_ and month_agg_: store monthly performance.
dow_data_ and dow_agg_: store day-of-week performance.
COUNT tracks total number of occurrences, and COUNT_POSITIVE tracks positive-return occurrences.
3. Return Calculation:
Calculates daily percentage change (chg_pct_) in price:
chg_pct_ = close / close[1] - 1
Ensures it captures this data only for the specified years (year >= i_year_start).
4. Monthly Performance Calculation:
Each daily return is grouped by month:
matrix.set updates total returns per month.
The script tracks:
Monthly cumulative returns
Number of occurrences (how many days recorded per month)
Positive occurrences (days with positive returns)
5. Day-of-Week Performance Calculation:
Similarly, daily returns are also grouped by day-of-the-week (Sunday to Saturday):
Daily return values are summed per weekday.
The script tracks:
Cumulative returns per weekday
Number of occurrences per weekday
Positive occurrences per weekday
6. Visual Display (Tables):
The script creates two visual tables:
Left Table: Monthly Performance.
Right Table: Day-of-the-Week Performance.
For each table, it shows:
Yearly data for each month/day.
Summaries at the bottom:
SUM row: Shows total accumulated returns over all selected years for each month/day.
+ive row: Shows percentage (%) of times the month/day had positive returns, along with a tooltip displaying positive occurrences vs total occurrences.
Cells are color-coded:
Green for positive returns.
Red for negative returns.
Gray for neutral/no change.
7. Interpreting the Tables:
Monthly Table (left side):
Helps identify seasonal patterns (e.g., historically bullish/bearish months).
Day-of-Week Table (right side):
Helps detect recurring weekday patterns (e.g., historically bullish Mondays or bearish Fridays).
Practical Use:
Traders use this to:
Identify patterns based on historical data.
Inform trading strategies, e.g., avoiding historically bearish days/months or leveraging historically bullish periods.
Example Interpretation:
If the table shows consistently green (positive) for March and April, historically the asset tends to perform well during spring. Similarly, if the "Friday" column is often red, historically Fridays are bearish for this asset.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.
Script open-source
In pieno spirito TradingView, il creatore di questo script lo ha reso open-source, in modo che i trader possano esaminarlo e verificarne la funzionalità. Complimenti all'autore! Sebbene sia possibile utilizzarlo gratuitamente, ricorda che la ripubblicazione del codice è soggetta al nostro Regolamento.
Declinazione di responsabilità
Le informazioni ed i contenuti pubblicati non costituiscono in alcun modo una sollecitazione ad investire o ad operare nei mercati finanziari. Non sono inoltre fornite o supportate da TradingView. Maggiori dettagli nelle Condizioni d'uso.