OPEN-SOURCE SCRIPT
已更新 Market Structure Shift (MSS) [Sword & Shield]

MARKET STRUCTURE SHIFT (MSS) [SWORD & SHIELD]
A clean and focused indicator for identifying Market Structure Shifts in price action.
════════════════════════════════════════════════════════════════════════════════
WHAT IS MARKET STRUCTURE SHIFT (MSS)?
════════════════════════════════════════════════════════════════════════════════
A Market Structure Shift occurs when price breaks a significant swing high or swing low,
indicating a potential change in market direction. This indicator automatically detects
and plots these key levels.
BULLISH MSS: Price breaks above a previous swing high
BEARISH MSS: Price breaks below a previous swing low
════════════════════════════════════════════════════════════════════════════════
FEATURES
════════════════════════════════════════════════════════════════════════════════
CLEAN DISPLAY
- Shows only the last 2 MSS by default (1 bullish + 1 bearish)
- Keeps charts clean and focused on recent structure
- Automatically removes old MSS when new ones appear
CUSTOMIZABLE DETECTION
- Adjustable swing detection (left/right bars)
- Choose break confirmation method (Close or Wick)
- Fixed-length lines (no infinite extension by default)
SMART FILTERING
- Only plots one MSS per direction until opposite MSS occurs
- Prevents duplicate signals in the same direction
- Clear visual distinction between bullish (blue) and bearish (red)
CLEAN LABELS
- Text labels positioned above lines
- No background tooltips for cleaner appearance
- Color-matched to their respective MSS lines
════════════════════════════════════════════════════════════════════════════════
SETTINGS
════════════════════════════════════════════════════════════════════════════════
SWING DETECTION
- Swing Left Bars (default: 2)
- Swing Right Bars (default: 2)
- Higher values = more significant swings detected
BREAK CONFIRMATION
- Close: MSS confirmed when candle closes beyond level
- Wick: MSS confirmed when wick touches beyond level
DISPLAY OPTIONS
- Show Only Last 2 MSS: ON by default (keeps chart clean)
- Extend lines to the right: OFF by default (fixed-length lines)
- Line bars (when not extended): 50 bars (customizable)
════════════════════════════════════════════════════════════════════════════════
HOW IT WORKS
════════════════════════════════════════════════════════════════════════════════
DETECTION LOGIC
1. Identifies swing highs and swing lows using pivot detection
2. Monitors price action for breaks of these levels
3. Confirms break based on selected method (Close or Wick)
4. Plots MSS line at the broken level
FILTERING LOGIC
- Only one MSS per direction is allowed consecutively
- Example: If bullish MSS appears, no new bullish MSS until bearish MSS occurs
- This prevents multiple signals in trending markets
DISPLAY LOGIC
- When "Show Only Last 2 MSS" is enabled:
• Only the most recent bullish MSS is shown
• Only the most recent bearish MSS is shown
• Old MSS are automatically deleted when new ones appear
- When disabled: All historical MSS remain visible
════════════════════════════════════════════════════════════════════════════════
USAGE EXAMPLES
════════════════════════════════════════════════════════════════════════════════
FOR TREND IDENTIFICATION
- Bullish MSS = Potential uptrend beginning
- Bearish MSS = Potential downtrend beginning
- Use in conjunction with other indicators for confirmation
FOR ENTRY SIGNALS
- Wait for MSS to confirm trend change
- Enter on pullback to MSS level
- Use MSS as support/resistance
FOR SCALPING (Lower Timeframes)
- Swing Left/Right Bars: 2-3 (more sensitive)
- Break Confirmation: Close (more reliable)
- Show Only Last 2 MSS: ON (cleaner charts)
FOR SWING TRADING (Higher Timeframes)
- Swing Left/Right Bars: 5-10 (more significant swings)
- Break Confirmation: Close (avoid false breaks)
- Show Only Last 2 MSS: ON or OFF based on preference
════════════════════════════════════════════════════════════════════════════════
VISUAL DESIGN
════════════════════════════════════════════════════════════════════════════════
LINES
- Dashed style for easy identification
- Blue for bullish MSS
- Red for bearish MSS
- Fixed length (50 bars default) for cleaner appearance
LABELS
- "MSS" text positioned above each line
- No background for clean display
- Color-matched to line color
- Small size to avoid chart clutter
════════════════════════════════════════════════════════════════════════════════
CREDITS & LICENSE
════════════════════════════════════════════════════════════════════════════════
© Sword & Shield
This Pine Script code is subject to the terms of the Mozilla Public License 2.0
mozilla.org/MPL/2.0/
A clean and focused indicator for identifying Market Structure Shifts in price action.
════════════════════════════════════════════════════════════════════════════════
WHAT IS MARKET STRUCTURE SHIFT (MSS)?
════════════════════════════════════════════════════════════════════════════════
A Market Structure Shift occurs when price breaks a significant swing high or swing low,
indicating a potential change in market direction. This indicator automatically detects
and plots these key levels.
BULLISH MSS: Price breaks above a previous swing high
BEARISH MSS: Price breaks below a previous swing low
════════════════════════════════════════════════════════════════════════════════
FEATURES
════════════════════════════════════════════════════════════════════════════════
CLEAN DISPLAY
- Shows only the last 2 MSS by default (1 bullish + 1 bearish)
- Keeps charts clean and focused on recent structure
- Automatically removes old MSS when new ones appear
CUSTOMIZABLE DETECTION
- Adjustable swing detection (left/right bars)
- Choose break confirmation method (Close or Wick)
- Fixed-length lines (no infinite extension by default)
SMART FILTERING
- Only plots one MSS per direction until opposite MSS occurs
- Prevents duplicate signals in the same direction
- Clear visual distinction between bullish (blue) and bearish (red)
CLEAN LABELS
- Text labels positioned above lines
- No background tooltips for cleaner appearance
- Color-matched to their respective MSS lines
════════════════════════════════════════════════════════════════════════════════
SETTINGS
════════════════════════════════════════════════════════════════════════════════
SWING DETECTION
- Swing Left Bars (default: 2)
- Swing Right Bars (default: 2)
- Higher values = more significant swings detected
BREAK CONFIRMATION
- Close: MSS confirmed when candle closes beyond level
- Wick: MSS confirmed when wick touches beyond level
DISPLAY OPTIONS
- Show Only Last 2 MSS: ON by default (keeps chart clean)
- Extend lines to the right: OFF by default (fixed-length lines)
- Line bars (when not extended): 50 bars (customizable)
════════════════════════════════════════════════════════════════════════════════
HOW IT WORKS
════════════════════════════════════════════════════════════════════════════════
DETECTION LOGIC
1. Identifies swing highs and swing lows using pivot detection
2. Monitors price action for breaks of these levels
3. Confirms break based on selected method (Close or Wick)
4. Plots MSS line at the broken level
FILTERING LOGIC
- Only one MSS per direction is allowed consecutively
- Example: If bullish MSS appears, no new bullish MSS until bearish MSS occurs
- This prevents multiple signals in trending markets
DISPLAY LOGIC
- When "Show Only Last 2 MSS" is enabled:
• Only the most recent bullish MSS is shown
• Only the most recent bearish MSS is shown
• Old MSS are automatically deleted when new ones appear
- When disabled: All historical MSS remain visible
════════════════════════════════════════════════════════════════════════════════
USAGE EXAMPLES
════════════════════════════════════════════════════════════════════════════════
FOR TREND IDENTIFICATION
- Bullish MSS = Potential uptrend beginning
- Bearish MSS = Potential downtrend beginning
- Use in conjunction with other indicators for confirmation
FOR ENTRY SIGNALS
- Wait for MSS to confirm trend change
- Enter on pullback to MSS level
- Use MSS as support/resistance
FOR SCALPING (Lower Timeframes)
- Swing Left/Right Bars: 2-3 (more sensitive)
- Break Confirmation: Close (more reliable)
- Show Only Last 2 MSS: ON (cleaner charts)
FOR SWING TRADING (Higher Timeframes)
- Swing Left/Right Bars: 5-10 (more significant swings)
- Break Confirmation: Close (avoid false breaks)
- Show Only Last 2 MSS: ON or OFF based on preference
════════════════════════════════════════════════════════════════════════════════
VISUAL DESIGN
════════════════════════════════════════════════════════════════════════════════
LINES
- Dashed style for easy identification
- Blue for bullish MSS
- Red for bearish MSS
- Fixed length (50 bars default) for cleaner appearance
LABELS
- "MSS" text positioned above each line
- No background for clean display
- Color-matched to line color
- Small size to avoid chart clutter
════════════════════════════════════════════════════════════════════════════════
CREDITS & LICENSE
════════════════════════════════════════════════════════════════════════════════
© Sword & Shield
This Pine Script code is subject to the terms of the Mozilla Public License 2.0
mozilla.org/MPL/2.0/
版本注释
minor changes开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。