Swing LevelsSwing Levels is a market structure indicator that identifies confirmed swing highs and swing lows and converts them into horizontal reference levels on the chart.
The purpose of the indicator is to visualize recent structural turning points and help observe how price interacts with those areas over time.
The script also connects consecutive pivots with diagonal structure lines to illustrate the progression of swings within the current market movement.
Calculation concept
The indicator detects structural pivots using a swing detection algorithm based on two parameters: pivot depth and price deviation.
Pivot Depth defines the number of surrounding bars used to determine whether a local high or low qualifies as a swing point.
Pivot Deviation defines the minimum price distance required between swings. This helps filter small fluctuations and focuses on structurally meaningful movements.
When a new swing is confirmed, the indicator:
1. identifies whether the pivot is a swing high or swing low,
2. records the price level and bar index of that pivot,
3. draws a horizontal level at the pivot price,
4. connects the new pivot to the previous pivot with a diagonal structure line.
Horizontal levels represent areas where price previously changed direction with sufficient momentum to form a structural turning point.
What the indicator displays
The indicator can display three structural elements:
Horizontal swing levels
Each confirmed pivot becomes a horizontal level. These levels represent prices where the market previously reacted and formed a structural reversal.
Diagonal structure lines
Consecutive pivots are connected by diagonal lines to visualize the sequence of price swings and structural development.
Recent extreme reference lines
Optional dashed lines can extend from recent structural extremes to provide a reference for the most recent swing highs and lows.
Horizontal levels are dynamically colored depending on their relation to the current price:
• levels above the current price represent potential overhead resistance areas
• levels below the current price represent potential support areas
Inputs
Pivot Depth
Controls the sensitivity of swing detection by defining the number of bars used to identify pivots.
Pivot Deviation (ticks)
Defines the minimum price deviation required for a pivot to be considered significant.
Max Horizontal Levels
Limits the number of horizontal levels maintained on the chart.
Extend Levels Right
Extends confirmed levels forward as new bars appear.
Diagonal Line Thickness
Controls the visual thickness of structure lines.
Max Diagonal Objects
Limits the number of diagonal structure elements stored by the indicator.
Show Last Extremes Lines
Displays reference lines from the most recent swing extremes.
Practical use
Swing Levels may be used to:
• observe where price previously reversed or reacted
• monitor how price behaves when revisiting prior structural areas
• track the sequence of higher highs, lower highs, higher lows, and lower lows
• combine structural levels with independent analytical methods such as price action or risk management
The indicator highlights historical structural points and does not attempt to forecast future price movement.
Scope
This script visualizes market structure derived from confirmed swing points.
It does not generate automated trading signals and does not define entry or exit conditions.
The indicator is intended as a structural analysis tool that can complement other analytical approaches.
مؤشر Pine Script®






















