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
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน