PROTECTED SOURCE SCRIPT

Position Manager DCA by MFC

41
# 📊 Advanced Position Manager with DCA & Multi-TP

**Professional position tracking indicator with automatic DCA calculation, multiple take-profits, dynamic risk management, and comprehensive alerts system.**

---

## 🎯 KEY FEATURES

### 📍 **Multi-Position Management (10 Slots)**
- Track up to 10 positions simultaneously across different symbols
- Automatic symbol detection (works on any pair/exchange)
- Support for both LONG and SHORT positions
- Visual position lines with customizable colors and styles

### 💰 **DCA (Dollar Cost Averaging) - AUTOMATIC CALCULATION**
- Support for up to 3 entries per position (Entry 1 + DCA 2 + DCA 3)
- **Automatic weighted average entry price calculation**
- Manual PEPP (Price Entry Averaged Weighted) override option for exact exchange synchronization
- Dynamic capital tracking (sums all entries automatically)

**Example:**
```
Entry 1: $50,000 with $1,000
DCA 2: $48,000 with $500
DCA 3: $46,000 with $500
─────────────────────────────
Auto PEPP: $48,500
Total Capital: $2,000
```

### 🎯 **Multiple Take-Profit Levels (3 TPs)**
- Configure 3 independent take-profit levels per position
- Customizable % of position to close at each TP level
- Default distribution: 30% / 40% / 30%
- Individual PnL calculation for each TP
- Total cumulative PnL display

**Visual representation:**
- TP1: Light orange line (30% exit)
- TP2: Medium orange line (40% exit)
- TP3: Dark orange line (30% exit)

### 🛡️ **Advanced Risk Management**

#### **Liquidation Calculator**
- Real-time liquidation price calculation
- Support for additional margin to push liquidation further
- Works with leverages from 1x to 125x
- Shows both:
- **Static risk:** Distance from entry to liquidation
- **Dynamic risk:** Distance from current price to liquidation

#### **Stop Danger Feature** ⚠️
- **Unique metric:** Calculates exactly how much additional capital you need to reduce liquidation risk to ~0%
- Formula: `(Total Capital × (Leverage - 1)) - Current Additional Margin`
- Helps you plan your risk management proactively

**Example:**
```
Capital: $1,000
Leverage: 10x
Current Margin: $0
────────────────────
Stop Danger: $9,000 needed for ~0% risk
```

### 📈 **Comprehensive Information Table**

The table displays (all customizable):

**Position Metrics:**
- **PnL Actual:** Current floating P&L in USD + % from entry
- **PnL TP1/TP2/TP3:** Individual profit at each TP + % move needed
- **TOTAL TPs:** Cumulative profit if all TPs hit
- **Liquidation Risk:** % to liquidation (static + dynamic)
- **Stop Danger:** Additional capital needed for safety
- **PnL at SL:** Loss if stop loss hits
- **Risk/Reward Ratio:** Calculated automatically

**Reference Levels:**
- Daily Open (D)
- Weekly Open (W)
- Monthly Open (M)
- Yearly Open (Y)
- All-Time High (ATH) - auto-detected

**Visual markers:** Colored dots mark the exact opening candle of each period

### 🎨 **Customization Options**

**Lines:**
- Customizable colors for Entry, TP1, TP2, TP3, SL, Liquidation
- Line width adjustment (1-5)
- Line styles: Solid, Dotted, Dashed

**Reference Levels:**
- Individual color settings for D/W/M/Y/ATH
- Toggle: "Show Only Labels" (hide lines, keep labels for cleaner charts)
- Circle markers at period opening

**Table:**
- 4 position options (Top/Bottom - Left/Right)
- 3 font sizes (Small, Normal, Large)
- **Solid background toggle** for better readability
- Show/hide individual metrics
- Customizable labels for each metric

### 🔔 **Smart Alert System**

**One alert to rule them all!**
- Set ONE alert: "Any function call"
- Configure which alerts you want in indicator settings
- Notifications sent automatically when conditions are met

**Available Alerts:**
- ✅ TP1 Reached
- ✅ TP2 Reached
- ✅ TP3 Reached
- ✅ Stop Loss Hit
- ✅ Entry Price Reached
- ⚠️ Near Liquidation (< 5%)
- 📊 Daily Open Cross
- 📊 Weekly Open Cross
- 📊 Monthly Open Cross
- 📊 Yearly Open Cross
- 🚀 New ATH

**Messages include:** Symbol ticker + current price

---

## 🚀 HOW TO USE

### **Basic Setup (Single Entry)**

1. **Enable Position Slot**
- Activate Position 1 (or any slot)
- Enter symbol base (e.g., "BTC", "ETH", "HYPE")
- Select direction: Long or Short

2. **Configure Entry**
- Price Entry 1: Your entry price
- Capital Entry 1: Your position size in USD

3. **Set Take Profits**
- TP1: First target (default 30% close)
- TP2: Second target (default 40% close)
- TP3: Final target (default 30% close)

4. **Risk Management**
- Stop Loss: Optional protective stop
- Additional Margin: Extra capital to reduce liquidation risk
- Leverage: 1x to 125x

### **Advanced Setup (With DCA)**

1. **After your first entry, price drops...**

2. **Activate DCA 2:**
- ☑ Activate DCA 2
- Price DCA 2: Second entry price
- Capital DCA 2: Additional capital in USD

3. **Add DCA 3 if needed:**
- ☑ Activate DCA 3
- Price DCA 3: Third entry price
- Capital DCA 3: Additional capital in USD

4. **Indicator automatically calculates:**
- ✅ Weighted average entry price
- ✅ Total capital invested
- ✅ New liquidation price
- ✅ Updated PnL for all TPs

### **Manual PEPP Override (Optional)**

If your exchange shows a slightly different average entry price (due to fees):

1. ☑ Enable "Use Manual PEPP"
2. Enter exact PEPP from exchange (e.g., 31.786)
3. Indicator uses this exact price for all calculations
4. Capital total remains the sum of all entries

### **Setting Up Alerts**

1. Add indicator to chart
2. Click ⏰ (Alert icon)
3. Condition: Select indicator → "Any alert() function call"
4. In indicator settings, enable desired alerts:
- ☑ Alert TP1 Reached
- ☑ Alert Stop Loss
- ☑ Alert Near Liquidation
- etc.
5. Configure notifications (App, Email, SMS, Webhook)
6. Done! One alert monitors everything

---

## 📊 CALCULATIONS EXPLAINED

### **Weighted Average Entry Price (PEPP)**
```
PEPP = (Price1 × Capital1 + Price2 × Capital2 + Price3 × Capital3) / (Capital1 + Capital2 + Capital3)
```

### **Liquidation Price**
```
For LONG:
Liquidation = Entry × (1 - ((Total Capital + Additional Margin) / (Total Capital × Leverage)))

For SHORT:
Liquidation = Entry × (1 + ((Total Capital + Additional Margin) / (Total Capital × Leverage)))
```

### **PnL Calculation**
```
Position Size = Capital × Leverage
Price Change % = (Exit - Entry) / Entry [for LONG]
Price Change % = (Entry - Exit) / Entry [for SHORT]
PnL = Position Size × Price Change %
```

### **Partial PnL (for TPs)**
```
PnL TP1 = PnL at TP1 price × (TP1 % / 100)
PnL TP2 = PnL at TP2 price × (TP2 % / 100)
PnL TP3 = PnL at TP3 price × (TP3 % / 100)
Total = PnL TP1 + PnL TP2 + PnL TP3
```

### **Stop Danger**
```
Stop Danger = (Total Capital × (Leverage - 1)) - Current Additional Margin
```
Shows how much MORE margin you need to add for ~0% liquidation risk.

---

## 💡 PRO TIPS

### **DCA Strategy**
- Plan your DCA levels in advance based on support zones
- Use Fibonacci retracements to space your entries
- Keep capital distribution in mind (e.g., 50% / 30% / 20%)
- Monitor "Stop Danger" to know when to add margin

### **TP Distribution**
- Conservative: 50% / 30% / 20% (secure early profits)
- Balanced: 30% / 40% / 30% (default)
- Aggressive: 20% / 30% / 50% (hold for bigger moves)

### **Risk Management**
- Always check "Liquidation Risk" before entering
- Use "Stop Danger" to plan emergency capital
- Dynamic risk shows real-time exposure as price moves
- Consider adding margin when dynamic risk < -10%

### **Multi-Position Tracking**
- Use different slots for different strategies
- Slot 1-3: Active swing trades
- Slot 4-6: DCA positions
- Slot 7-10: Long-term holds

### **Reference Levels**
- Enable "Show Only Labels" when using many indicators
- Use Daily/Weekly opens for intraday bias
- Monthly/Yearly opens for macro trend confirmation
- ATH tracking for breakout opportunities

---

## ⚙️ TECHNICAL SPECIFICATIONS

- **Pine Script Version:** v6
- **Overlay:** True (draws on price chart)
- **Maximum Positions:** 10 simultaneous
- **Leverage Range:** 1x - 125x
- **DCA Levels:** Up to 3 entries per position
- **Take-Profit Levels:** 3 per position
- **Reference Levels:** 5 (D, W, M, Y, ATH)
- **Alert Types:** 11 different conditions

---

## 🎓 USE CASES

### **Futures Trading**
- Track leveraged positions with accurate liquidation prices
- DCA into positions during dips
- Set multiple TPs to scale out gradually
- Monitor dynamic risk as price moves

### **Spot + DCA**
- Perfect for dollar-cost averaging into spot positions
- Track your average entry as you add more
- Set profit targets based on your DCA average
- No liquidation risk (can still track for reference)

### **Portfolio Management**
- Monitor up to 10 different positions across exchanges
- All calculations update in real-time
- Reference levels help with broader market context
- Centralized view of all your active trades

### **Risk Analysis**
- Calculate exact capital needed for safety (Stop Danger)
- Compare static vs dynamic liquidation risk
- Plan position sizing based on R/R ratios
- Set protective alerts for near-liquidation scenarios

---

## 📝 IMPORTANT NOTES

### **Symbol Detection**
- Enter only the BASE symbol (e.g., "BTC", not "BTCUSDT")
- Works automatically on any pair/exchange
- Case-insensitive matching
- Compatible with futures, spot, and perpetual contracts

### **Leverage & Liquidation**
- Calculations assume standard perpetual contract mechanics
- Additional margin effectively reduces your leverage
- Results may vary slightly between exchanges due to:
- Different maintenance margin requirements
- Funding rate impacts
- Exchange-specific fee structures

### **Manual PEPP**
- Use when you need exact synchronization with exchange
- Helpful when fees create small discrepancies
- Capital total always remains sum of actual entries
- Override only affects entry price, not capital

### **Alerts**
- Trigger on bar close for stability
- One alert covers all enabled conditions
- Manage which alerts fire from indicator settings
- No need to delete/recreate alerts when toggling conditions

---

## 🔄 UPDATES & CHANGELOG

**Current Version Features:**
✅ 10-slot position management
✅ Automatic DCA with weighted averaging
✅ Manual PEPP override option
✅ 3 take-profit levels per position
✅ Dynamic liquidation risk calculation
✅ Stop Danger metric
✅ Comprehensive alert system
✅ Reference level tracking (D/W/M/Y/ATH)
✅ Customizable table and visuals
✅ Solid background option for table

---

## 📞 SUPPORT

**Common Issues:**

**Q: Lines not showing?**
A: Make sure position is enabled and symbol matches current chart

**Q: Different PEPP than exchange?**
A: Use "Manual PEPP Override" to input exact exchange value

**Q: Alerts not working?**
A: Ensure you created alert with "Any alert() function call" condition

**Q: Liquidation seems wrong?**
A: Check that leverage and additional margin are correct

**Q: Multiple positions not working?**
A: Each slot needs unique symbol detection (base ticker only)

---

## 🏆 BEST PRACTICES

1. **Always use Stop Loss** for leveraged positions
2. **Monitor Stop Danger** before entering high-leverage trades
3. **Set realistic TP levels** based on support/resistance
4. **Use DCA strategically** at planned support zones
5. **Enable Near Liquidation alert** (< 5%) as safety net
6. **Check dynamic risk** regularly as market moves
7. **Keep capital reserved** for potential margin additions
8. **Document your entries** using the exact prices
9. **Review R/R ratios** before entering trades
10. **Use reference levels** for market context

---

## 📚 GLOSSARY

- **PEPP:** Price Entry Averaged Weighted (Precio de Entrada Promedio Ponderado)
- **DCA:** Dollar Cost Averaging
- **TP:** Take Profit
- **SL:** Stop Loss
- **PnL:** Profit and Loss
- **R/R:** Risk/Reward Ratio
- **ATH:** All-Time High
- **Stop Danger:** Additional capital needed for ~0% liquidation risk

---

**Made with ❤️ for serious traders | Compatible with all TradingView plans**

*This indicator does not provide financial advice. Always do your own research and manage your risk appropriately.*

Отказ от ответственности

Информация и публикации не предназначены для предоставления и не являются финансовыми, инвестиционными, торговыми или другими видами советов или рекомендаций, предоставленных или одобренных TradingView. Подробнее читайте в Условиях использования.