OPEN-SOURCE SCRIPT
Inside Swings

Overview
The Inside Swings indicator identifies and visualizes "inside swing" patterns in price action. These patterns occur when price creates a series of pivots that form overlapping ranges, indicating potential consolidation or reversal zones.
What are Inside Swings?
Inside swings are specific pivot patterns where:
- HLHL Pattern: High-Low-High-Low sequence where the first high is higher than the second high, and the first low is lower than the second low
- LHLH Pattern: Low-High-Low-High sequence where the first low is lower than the second low, and the first high is higher than the second high
Here an Example

These patterns create overlapping price ranges that often act as:
- Support/Resistance zones
- Consolidation areas
- Potential reversal points
- Breakout levels
Levels From the Created Range

Input Parameters
Core Settings
- Pivot Lookback Length (default: 5): Number of bars on each side to confirm a pivot high/low
- Max Boxes (default: 100): Maximum number of patterns to display on chart
Extension Settings
- Extend Lines: Enable/disable line extensions - this extends the Extremes of the Swings to where a new Swing Started or Extended Right for the Latest Inside Swings
- Show High 1 Line: Display first high/low extension line
- Show High 2 Line: Display second high/low extension line
- Show Low 1 Line: Display first low/high extension line
- Show Low 2 Line: Display second low/high extension line
Visual Customization
Box Colors
- HLHL Box Color: Color for HLHL pattern boxes (default: green)
- HLHL Border Color: Border color for HLHL boxes
- LHLH Box Color: Color for LHLH pattern boxes (default: red)
- LHLH Border Color: Border color for LHLH boxes
Line Colors
- HLHL Line Color: Extension line color for HLHL patterns
- LHLH Line Color: Extension line color for LHLH patterns
- Line Width: Thickness of extension lines (1-5)
Pattern Detection Logic
HLHL Pattern (Bullish Inside Swing)
Condition: High1 > High2 AND Low1 < Low2
Sequence: High → Low → High → Low
Visual: Two overlapping boxes with first range encompassing second
Detection Criteria:
1. Last 4 pivots form High-Low-High-Low sequence
2. Fourth pivot (first high) > Second pivot (second high)
3. Third pivot (first low) < Last pivot (second low)
LHLH Pattern (Bearish Inside Swing)
Condition: Low1 < Low2 AND High1 > High2
Sequence: Low → High → Low → High
Visual: Two overlapping boxes with first range encompassing second
Detection Criteria:
1. Last 4 pivots form Low-High-Low-High sequence
2. Fourth pivot (first low) < Second pivot (second low)
3. Third pivot (first high) > Last pivot (second high)
Visual Elements
Boxes
- Box 1: Spans from first pivot to last pivot (larger range)
- Box 2: Spans from third pivot to last pivot (smaller range)
- Overlap: The intersection of both boxes represents the inside swing zone
Extension Lines
- High 1 Line: Horizontal line at first high/low level
- High 2 Line: Horizontal line at second high/low level
- Low 1 Line: Horizontal line at first low/high level
- Low 2 Line: Horizontal line at second low/high level
Line Extension Behavior
- Historical Patterns: Lines extend until the next pattern starts
- Latest Pattern: Lines extend to the right edge of chart
- Dynamic Updates: All lines are redrawn on each bar for accuracy
Trading Applications
Support/Resistance Levels
Inside swing levels often act as:
- Dynamic support/resistance
- Breakout confirmation levels
- Reversal entry points
Pattern Interpretation
- HLHL Patterns: Potential bullish continuation or reversal
- LHLH Patterns: Potential bearish continuation or reversal
- Overlap Zone: Key area for price interaction
Entry Strategies
1. Breakout Strategy: Enter on break above/below inside swing levels
2. Reversal Strategy: Enter on bounce from inside swing levels
3. Range Trading: Trade between inside swing levels
Technical Implementation
Data Structures
type InsideSwing
int startBar // First pivot bar
int endBar // Last pivot bar
string patternType // "HLHL" or "LHLH"
float high1 // First high/low
float low1 // First low/high
float high2 // Second high/low
float low2 // Second low/high
box box1 // First box
box box2 // Second box
line high1Line // High 1 extension line
line high2Line // High 2 extension line
line low1Line // Low 1 extension line
line low2Line // Low 2 extension line
bool isLatest // Latest pattern flag
Memory Management
- Pattern Storage: Array-based storage with automatic cleanup
- Pivot Tracking: Maintains last 4 pivots for pattern detection
- Resource Cleanup: Automatically removes oldest patterns when limit exceeded
Performance Optimization
- Duplicate Prevention: Checks for existing patterns before creation
- Efficient Redraw: Only redraws lines when necessary
- Memory Limits: Configurable maximum pattern count
Usage Tips
Best Practices
1. Combine with Volume: Use volume confirmation for breakouts
2. Multiple Timeframes: Check higher timeframes for context
3. Risk Management: Set stops beyond inside swing levels
4. Pattern Validation: Wait for confirmation before entering
Common Scenarios
- Consolidation Breakouts: Inside swings often precede significant moves
- Reversal Zones: Failed breakouts at inside swing levels
- Trend Continuation: Inside swings in trending markets
Limitations
- Lagging Indicator: Patterns form after completion
- False Signals: Not all inside swings lead to significant moves
- Market Dependent: Effectiveness varies by market conditions
Customization Options
Visual Adjustments
- Modify colors for different market conditions
- Adjust line widths for visibility
- Enable/disable specific elements
Detection Sensitivity
- Increase pivot length for smoother patterns
- Decrease for more sensitive detection
- Balance between noise and signal
Display Management
- Control maximum pattern count
- Adjust cleanup frequency
- Manage memory usage
Conclusion
The Inside Swings indicator provides a systematic approach to identifying consolidation and potential reversal zones in price action. By visualizing overlapping pivot ranges
The indicator's strength lies in its ability to:
- Identify key price levels automatically
- Provide visual context for market structure
- Offer flexible customization options
- Maintain performance through efficient memory management
The Inside Swings indicator identifies and visualizes "inside swing" patterns in price action. These patterns occur when price creates a series of pivots that form overlapping ranges, indicating potential consolidation or reversal zones.
What are Inside Swings?
Inside swings are specific pivot patterns where:
- HLHL Pattern: High-Low-High-Low sequence where the first high is higher than the second high, and the first low is lower than the second low
- LHLH Pattern: Low-High-Low-High sequence where the first low is lower than the second low, and the first high is higher than the second high
Here an Example
These patterns create overlapping price ranges that often act as:
- Support/Resistance zones
- Consolidation areas
- Potential reversal points
- Breakout levels
Levels From the Created Range
Input Parameters
Core Settings
- Pivot Lookback Length (default: 5): Number of bars on each side to confirm a pivot high/low
- Max Boxes (default: 100): Maximum number of patterns to display on chart
Extension Settings
- Extend Lines: Enable/disable line extensions - this extends the Extremes of the Swings to where a new Swing Started or Extended Right for the Latest Inside Swings
- Show High 1 Line: Display first high/low extension line
- Show High 2 Line: Display second high/low extension line
- Show Low 1 Line: Display first low/high extension line
- Show Low 2 Line: Display second low/high extension line
Visual Customization
Box Colors
- HLHL Box Color: Color for HLHL pattern boxes (default: green)
- HLHL Border Color: Border color for HLHL boxes
- LHLH Box Color: Color for LHLH pattern boxes (default: red)
- LHLH Border Color: Border color for LHLH boxes
Line Colors
- HLHL Line Color: Extension line color for HLHL patterns
- LHLH Line Color: Extension line color for LHLH patterns
- Line Width: Thickness of extension lines (1-5)
Pattern Detection Logic
HLHL Pattern (Bullish Inside Swing)
Condition: High1 > High2 AND Low1 < Low2
Sequence: High → Low → High → Low
Visual: Two overlapping boxes with first range encompassing second
Detection Criteria:
1. Last 4 pivots form High-Low-High-Low sequence
2. Fourth pivot (first high) > Second pivot (second high)
3. Third pivot (first low) < Last pivot (second low)
LHLH Pattern (Bearish Inside Swing)
Condition: Low1 < Low2 AND High1 > High2
Sequence: Low → High → Low → High
Visual: Two overlapping boxes with first range encompassing second
Detection Criteria:
1. Last 4 pivots form Low-High-Low-High sequence
2. Fourth pivot (first low) < Second pivot (second low)
3. Third pivot (first high) > Last pivot (second high)
Visual Elements
Boxes
- Box 1: Spans from first pivot to last pivot (larger range)
- Box 2: Spans from third pivot to last pivot (smaller range)
- Overlap: The intersection of both boxes represents the inside swing zone
Extension Lines
- High 1 Line: Horizontal line at first high/low level
- High 2 Line: Horizontal line at second high/low level
- Low 1 Line: Horizontal line at first low/high level
- Low 2 Line: Horizontal line at second low/high level
Line Extension Behavior
- Historical Patterns: Lines extend until the next pattern starts
- Latest Pattern: Lines extend to the right edge of chart
- Dynamic Updates: All lines are redrawn on each bar for accuracy
Trading Applications
Support/Resistance Levels
Inside swing levels often act as:
- Dynamic support/resistance
- Breakout confirmation levels
- Reversal entry points
Pattern Interpretation
- HLHL Patterns: Potential bullish continuation or reversal
- LHLH Patterns: Potential bearish continuation or reversal
- Overlap Zone: Key area for price interaction
Entry Strategies
1. Breakout Strategy: Enter on break above/below inside swing levels
2. Reversal Strategy: Enter on bounce from inside swing levels
3. Range Trading: Trade between inside swing levels
Technical Implementation
Data Structures
type InsideSwing
int startBar // First pivot bar
int endBar // Last pivot bar
string patternType // "HLHL" or "LHLH"
float high1 // First high/low
float low1 // First low/high
float high2 // Second high/low
float low2 // Second low/high
box box1 // First box
box box2 // Second box
line high1Line // High 1 extension line
line high2Line // High 2 extension line
line low1Line // Low 1 extension line
line low2Line // Low 2 extension line
bool isLatest // Latest pattern flag
Memory Management
- Pattern Storage: Array-based storage with automatic cleanup
- Pivot Tracking: Maintains last 4 pivots for pattern detection
- Resource Cleanup: Automatically removes oldest patterns when limit exceeded
Performance Optimization
- Duplicate Prevention: Checks for existing patterns before creation
- Efficient Redraw: Only redraws lines when necessary
- Memory Limits: Configurable maximum pattern count
Usage Tips
Best Practices
1. Combine with Volume: Use volume confirmation for breakouts
2. Multiple Timeframes: Check higher timeframes for context
3. Risk Management: Set stops beyond inside swing levels
4. Pattern Validation: Wait for confirmation before entering
Common Scenarios
- Consolidation Breakouts: Inside swings often precede significant moves
- Reversal Zones: Failed breakouts at inside swing levels
- Trend Continuation: Inside swings in trending markets
Limitations
- Lagging Indicator: Patterns form after completion
- False Signals: Not all inside swings lead to significant moves
- Market Dependent: Effectiveness varies by market conditions
Customization Options
Visual Adjustments
- Modify colors for different market conditions
- Adjust line widths for visibility
- Enable/disable specific elements
Detection Sensitivity
- Increase pivot length for smoother patterns
- Decrease for more sensitive detection
- Balance between noise and signal
Display Management
- Control maximum pattern count
- Adjust cleanup frequency
- Manage memory usage
Conclusion
The Inside Swings indicator provides a systematic approach to identifying consolidation and potential reversal zones in price action. By visualizing overlapping pivot ranges
The indicator's strength lies in its ability to:
- Identify key price levels automatically
- Provide visual context for market structure
- Offer flexible customization options
- Maintain performance through efficient memory management
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.