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.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.
Script de código aberto
Em verdadeiro espírito do TradingView, o criador deste script o tornou de código aberto, para que os traders possam revisar e verificar sua funcionalidade. Parabéns ao autor! Embora você possa usá-lo gratuitamente, lembre-se de que a republicação do código está sujeita às nossas Regras da Casa.
Aviso legal
As informações e publicações não se destinam a ser, e não constituem, conselhos ou recomendações financeiras, de investimento, comerciais ou de outro tipo fornecidos ou endossados pela TradingView. Leia mais nos Termos de Uso.