OPEN-SOURCE SCRIPT
FPT - DCA Model

FPT - DCA Model is a simple but powerful tool to backtest a weekly “buy the dip” DCA plan with dynamic position sizing and partial profit-taking.
🔹 Core Idea
- Invest a fixed amount every week (on Friday closes)
- Buy more aggressively when price trades at a discount from its 52-week high
- Take partial profits when price stretches too far above the daily EMA50
- Track the performance of your DCA plan vs a simple buy-and-hold from the same start date
⚙ How it works
1. Weekly DCA (on Daily timeframe)
- On each Friday after the Start Date:
- Add the “Weekly contribution” to the cash pool.
- If the close is below the “Discount from 52W high” level:
→ FULL DCA: use the full weekly contribution + an extra booster from your stash (up to “Max extra stash used on dip”).
→ Marked on the chart with a small green triangle under the bar.
- Otherwise:
→ HALF DCA: invest only 50% of the weekly contribution and keep the other 50% as stash (uninvested cash).
→ Marked with a small blue triangle under the bar.
2. 52-Week High Discount Logic
- The script computes the 52-week high as the highest daily high of the last 252 trading days.
- The “discount level” is: 52W high × (1 – Discount%).
- When price is at or below this level, dips are treated as buying opportunities and the model allocates more.
3. Selling Logic (Partial Take Profit)
- When the close is above the daily EMA50 by the selected percentage:
→ Sell the given “Sell portion of qty (%)” of your current holdings.
→ Marked with a small red triangle above the bar.
- This behaves like a gradual profit-taking system: if price stays extended above EMA50, multiple partial sells can occur over time.
📊 Panel (top-right)
The panel summarizes the state of your DCA plan:
- Weeks: number of DCA weeks since Start Date
- Total deposit: total money contributed (sum of all weekly contributions)
- Shares qty: total number of shares accumulated
- Avg price: volume-weighted average entry price
- Shares value: current market value of all shares (qty × close)
- Cash: uninvested cash (including saved stash)
- Total equity: Shares value + Cash
- DCA % PnL: performance of the DCA plan vs total deposits
- Stock % since start: performance of the underlying asset since the Start Date
✅ Recommended Use
- Timeframe: Daily (the DCA engine is designed to run on daily bars and Friday closes).
- Works best on stocks, ETFs or indices where a 52-week high is a meaningful reference.
- You can tune:
- Weekly contribution
- Discount from 52W high
- Booster amount
- EMA50 extension threshold and sell portion
⚠ Notes & Disclaimer
- This script is a backtesting and educational tool. It does not place real orders.
- Past performance does not guarantee future results.
- Always combine DCA and risk management with your own research and judgment.
Built by FPT (Funded Pips Trading) for long-term, rules-based DCA planning.
🔹 Core Idea
- Invest a fixed amount every week (on Friday closes)
- Buy more aggressively when price trades at a discount from its 52-week high
- Take partial profits when price stretches too far above the daily EMA50
- Track the performance of your DCA plan vs a simple buy-and-hold from the same start date
⚙ How it works
1. Weekly DCA (on Daily timeframe)
- On each Friday after the Start Date:
- Add the “Weekly contribution” to the cash pool.
- If the close is below the “Discount from 52W high” level:
→ FULL DCA: use the full weekly contribution + an extra booster from your stash (up to “Max extra stash used on dip”).
→ Marked on the chart with a small green triangle under the bar.
- Otherwise:
→ HALF DCA: invest only 50% of the weekly contribution and keep the other 50% as stash (uninvested cash).
→ Marked with a small blue triangle under the bar.
2. 52-Week High Discount Logic
- The script computes the 52-week high as the highest daily high of the last 252 trading days.
- The “discount level” is: 52W high × (1 – Discount%).
- When price is at or below this level, dips are treated as buying opportunities and the model allocates more.
3. Selling Logic (Partial Take Profit)
- When the close is above the daily EMA50 by the selected percentage:
→ Sell the given “Sell portion of qty (%)” of your current holdings.
→ Marked with a small red triangle above the bar.
- This behaves like a gradual profit-taking system: if price stays extended above EMA50, multiple partial sells can occur over time.
📊 Panel (top-right)
The panel summarizes the state of your DCA plan:
- Weeks: number of DCA weeks since Start Date
- Total deposit: total money contributed (sum of all weekly contributions)
- Shares qty: total number of shares accumulated
- Avg price: volume-weighted average entry price
- Shares value: current market value of all shares (qty × close)
- Cash: uninvested cash (including saved stash)
- Total equity: Shares value + Cash
- DCA % PnL: performance of the DCA plan vs total deposits
- Stock % since start: performance of the underlying asset since the Start Date
✅ Recommended Use
- Timeframe: Daily (the DCA engine is designed to run on daily bars and Friday closes).
- Works best on stocks, ETFs or indices where a 52-week high is a meaningful reference.
- You can tune:
- Weekly contribution
- Discount from 52W high
- Booster amount
- EMA50 extension threshold and sell portion
⚠ Notes & Disclaimer
- This script is a backtesting and educational tool. It does not place real orders.
- Past performance does not guarantee future results.
- Always combine DCA and risk management with your own research and judgment.
Built by FPT (Funded Pips Trading) for long-term, rules-based DCA planning.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuyla, bu komut dosyasının mimarı, yatırımcıların işlevselliğini inceleyip doğrulayabilmesi için onu açık kaynaklı hale getirdi. Yazarı tebrik ederiz! Ücretsiz olarak kullanabilseniz de, kodu yeniden yayınlamanın Topluluk Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, alım satım veya diğer türden tavsiye veya öneriler anlamına gelmez ve teşkil etmez. Kullanım Koşulları bölümünde daha fazlasını okuyun.