OPEN-SOURCE SCRIPT
Cyclical Phases of the Market

🧭 Overview
“Cyclical Phases of the Market” automatically detects major market cycles by connecting swing lows and measuring the average number of bars between them.
Once it learns the rhythm of past cycles, it projects the next expected cycle (in time and price) using a dashed orange line and a forecast label.
In simple terms:
The indicator shows where the next potential low is statistically expected to occur, based on the timing and depth of previous cycles.
⚙️ Core Logic – Step by Step
1️⃣ Pivot Detection
The script uses the built-in ta.pivotlow() and ta.pivothigh() functions to find local turning points:
pivotLow marks a local swing low, defined by pivotLeft and pivotRight bars on each side.
Only confirmed lows are used to define the major cycle points.
Each new pivot low is stored in two arrays:
cycleLows[] → price level of the low
cycleBars[] → bar index where the low occurred
2️⃣ Cycle Identification and Drawing
Every time two consecutive swing lows are found, the indicator:
Calculates the number of bars between them (cycle length).
If that distance is greater than or equal to minCycleBars, it draws a teal line connecting the two lows — visually representing one complete cycle.
These teal lines form the historical cycle structure of the market.
3️⃣ Average Cycle Length
Once there are at least three completed cycles, the script calculates the average duration (mean number of bars between lows).
This value — avgCycleLength — represents the dominant periodicity or cycle rhythm of the market.
4️⃣ Forecasting the Next Cycle
When a valid average cycle length exists, the model projects the next expected cycle:
Time projection:
Adds avgCycleLength to the last cycle’s ending bar index to find where the next low should occur.
Price projection:
Estimates the vertical amplitude by taking the difference between the last two cycle lows (priceDiff).
Adds this same difference to the last low price to forecast the next probable low level.
The result is drawn as an orange dashed line extending into the future, representing the Next Expected Cycle.
5️⃣ Forecast Label
An orange label 🔮 appears at the projected future point showing:
Text:
🔮 Upcoming Cycle Forecast
Price: [forecasted level]
The label marks the probable area and timing of the next cyclical low.
(Note: the date/time calculation currently multiplies bar count by 7 days, so it’s designed mainly for daily charts. On other timeframes, that conversion can be adapted.)
📊 How to Read It on the Chart
Visual Element Meaning Interpretation
Teal lines Completed historical cycles (low to low) Show actual periodic rhythm of the market
Orange dashed line Projection of the next expected cycle Anticipated path toward the next cyclical low
Orange label 🔮 Upcoming Cycle Forecast Displays expected price and bar location
Average cycle length Internal variable (bars between lows) Represents the dominant cycle period
📈 Interpretation
When teal segments show consistent spacing, the market is following a stable rhythm → cycles are predictable.
When cycle spacing shortens, the market is accelerating (volatility rising).
When it widens, the market is slowing down or entering accumulation.
The orange dashed line represents the next expected low zone:
If the market drops near this line → cyclical pattern confirmed.
If the market breaks well below → cycle amplitude has increased (trend weakening).
If the market rises above and delays → a new longer cycle may be forming.
🧠 Practical Use
Combine with oscillators (e.g., RSI or TSI) to confirm momentum alignment near projected lows.
Use in conjunction with volume to identify accumulation or exhaustion near the expected turning point.
Compare across timeframes: weekly cycles confirm long-term rhythm; daily cycles refine short-term entries.
⚡ Summary
Aspect Description
Purpose Detect and forecast recurring market cycles
Cycle basis Low-to-Low pivot analysis
Visuals Teal historical cycles + Orange forecast line
Forecast Next expected low (price and time)
Ideal timeframe Daily
Main outputs Average cycle length, next projected cycle, visual cycle map
“Cyclical Phases of the Market” automatically detects major market cycles by connecting swing lows and measuring the average number of bars between them.
Once it learns the rhythm of past cycles, it projects the next expected cycle (in time and price) using a dashed orange line and a forecast label.
In simple terms:
The indicator shows where the next potential low is statistically expected to occur, based on the timing and depth of previous cycles.
⚙️ Core Logic – Step by Step
1️⃣ Pivot Detection
The script uses the built-in ta.pivotlow() and ta.pivothigh() functions to find local turning points:
pivotLow marks a local swing low, defined by pivotLeft and pivotRight bars on each side.
Only confirmed lows are used to define the major cycle points.
Each new pivot low is stored in two arrays:
cycleLows[] → price level of the low
cycleBars[] → bar index where the low occurred
2️⃣ Cycle Identification and Drawing
Every time two consecutive swing lows are found, the indicator:
Calculates the number of bars between them (cycle length).
If that distance is greater than or equal to minCycleBars, it draws a teal line connecting the two lows — visually representing one complete cycle.
These teal lines form the historical cycle structure of the market.
3️⃣ Average Cycle Length
Once there are at least three completed cycles, the script calculates the average duration (mean number of bars between lows).
This value — avgCycleLength — represents the dominant periodicity or cycle rhythm of the market.
4️⃣ Forecasting the Next Cycle
When a valid average cycle length exists, the model projects the next expected cycle:
Time projection:
Adds avgCycleLength to the last cycle’s ending bar index to find where the next low should occur.
Price projection:
Estimates the vertical amplitude by taking the difference between the last two cycle lows (priceDiff).
Adds this same difference to the last low price to forecast the next probable low level.
The result is drawn as an orange dashed line extending into the future, representing the Next Expected Cycle.
5️⃣ Forecast Label
An orange label 🔮 appears at the projected future point showing:
Text:
🔮 Upcoming Cycle Forecast
Price: [forecasted level]
The label marks the probable area and timing of the next cyclical low.
(Note: the date/time calculation currently multiplies bar count by 7 days, so it’s designed mainly for daily charts. On other timeframes, that conversion can be adapted.)
📊 How to Read It on the Chart
Visual Element Meaning Interpretation
Teal lines Completed historical cycles (low to low) Show actual periodic rhythm of the market
Orange dashed line Projection of the next expected cycle Anticipated path toward the next cyclical low
Orange label 🔮 Upcoming Cycle Forecast Displays expected price and bar location
Average cycle length Internal variable (bars between lows) Represents the dominant cycle period
📈 Interpretation
When teal segments show consistent spacing, the market is following a stable rhythm → cycles are predictable.
When cycle spacing shortens, the market is accelerating (volatility rising).
When it widens, the market is slowing down or entering accumulation.
The orange dashed line represents the next expected low zone:
If the market drops near this line → cyclical pattern confirmed.
If the market breaks well below → cycle amplitude has increased (trend weakening).
If the market rises above and delays → a new longer cycle may be forming.
🧠 Practical Use
Combine with oscillators (e.g., RSI or TSI) to confirm momentum alignment near projected lows.
Use in conjunction with volume to identify accumulation or exhaustion near the expected turning point.
Compare across timeframes: weekly cycles confirm long-term rhythm; daily cycles refine short-term entries.
⚡ Summary
Aspect Description
Purpose Detect and forecast recurring market cycles
Cycle basis Low-to-Low pivot analysis
Visuals Teal historical cycles + Orange forecast line
Forecast Next expected low (price and time)
Ideal timeframe Daily
Main outputs Average cycle length, next projected cycle, visual cycle map
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.
Skrypt open-source
W duchu TradingView twórca tego skryptu udostępnił go jako open-source, aby traderzy mogli analizować i weryfikować jego funkcjonalność. Brawo dla autora! Możesz korzystać z niego za darmo, ale pamiętaj, że ponowna publikacja kodu podlega naszym Zasadom Społeczności.
Wyłączenie odpowiedzialności
Informacje i publikacje przygotowane przez TradingView lub jego użytkowników, prezentowane na tej stronie, nie stanowią rekomendacji ani porad handlowych, inwestycyjnych i finansowych i nie powinny być w ten sposób traktowane ani wykorzystywane. Więcej informacji na ten temat znajdziesz w naszym Regulaminie.