OPEN-SOURCE SCRIPT
Adaptive Support/Resistance EMA Indicator

This indicator automatically identifies and displays the optimal Exponential Moving Average (EMA) period for the current market conditions by analyzing how well different EMAs act as support or resistance levels.
How It Works
Adaptive Period Selection:
The indicator tests 33 different EMA periods (ranging from 5 to 400, including Fibonacci numbers like 8, 13, 21, 34, 55, 89, 144, 233, 377) and scores each based on how effectively it functions as support or resistance.
Intelligent Scoring System:
Each EMA is evaluated using three key metrics:
Respect Rate - Percentage of time price stays on the correct side of the EMA (above for support, below for resistance)
Successful Bounces - Number of times price approached the EMA and reversed without breaking through
Break Severity - Penalties for failed breaks, weighted by both depth and duration of the violation
Trend-Aware Behavior:
Uptrend (price > 50 EMA): Finds the EMA that best acts as a support floor below price
Downtrend (price < 50 EMA): Finds the EMA that best acts as a resistance ceiling above price
Adaptive Features:
Dynamic Lookback: Automatically adjusts analysis period (50-200 bars) based on market volatility
Sticky Selection: Won't switch EMAs unless new choice shows significant improvement (8% threshold by default)
Update Frequency: Recalculates every 20 bars or immediately during high volatility periods
Visual Elements
EMA Display:
Green line = Support (in uptrends)
Red line = Resistance (in downtrends)
Optional glow effect for enhanced visibility
Optional fill between price and EMA
Labels:
Shows "SUP [period]" or "RES [period]" when the selected EMA changes
Markers appear only when there's a meaningful change
Info Table:
Displays real-time statistics:
Current EMA period
Role (Support or Resistance)
Adaptive lookback length
Number of successful bounces
Number of breaks
Break severity score (color-coded: green < 5, yellow 5-20, red > 20)
Key Advantages
No manual EMA period selection needed
Adapts to changing market conditions automatically
Considers both bounce quality and break severity
Reduces whipsaws through sticky selection logic
Provides transparency with detailed performance metrics
Settings
Performance Settings:
Min/Max Lookback: Range for adaptive analysis window
Update Frequency: How often to recalculate (higher = faster performance)
Sticky Threshold: Required improvement % to switch EMAs
Detection Settings:
Touch Threshold: How close price must get to count as a "touch"
Bounce Window: Bars to confirm a successful bounce vs break
Visual Settings:
Customizable support/resistance colors
Toggle glow and fill effects
Show/hide info table and change markers
How It Works
Adaptive Period Selection:
The indicator tests 33 different EMA periods (ranging from 5 to 400, including Fibonacci numbers like 8, 13, 21, 34, 55, 89, 144, 233, 377) and scores each based on how effectively it functions as support or resistance.
Intelligent Scoring System:
Each EMA is evaluated using three key metrics:
Respect Rate - Percentage of time price stays on the correct side of the EMA (above for support, below for resistance)
Successful Bounces - Number of times price approached the EMA and reversed without breaking through
Break Severity - Penalties for failed breaks, weighted by both depth and duration of the violation
Trend-Aware Behavior:
Uptrend (price > 50 EMA): Finds the EMA that best acts as a support floor below price
Downtrend (price < 50 EMA): Finds the EMA that best acts as a resistance ceiling above price
Adaptive Features:
Dynamic Lookback: Automatically adjusts analysis period (50-200 bars) based on market volatility
Sticky Selection: Won't switch EMAs unless new choice shows significant improvement (8% threshold by default)
Update Frequency: Recalculates every 20 bars or immediately during high volatility periods
Visual Elements
EMA Display:
Green line = Support (in uptrends)
Red line = Resistance (in downtrends)
Optional glow effect for enhanced visibility
Optional fill between price and EMA
Labels:
Shows "SUP [period]" or "RES [period]" when the selected EMA changes
Markers appear only when there's a meaningful change
Info Table:
Displays real-time statistics:
Current EMA period
Role (Support or Resistance)
Adaptive lookback length
Number of successful bounces
Number of breaks
Break severity score (color-coded: green < 5, yellow 5-20, red > 20)
Key Advantages
No manual EMA period selection needed
Adapts to changing market conditions automatically
Considers both bounce quality and break severity
Reduces whipsaws through sticky selection logic
Provides transparency with detailed performance metrics
Settings
Performance Settings:
Min/Max Lookback: Range for adaptive analysis window
Update Frequency: How often to recalculate (higher = faster performance)
Sticky Threshold: Required improvement % to switch EMAs
Detection Settings:
Touch Threshold: How close price must get to count as a "touch"
Bounce Window: Bars to confirm a successful bounce vs break
Visual Settings:
Customizable support/resistance colors
Toggle glow and fill effects
Show/hide info table and change markers
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.