Appearance
Personalize your experience
Mode
Accent Color
Layout
Direction
DCA Accumulator
FreeDollar-cost averaging bot with dip-buy detection
4.8(201)
4.5k installs 980 2 commentsP
dcalong-termaccumulationcrypto
Preview
1 / 2
Chart preview
About
Systematically buys on schedule or when price dips below SMA. Configurable intervals, dip thresholds, and max portfolio allocation.
Features
• Scheduled interval buys
• Dip detection (% below SMA)
• Multiplied buy on dips
• Max position cap
Bot Details
Supported Brokers
Binance, Delta Exchange
Risk Level
low
Strategy
Scheduled + dip-based DCA with SMA detection
Source Code
Edit in IDEtypescript
| 1 | // DCA Bot — Quatick IDE |
| 2 | // Shows deviation of close from the rolling DCA average price. |
| 3 | // SDK math globals available: sma, ema, atr, rsi, macd, bollingerBands, vwap, etc. |
| 4 | |
| 5 | const metadata = { id: 'dca-bot', name: 'DCA Bot', version: '1.0.0', category: 'bot' }; |
| 6 | |
| 7 | interface BarData { |
| 8 | time: number; |
| 9 | open: number; |
| 10 | high: number; |
| 11 | low: number; |
| 12 | close: number; |
| 13 | volume?: number; |
| 14 | } |
| 15 | |
| 16 | const defaultParams = { |
| 17 | smaPeriod: 20, |
| 18 | interval: 10, |
| 19 | dipThreshold: 2, |
| 20 | }; |
| 21 | |
| 22 | /** |
| 23 | * DCA Average Price Line. |
| 24 | * Returns the simulated rolling average cost of a DCA strategy. |
| 25 | * Buy scheduled every N bars; extra buy on dips below SMA by threshold %. |
| 26 | */ |
| 27 | function calculate(bars: BarData[], params = defaultParams): { time: number; value: number }[] { |
| 28 | const closes = bars.map(b => b.close); |
| 29 | const smaValues = sma(closes, params.smaPeriod); |
| 30 | const result: { time: number; value: number }[] = []; |
| 31 | |
| 32 | let totalInvested = 0; |
| 33 | let totalQty = 0; |
| 34 | let barsSinceBuy = 0; |
| 35 | |
| 36 | for (let i = params.smaPeriod; i < bars.length; i++) { |
| 37 | barsSinceBuy++; |
| 38 | const price = bars[i].close; |
| 39 | const sm = smaValues[i]; |
| 40 | |
| 41 | const isDip = !isNaN(sm) && ((sm - price) / sm) * 100 >= params.dipThreshold; |
| 42 | const isScheduled = barsSinceBuy >= params.interval; |
| 43 | |
| 44 | if (isDip || isScheduled) { |
| 45 | const amount = isDip ? 200 : 100; |
| 46 | totalQty += amount / price; |
| 47 | totalInvested += amount; |
| 48 | barsSinceBuy = 0; |
| 49 | } |
| 50 | |
| 51 | if (totalQty > 0) { |
| 52 | result.push({ time: bars[i].time, value: totalInvested / totalQty }); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return result; |
| 57 | } |
Read-only preview. Open in the QuaTick IDE to edit and deploy.
Reviews
No reviews yet. Be the first to review this listing.
Discussion
Sign in to join the discussion. Your posts and replies show up on your profile.