OPEN-SOURCE SCRIPT
Seasonal Anomaly Chart (24 Years)

Seasonal Anomaly Indicator: Overview
This is an advanced analytical tool that extracts the "year-to-date price movement patterns (seasonality)" of a target symbol over the past 24 years (default setting), compares them with the current year's performance, and automatically plots a projected trajectory for the next 180 days—based on historical statistics—onto the right side of the chart (the future space).
While seasonal anomalies are a powerful tool, they do not represent an absolute rule that plays out identically every year. Years marked by macroeconomic shocks (such as sudden interest rate fluctuations or pandemics) can see price action deviate completely from established anomalies.
Therefore, this indicator should not be used in isolation to make trading decisions.
We recommend using it as a filter for market context—providing supporting evidence for your edge—such as entering a trade only when a trend-following signal appears during a period where seasonality suggests an upward move.
Technical Prerequisites:
To ensure accurate data synchronization while bypassing Pine Script's inherent execution limits (such as memory constraints and loop timeouts), this script employs the following design:
1. Flattened Ring Buffer
Since Pine Script limits the dynamic handling of multi-dimensional arrays, this script uses a "flattened index" approach, treating a one-dimensional array like a two-dimensional matrix. It constructs a ring buffer sized for the target number of past years plus one; by using modulo operations to cyclically overwrite data, it maintains a continuous record of the most recent 24 years of data.
2. Absolute Synchronization Based on Trading Days
Synchronizing historical data based on calendar dates (month and day) results in data gaps caused by weekends, holidays, and leap years. This system synchronizes data using the "number of bars elapsed since the start of the year" (*bar_in_year*) as the reference axis. This allows historical cycles to be overlaid without distortion—whether using daily or weekly charts—based purely on actual market trading days. 3. Mathematical Calculation of Volatility
Data for each bar is calculated and normalized in real-time as a percentage change relative to the opening price on the first trading day of the year.
User Manual (Settings and Interpretation)
Step 1: Adjusting Parameters
You can make the following adjustments via the "gear icon (Settings)" next to the indicator name ("Seasonal %") on the chart:
① Historical years (Default: 24):
The number of past years used to calculate the seasonal average. While 24 years is effective for stock indices, you should optimize this by reducing it to "5" or "10" for markets with shorter histories (such as cryptocurrency) or to align with the current market regime (market environment).
② Number of future bars for the forecast (Default: 180):
The length of the forecast line drawn in the empty space to the right of the chart.
③ Color settings:
Colors can be changed to ensure visibility against the chart's background color.
Step 2: How to Read the Chart
The indicator displays four elements:
① Gray dotted line (Zero Line):
The baseline (0%) representing the start of the year (as of January 1st).
② Orange solid line (Historical Average):
The average performance (anomaly) over the past 24 years. It indicates statistical tendencies, such as periods when prices are likely to rise or fall.
③ White solid line (Current Year's Performance):
The actual price movement (%) for the current year. By observing the divergence between the historical average (orange) and the current year (white), you can relatively assess whether the market is stronger or weaker than usual.
④ Orange dotted line (Future Forecast):
A future projection based on the historical average, drawn in the empty space to the right of the current bar. Use this to gauge potential profit-taking points or to predict trend reversal timings.
This is an advanced analytical tool that extracts the "year-to-date price movement patterns (seasonality)" of a target symbol over the past 24 years (default setting), compares them with the current year's performance, and automatically plots a projected trajectory for the next 180 days—based on historical statistics—onto the right side of the chart (the future space).
While seasonal anomalies are a powerful tool, they do not represent an absolute rule that plays out identically every year. Years marked by macroeconomic shocks (such as sudden interest rate fluctuations or pandemics) can see price action deviate completely from established anomalies.
Therefore, this indicator should not be used in isolation to make trading decisions.
We recommend using it as a filter for market context—providing supporting evidence for your edge—such as entering a trade only when a trend-following signal appears during a period where seasonality suggests an upward move.
Technical Prerequisites:
To ensure accurate data synchronization while bypassing Pine Script's inherent execution limits (such as memory constraints and loop timeouts), this script employs the following design:
1. Flattened Ring Buffer
Since Pine Script limits the dynamic handling of multi-dimensional arrays, this script uses a "flattened index" approach, treating a one-dimensional array like a two-dimensional matrix. It constructs a ring buffer sized for the target number of past years plus one; by using modulo operations to cyclically overwrite data, it maintains a continuous record of the most recent 24 years of data.
2. Absolute Synchronization Based on Trading Days
Synchronizing historical data based on calendar dates (month and day) results in data gaps caused by weekends, holidays, and leap years. This system synchronizes data using the "number of bars elapsed since the start of the year" (*bar_in_year*) as the reference axis. This allows historical cycles to be overlaid without distortion—whether using daily or weekly charts—based purely on actual market trading days. 3. Mathematical Calculation of Volatility
Data for each bar is calculated and normalized in real-time as a percentage change relative to the opening price on the first trading day of the year.
User Manual (Settings and Interpretation)
Step 1: Adjusting Parameters
You can make the following adjustments via the "gear icon (Settings)" next to the indicator name ("Seasonal %") on the chart:
① Historical years (Default: 24):
The number of past years used to calculate the seasonal average. While 24 years is effective for stock indices, you should optimize this by reducing it to "5" or "10" for markets with shorter histories (such as cryptocurrency) or to align with the current market regime (market environment).
② Number of future bars for the forecast (Default: 180):
The length of the forecast line drawn in the empty space to the right of the chart.
③ Color settings:
Colors can be changed to ensure visibility against the chart's background color.
Step 2: How to Read the Chart
The indicator displays four elements:
① Gray dotted line (Zero Line):
The baseline (0%) representing the start of the year (as of January 1st).
② Orange solid line (Historical Average):
The average performance (anomaly) over the past 24 years. It indicates statistical tendencies, such as periods when prices are likely to rise or fall.
③ White solid line (Current Year's Performance):
The actual price movement (%) for the current year. By observing the divergence between the historical average (orange) and the current year (white), you can relatively assess whether the market is stronger or weaker than usual.
④ Orange dotted line (Future Forecast):
A future projection based on the historical average, drawn in the empty space to the right of the current bar. Use this to gauge potential profit-taking points or to predict trend reversal timings.
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。