OPEN-SOURCE SCRIPT
Double Moving Average

## 📊 Double Moving Average (DMA)
**General Description:**
An indicator composed of two completely independent Moving Averages (MAs), each configured with its own parameters. Unlike a standard MA, each MA #1 and MA #2 can use a different timeframe, even if the chart displays another timeframe.
---
### **MA #1 - Parameters**
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| **Enable MA #1** | ✓ | Yes/No | Activate/deactivate the first MA |
| **Length** | 50 | 1-500 | Calculation period of the MA |
| **Source** | Close | Open/High/Low/Close | Price source |
| **Offset** | 0 | 0-100 | Shift the curve to the right |
| **Type** | EMA | SMA/EMA/WMA | Type of moving average |
### **MA #2 - Parameters**
Identical to MA #1 but with default **Length: 200**
---
### **Smoothing - Per MA**
Each MA can have its own smoothing:
| Parameter | Options |
|-----------|---------|
| **Enable Smoothing** | Yes/No |
| **Type** | None / SMA / EMA / WMA |
| **Length** | 1-100 |
| **BB StdDev** | 0.1-10 (Bollinger Bands) |
---
### **Timeframe (Period) - Per MA**
Each MA calculates on an independent timeframe:
**Options:** 1min, 2min, 5min, 10min, 15min, 30min, 1hr, 2hr, 4hr, 1day
**"Wait for Close":** Waits for the timeframe candle to close before confirmation
---
### **Main Functions**
1. **`f_convert_timeframe()`** - Converts timeframe formats for Pine Script
2. **`f_calculate_ma()`** - Calculates SMA, EMA, or WMA
3. **`f_apply_smoothing()`** - Applies smoothing if enabled
---
### **Use Cases**
- Display short-term MA (5min) for scalping
- Display long-term MA (1day) for overall trend
- All on the same chart, independent of the displayed timeframe
- Compare two different trend periods simultaneously
**General Description:**
An indicator composed of two completely independent Moving Averages (MAs), each configured with its own parameters. Unlike a standard MA, each MA #1 and MA #2 can use a different timeframe, even if the chart displays another timeframe.
---
### **MA #1 - Parameters**
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| **Enable MA #1** | ✓ | Yes/No | Activate/deactivate the first MA |
| **Length** | 50 | 1-500 | Calculation period of the MA |
| **Source** | Close | Open/High/Low/Close | Price source |
| **Offset** | 0 | 0-100 | Shift the curve to the right |
| **Type** | EMA | SMA/EMA/WMA | Type of moving average |
### **MA #2 - Parameters**
Identical to MA #1 but with default **Length: 200**
---
### **Smoothing - Per MA**
Each MA can have its own smoothing:
| Parameter | Options |
|-----------|---------|
| **Enable Smoothing** | Yes/No |
| **Type** | None / SMA / EMA / WMA |
| **Length** | 1-100 |
| **BB StdDev** | 0.1-10 (Bollinger Bands) |
---
### **Timeframe (Period) - Per MA**
Each MA calculates on an independent timeframe:
**Options:** 1min, 2min, 5min, 10min, 15min, 30min, 1hr, 2hr, 4hr, 1day
**"Wait for Close":** Waits for the timeframe candle to close before confirmation
---
### **Main Functions**
1. **`f_convert_timeframe()`** - Converts timeframe formats for Pine Script
2. **`f_calculate_ma()`** - Calculates SMA, EMA, or WMA
3. **`f_apply_smoothing()`** - Applies smoothing if enabled
---
### **Use Cases**
- Display short-term MA (5min) for scalping
- Display long-term MA (1day) for overall trend
- All on the same chart, independent of the displayed timeframe
- Compare two different trend periods simultaneously
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.