OPEN-SOURCE SCRIPT
Auto Swing Ruler

Auto Swing Ruler is a visual measurement tool that automatically identifies confirmed price swings and measures each completed leg directly on the chart.
Its purpose is to replace repeated manual use of the measuring tool by displaying compact information for each swing, including movement size, duration, historical rank, and optional volume participation.
The indicator does not generate buy or sell signals. It is designed to help users compare the structure, speed, and relative importance of price swings.
HOW SWINGS ARE DETECTED
The script uses confirmed pivot highs and pivot lows to construct an alternating swing chain.
A pivot is confirmed only after the number of bars selected in the Pivot strength setting has passed on its right side.
When two consecutive pivots are of the same type, the script retains the more extreme value:
- For consecutive pivot highs, the higher pivot is retained.
- For consecutive pivot lows, the lower pivot is retained.
This prevents the swing chain from creating unnecessary same-direction segments.
Higher Pivot strength values identify broader and cleaner swings, while lower values produce more frequent and shorter swing legs.
LEG MEASUREMENTS
Each confirmed swing leg can display the following information:
- Percentage movement or ATR multiples.
- Duration in bars.
- Historical percentile rank.
- Relative volume during the leg.
Example:
+12.4% / 14b / P85 / V1.3x
This means:
- The leg advanced by 12.4%.
- The movement lasted 14 bars.
- Its absolute size ranked at approximately the 85th percentile of the stored completed-leg history.
- Average volume during the leg was approximately 1.3 times the current 50-bar average volume.
Users can choose between two measurement modes:
1. Percent
Displays the percentage change between the beginning and end of the swing leg.
2. ATR multiples
Displays the absolute price movement divided by ATR(14), allowing swing size to be viewed relative to recent volatility.
HISTORICAL PERCENTILE
The script stores the absolute percentage size of up to the most recent 100 finalized legs.
Before adding a newly completed leg to the history, the indicator compares its size with the existing stored legs and calculates its percentile rank.
A reading such as P85 means that the leg was larger than approximately 85% of the stored comparison legs.
The percentile is a descriptive ranking of historical swing size. It is not a probability, success rate, or prediction of future price movement.
VOLUME RATIO
When enabled, the indicator calculates the average volume recorded during the completed leg and compares it with the current 50-bar average volume.
For example:
- V1.5x means average volume during the leg was approximately 1.5 times the reference average.
- V0.8x means average volume during the leg was below the reference average.
The volume field is skipped when usable volume data is unavailable. Volume comparisons may also be less meaningful on markets that provide synthetic, tick-based, or incomplete volume.
PROVISIONAL AND FINALIZED LEGS
A newly detected leg remains provisional until the next opposite pivot is confirmed.
Provisional measurements are prefixed with the ~ symbol because the current same-direction extreme may still be replaced by a more extreme pivot.
For example:
~+6.8% / 9b
When the next opposite pivot is confirmed, the previous leg becomes finalized. Its endpoint, line, and measurement label are then fixed during normal chart operation.
LIVE LEG
The optional dashed live line connects the latest confirmed pivot to the current closing price.
It provides a real-time visual estimate of the movement currently developing after the latest confirmed pivot.
The live leg is not a confirmed swing. Its size, direction, endpoint, and duration can change while price develops.
An optional state label can display the live percentage movement, bar count, and percentile comparison. This label is disabled by default to keep the chart clean.
VISUAL-DENSITY CONTROLS
The indicator includes several options designed to reduce chart clutter:
- Show or hide all completed-leg labels.
- Show or hide movement size.
- Show or hide bar count.
- Show or hide percentile rank.
- Show or hide volume ratio.
- Show or hide the live leg.
- Show or hide the live state label.
- Select label size.
- Limit the number of completed legs displayed on the chart.
- Adjust swing-line width and style.
- Select separate colors for rising and falling legs.
The Visible completed legs setting limits only the number of drawings shown on the chart. Historical leg measurements used by the percentile calculation are stored separately.
The default display shows movement size and bar count, while percentile rank, volume ratio, and the state label are disabled to maintain a cleaner chart.
ALERTS
The indicator provides alert conditions for:
- A newly confirmed swing high.
- A newly confirmed swing low.
- A finalized leg reaching or exceeding the selected Big leg alert percentile.
The Big leg alert requires at least ten finalized legs in the stored history before it can trigger.
REPAINTING AND CONFIRMATION
Auto Swing Ruler uses confirmed pivots.
Because a pivot requires future bars on its right side, swing points appear with a natural delay equal to the selected Pivot strength.
The current provisional leg may extend or change when a more extreme same-direction pivot is confirmed.
The live leg changes continuously because it connects the latest confirmed pivot to the current market price.
After an opposite pivot confirms and a leg becomes finalized, its stored measurement and drawing are no longer modified during normal chart operation.
Changing the symbol, timeframe, Pivot strength, measurement settings, or available chart history causes the script to recalculate its swing structure.
LIMITATIONS
Pivot-based swing detection is inherently delayed and is not intended to identify turning points at the exact moment they occur.
Lower Pivot strength settings may create many small legs in volatile or sideways markets. Higher settings may omit smaller price movements.
ATR measurements use the ATR value available when the leg is finalized rather than an average ATR calculated across the full leg.
The volume ratio compares the leg's average volume with the 50-bar volume average available when the leg is finalized.
Percentile results depend on the completed legs available in the loaded chart history and should not be treated as universal market statistics.
Auto Swing Ruler is a visual measurement and historical-comparison tool. It does not forecast future price direction, place orders, or provide standalone trading recommendations.
Its purpose is to replace repeated manual use of the measuring tool by displaying compact information for each swing, including movement size, duration, historical rank, and optional volume participation.
The indicator does not generate buy or sell signals. It is designed to help users compare the structure, speed, and relative importance of price swings.
HOW SWINGS ARE DETECTED
The script uses confirmed pivot highs and pivot lows to construct an alternating swing chain.
A pivot is confirmed only after the number of bars selected in the Pivot strength setting has passed on its right side.
When two consecutive pivots are of the same type, the script retains the more extreme value:
- For consecutive pivot highs, the higher pivot is retained.
- For consecutive pivot lows, the lower pivot is retained.
This prevents the swing chain from creating unnecessary same-direction segments.
Higher Pivot strength values identify broader and cleaner swings, while lower values produce more frequent and shorter swing legs.
LEG MEASUREMENTS
Each confirmed swing leg can display the following information:
- Percentage movement or ATR multiples.
- Duration in bars.
- Historical percentile rank.
- Relative volume during the leg.
Example:
+12.4% / 14b / P85 / V1.3x
This means:
- The leg advanced by 12.4%.
- The movement lasted 14 bars.
- Its absolute size ranked at approximately the 85th percentile of the stored completed-leg history.
- Average volume during the leg was approximately 1.3 times the current 50-bar average volume.
Users can choose between two measurement modes:
1. Percent
Displays the percentage change between the beginning and end of the swing leg.
2. ATR multiples
Displays the absolute price movement divided by ATR(14), allowing swing size to be viewed relative to recent volatility.
HISTORICAL PERCENTILE
The script stores the absolute percentage size of up to the most recent 100 finalized legs.
Before adding a newly completed leg to the history, the indicator compares its size with the existing stored legs and calculates its percentile rank.
A reading such as P85 means that the leg was larger than approximately 85% of the stored comparison legs.
The percentile is a descriptive ranking of historical swing size. It is not a probability, success rate, or prediction of future price movement.
VOLUME RATIO
When enabled, the indicator calculates the average volume recorded during the completed leg and compares it with the current 50-bar average volume.
For example:
- V1.5x means average volume during the leg was approximately 1.5 times the reference average.
- V0.8x means average volume during the leg was below the reference average.
The volume field is skipped when usable volume data is unavailable. Volume comparisons may also be less meaningful on markets that provide synthetic, tick-based, or incomplete volume.
PROVISIONAL AND FINALIZED LEGS
A newly detected leg remains provisional until the next opposite pivot is confirmed.
Provisional measurements are prefixed with the ~ symbol because the current same-direction extreme may still be replaced by a more extreme pivot.
For example:
~+6.8% / 9b
When the next opposite pivot is confirmed, the previous leg becomes finalized. Its endpoint, line, and measurement label are then fixed during normal chart operation.
LIVE LEG
The optional dashed live line connects the latest confirmed pivot to the current closing price.
It provides a real-time visual estimate of the movement currently developing after the latest confirmed pivot.
The live leg is not a confirmed swing. Its size, direction, endpoint, and duration can change while price develops.
An optional state label can display the live percentage movement, bar count, and percentile comparison. This label is disabled by default to keep the chart clean.
VISUAL-DENSITY CONTROLS
The indicator includes several options designed to reduce chart clutter:
- Show or hide all completed-leg labels.
- Show or hide movement size.
- Show or hide bar count.
- Show or hide percentile rank.
- Show or hide volume ratio.
- Show or hide the live leg.
- Show or hide the live state label.
- Select label size.
- Limit the number of completed legs displayed on the chart.
- Adjust swing-line width and style.
- Select separate colors for rising and falling legs.
The Visible completed legs setting limits only the number of drawings shown on the chart. Historical leg measurements used by the percentile calculation are stored separately.
The default display shows movement size and bar count, while percentile rank, volume ratio, and the state label are disabled to maintain a cleaner chart.
ALERTS
The indicator provides alert conditions for:
- A newly confirmed swing high.
- A newly confirmed swing low.
- A finalized leg reaching or exceeding the selected Big leg alert percentile.
The Big leg alert requires at least ten finalized legs in the stored history before it can trigger.
REPAINTING AND CONFIRMATION
Auto Swing Ruler uses confirmed pivots.
Because a pivot requires future bars on its right side, swing points appear with a natural delay equal to the selected Pivot strength.
The current provisional leg may extend or change when a more extreme same-direction pivot is confirmed.
The live leg changes continuously because it connects the latest confirmed pivot to the current market price.
After an opposite pivot confirms and a leg becomes finalized, its stored measurement and drawing are no longer modified during normal chart operation.
Changing the symbol, timeframe, Pivot strength, measurement settings, or available chart history causes the script to recalculate its swing structure.
LIMITATIONS
Pivot-based swing detection is inherently delayed and is not intended to identify turning points at the exact moment they occur.
Lower Pivot strength settings may create many small legs in volatile or sideways markets. Higher settings may omit smaller price movements.
ATR measurements use the ATR value available when the leg is finalized rather than an average ATR calculated across the full leg.
The volume ratio compares the leg's average volume with the 50-bar volume average available when the leg is finalized.
Percentile results depend on the completed legs available in the loaded chart history and should not be treated as universal market statistics.
Auto Swing Ruler is a visual measurement and historical-comparison tool. It does not forecast future price direction, place orders, or provide standalone trading recommendations.
Open-source script
In true PulseWire spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.
Open-source script
In true PulseWire spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by PulseWire. Read more in the Terms of Use.
