1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.
Source Code
71 lines of Pine Script v6 from src/zigzag-swing-cycle-avg-length.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.
ZigZag Swing Cycle Average utilizes TradingView's built-in ZigZag library to detect pivot legs based on configurable percentage deviation thresholds and depth parameters. On the latest bar, the script calculates the total bars, number of cycles, and average cycle lengths for both upward and downward swings. It presents these analytics in a clean summary table positioned in the bottom-right corner while optionally rendering the ZigZag lines directly on the price chart.
Average cycle length statistics for up and down legs
Summary table dashboard displaying bar counts and cycle metrics
Configurable ZigZag deviation threshold and depth settings
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Deviation threshold %
float
3.0
devThreshold
Depth
int
12
depth
Allow last in-progress leg
bool
false
allowExtendLast
Show ZigZag
bool
true
showZigZag
Line color
color
color.blue
lineColor
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.
This indicator classifies each bar as bull, bear, or sideways from a rolling log return compared with adjustable percentage thresholds. It paints a regime ribbon on the price chart, shows a current-regime banner, and labels state changes after a minimum hold.
This indicator overlays an intraday SPX and ES chart with a midnight session range, regular-trading-hours opening levels, and a VWAP projection box. It draws the midnight high, mid, and low, flags edge rejections within an absolute tolerance, and plots optiona
TradersPost Trading Checklist is an overlay indicator that evaluates a suite of popular technical conditions for long and short trade setups. It checks session-anchored VWAP, fast and slow EMA alignments and crosses, 200 SMA, RSI overbought or oversold conditi
This indicator classifies the market into gamma regime types (negative gamma trend, positive gamma mean-reversion, or transition) by calculating a composite score based on daily ATR ratios, session VWAP crossover frequencies, and opening range displacement. It
Calculates exponential moving averages for fast, pivot, and slow lengths along with optional 50, 100, and 200 simple moving average context lines. It visualizes bullish and bearish ribbon fills on the main price chart alongside MACD calculations to generate ea
Apex Trend & Liquidity Master calculates a trend cloud using customizable moving averages expanded by a volatility multiplier directly on the main price chart. It identifies dynamic support and resistance liquidity zones from swing high and low pivots, extendi