OPEN-SOURCE SCRIPT
Auto-Length Anchored Multiple EMA (Hour-Based)

# Auto-Length Anchored Multiple EMA (Hour-Based)
## Overview
This advanced EMA indicator automatically calculates Exponential Moving Average lengths based on the time elapsed since user-defined anchor dates. Unlike traditional fixed-length EMAs, this indicator dynamically adjusts EMA periods based on actual trading hours, making it ideal for event-based analysis and time-sensitive trading strategies.
## Key Features
### 🎯 **Dual Mode Operation**
- **Auto Mode**: EMA length automatically calculated from anchor date to current time
- **Manual Mode**: Traditional fixed-length EMA calculation
- Switch between modes independently for each EMA
### 📊 **Multiple EMA Support**
- Up to 4 independent EMAs with individual configurations
- Each EMA can have its own anchor date and settings
- Individual enable/disable controls for each EMA
### ⏰ **Smart Time Calculation**
- Accounts for actual trading hours (customizable)
- Weekend exclusion with Saturday trading option (for markets like NSE/BSE)
- Hour multiplier for fine-tuning EMA sensitivity
- Minimum EMA length protection to prevent calculation errors
### 🎨 **Visual Enhancements**
- **Dynamic Fill Colors**: Fill between EMA1 and EMA3 changes color based on price position
- **Customizable Colors**: Individual color settings for each EMA
- **Anchor Visualization**: Optional vertical lines and labels at anchor dates
- **Real-time Table**: Shows current EMA lengths, modes, and values
## Configuration Options
### Trading Session Settings
- **Trading Hours Per Day**: Set your market's trading hours (1-24)
- **Trading Days Per Week**: Configure for different markets (5 for Mon-Fri, 6 for Mon-Sat)
- **Include Saturday**: Enable for markets that trade on Saturday
- **Hour Multiplier**: Fine-tune EMA sensitivity (0.1x to 10x)
### EMA Configuration
- **Anchor Dates**: Set specific start dates for each EMA calculation
- **Manual Lengths**: Override with traditional fixed periods when needed
- **Enable/Disable**: Individual control for each EMA
- **Color Customization**: Personalize appearance for each EMA
### Visual Options
- **Fill Settings**: Toggle and customize fill colors between EMAs
- **Anchor Lines**: Show vertical lines at anchor dates
- **Anchor Labels**: Display formatted anchor date information
- **Length Table**: Real-time display of current EMA parameters
## Use Cases
### 📈 **Event-Based Analysis**
- Anchor EMAs to earnings announcements, policy decisions, or market events
- Track price behavior relative to specific time periods
- Analyze momentum changes from key market catalysts
### 🕐 **Time-Sensitive Trading**
- Perfect for intraday strategies where timing is crucial
- Automatically adjusts to market hours and trading sessions
- Eliminates manual EMA length recalculation
### 🌍 **Multi-Market Support**
- Configurable for different global markets
- Saturday trading support for Asian markets
- Flexible trading hour settings
## Technical Details
### Calculation Method
The indicator calculates trading bars elapsed since anchor date using:
```
Total Trading Bars = (Days Since Anchor × Trading Days Per Week ÷ 7) × Trading Hours Per Day × Hour Multiplier
```
### EMA Formula
Uses standard EMA calculation with dynamically calculated alpha:
```
Alpha = 2 ÷ (Current Length + 1)
EMA = Alpha × Current Price + (1 - Alpha) × Previous EMA
```
### Weekend Handling
- Automatically excludes weekends from calculation
- Optional Saturday inclusion for specific markets
- Accurate trading day counting
## Installation & Setup
1. **Add to Chart**: Apply the indicator to your desired timeframe
2. **Set Anchor Dates**: Configure anchor dates for each EMA you want to use
3. **Adjust Trading Hours**: Set your market's trading session parameters
4. **Customize Appearance**: Choose colors and visual options
5. **Enable Features**: Turn on fills, anchor lines, and information table as needed
## Best Practices
- **Anchor Selection**: Choose significant market events or technical breakouts as anchor points
- **Multiple Timeframes**: Use different anchor dates for short, medium, and long-term analysis
- **Hour Multiplier**: Start with 1.0 and adjust based on market volatility and your trading style
- **Visual Clarity**: Use contrasting colors for different EMAs to improve readability
## Compatibility
- **Pine Script Version**: v6
- **Chart Types**: All chart types supported
- **Timeframes**: Works on all timeframes (optimal on intraday charts)
- **Markets**: Suitable for stocks, forex, crypto, and commodities
## Notes
- Indicator starts calculation from the anchor date forward
- Minimum EMA length prevents calculation errors with very recent anchor dates
- Table display updates in real-time showing current EMA parameters
- Fill colors dynamically change based on price position relative to EMA1
---
*This indicator is perfect for traders who want to combine the power of EMAs with event-driven analysis and precise time-based calculations.*
## Overview
This advanced EMA indicator automatically calculates Exponential Moving Average lengths based on the time elapsed since user-defined anchor dates. Unlike traditional fixed-length EMAs, this indicator dynamically adjusts EMA periods based on actual trading hours, making it ideal for event-based analysis and time-sensitive trading strategies.
## Key Features
### 🎯 **Dual Mode Operation**
- **Auto Mode**: EMA length automatically calculated from anchor date to current time
- **Manual Mode**: Traditional fixed-length EMA calculation
- Switch between modes independently for each EMA
### 📊 **Multiple EMA Support**
- Up to 4 independent EMAs with individual configurations
- Each EMA can have its own anchor date and settings
- Individual enable/disable controls for each EMA
### ⏰ **Smart Time Calculation**
- Accounts for actual trading hours (customizable)
- Weekend exclusion with Saturday trading option (for markets like NSE/BSE)
- Hour multiplier for fine-tuning EMA sensitivity
- Minimum EMA length protection to prevent calculation errors
### 🎨 **Visual Enhancements**
- **Dynamic Fill Colors**: Fill between EMA1 and EMA3 changes color based on price position
- **Customizable Colors**: Individual color settings for each EMA
- **Anchor Visualization**: Optional vertical lines and labels at anchor dates
- **Real-time Table**: Shows current EMA lengths, modes, and values
## Configuration Options
### Trading Session Settings
- **Trading Hours Per Day**: Set your market's trading hours (1-24)
- **Trading Days Per Week**: Configure for different markets (5 for Mon-Fri, 6 for Mon-Sat)
- **Include Saturday**: Enable for markets that trade on Saturday
- **Hour Multiplier**: Fine-tune EMA sensitivity (0.1x to 10x)
### EMA Configuration
- **Anchor Dates**: Set specific start dates for each EMA calculation
- **Manual Lengths**: Override with traditional fixed periods when needed
- **Enable/Disable**: Individual control for each EMA
- **Color Customization**: Personalize appearance for each EMA
### Visual Options
- **Fill Settings**: Toggle and customize fill colors between EMAs
- **Anchor Lines**: Show vertical lines at anchor dates
- **Anchor Labels**: Display formatted anchor date information
- **Length Table**: Real-time display of current EMA parameters
## Use Cases
### 📈 **Event-Based Analysis**
- Anchor EMAs to earnings announcements, policy decisions, or market events
- Track price behavior relative to specific time periods
- Analyze momentum changes from key market catalysts
### 🕐 **Time-Sensitive Trading**
- Perfect for intraday strategies where timing is crucial
- Automatically adjusts to market hours and trading sessions
- Eliminates manual EMA length recalculation
### 🌍 **Multi-Market Support**
- Configurable for different global markets
- Saturday trading support for Asian markets
- Flexible trading hour settings
## Technical Details
### Calculation Method
The indicator calculates trading bars elapsed since anchor date using:
```
Total Trading Bars = (Days Since Anchor × Trading Days Per Week ÷ 7) × Trading Hours Per Day × Hour Multiplier
```
### EMA Formula
Uses standard EMA calculation with dynamically calculated alpha:
```
Alpha = 2 ÷ (Current Length + 1)
EMA = Alpha × Current Price + (1 - Alpha) × Previous EMA
```
### Weekend Handling
- Automatically excludes weekends from calculation
- Optional Saturday inclusion for specific markets
- Accurate trading day counting
## Installation & Setup
1. **Add to Chart**: Apply the indicator to your desired timeframe
2. **Set Anchor Dates**: Configure anchor dates for each EMA you want to use
3. **Adjust Trading Hours**: Set your market's trading session parameters
4. **Customize Appearance**: Choose colors and visual options
5. **Enable Features**: Turn on fills, anchor lines, and information table as needed
## Best Practices
- **Anchor Selection**: Choose significant market events or technical breakouts as anchor points
- **Multiple Timeframes**: Use different anchor dates for short, medium, and long-term analysis
- **Hour Multiplier**: Start with 1.0 and adjust based on market volatility and your trading style
- **Visual Clarity**: Use contrasting colors for different EMAs to improve readability
## Compatibility
- **Pine Script Version**: v6
- **Chart Types**: All chart types supported
- **Timeframes**: Works on all timeframes (optimal on intraday charts)
- **Markets**: Suitable for stocks, forex, crypto, and commodities
## Notes
- Indicator starts calculation from the anchor date forward
- Minimum EMA length prevents calculation errors with very recent anchor dates
- Table display updates in real-time showing current EMA parameters
- Fill colors dynamically change based on price position relative to EMA1
---
*This indicator is perfect for traders who want to combine the power of EMAs with event-driven analysis and precise time-based calculations.*
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.