Home › Guides › Trading bots & code
DCA bot explained: how it works — and where it breaks
A DCA bot buys more as price falls, so a small bounce is enough to exit. That's why it often looks like it "always wins". The math below shows the trade-off: small, frequent wins against one large, rare loss.
Two different things called "DCA"
The same 3 letters mean two very different things. Mixing them up is where a lot of confusion starts.
| DCA investing | A "DCA bot" | |
|---|---|---|
| What it does | Buys a fixed amount on a schedule, such as every month | Buys more each time price drops a set %, then sells at a small target |
| Why | Spread purchases over time instead of all at once | Lower the average price so a small bounce exits |
| Buy size | Same amount each time | Often grows with each buy |
| Time frame | Years | Hours to weeks |
| Main risk | The asset falls long-term | A long drop with no stop |
Dollar-cost averaging as an investing habit is covered in our Dollar-cost averaging glossary page. This page is about the bot.
How a DCA bot works
A typical crypto-style DCA bot has 4 settings:
- Base order — the first buy.
- Safety orders — extra buys placed lower, at set steps (for example, every 2% down).
- Volume scale — how much bigger each safety order is than the last (for example, 1.5×).
- Take profit — a % above the average price where it sells everything.
Because each lower buy is bigger, the average price drops fast. So price only needs a small bounce to hit the target.
The math, step by step
Base order 100, a safety order every 2% lower, each 1.5× bigger, up to 5 safety orders.
Example code for learning — test it on paper first; it is not a ready-made trading system.
base = 100.0 # first buy, in dollars
scale = 1.5 # each extra buy is 1.5x bigger than the last
step = 0.02 # buy again every 2% lower
start = 100.0 # price of the first buy
spent, coins = 0.0, 0.0
for i in range(6):
buy_price = start * (1 - step * i)
amount = base * scale ** i
spent += amount
coins += amount / buy_price
print(f"Buy {i+1}: ${amount:,.0f} at {buy_price:.2f} | in: ${spent:,.0f} | average: {spent / coins:.2f}")
In plain words:
- The loop runs 6 times: the base order plus 5 safety orders.
- buy_price steps down 2% of the starting price each time: 100, 98, 96…
- amount grows 1.5× each time: 100, 150, 225…
- spent and coins keep running totals. spent ÷ coins is the average price paid.
It prints:
Buy 1: $100 at 100.00 | in: $100 | average: 100.00
Buy 2: $150 at 98.00 | in: $250 | average: 98.79
Buy 3: $225 at 96.00 | in: $475 | average: 97.45
Buy 4: $338 at 94.00 | in: $812 | average: 95.99
Buy 5: $506 at 92.00 | in: $1,319 | average: 94.42
Buy 6: $759 at 90.00 | in: $2,078 | average: 92.75
A math example, not a promise. You can check averages like these with our average cost calculator.
Why it looks like it always wins
Look at the last line. Price fell 10%, from 100 to 90. But the average is 92.75.
With a 2% take profit, the bot sells at about 94.61. Price doesn't need to get back to 100 — just to 94.61. That's about +$41.56 on $2,078.
Small bounces happen all the time. So most cycles end with a small win. That's the part the screenshots show.
Where it breaks
Now notice 2 other things on those lines.
The money at risk grew 20×. The bot started with $100 in the trade. After 5 safety orders it has $2,078 in. You didn't decide to make a $2,078 trade. The bot did, one step at a time.
It ran out of safety orders at 90. Below that, there are no more buys. It just holds.
Say price keeps falling to 80:
- The bot holds about 22.4 coins, worth about $1,792.
- It paid $2,078.
- Open result: about −$286.
Each normal cycle earned about $41.56. So one long drop erased about 7 winning cycles. That's the trade-off: frequent small wins against a rare large loss. And with no stop, that loss can keep growing as price falls.
Compare: a single $100 buy at 100 that falls to 80 is −$20. The DCA structure turned the same 20% drop into a loss more than 14 times bigger, because it kept adding.
A DCA bot doesn't remove the loss. It moves it. It trades many small wins for a rare large loss. Whether that's acceptable depends entirely on how big the large loss can get — so set that number first.
What makes it worse
- Bigger volume scale. 2× instead of 1.5× is close to martingale (doubling after losses). It recovers faster and blows up harder.
- More safety orders. More buys mean more money committed to a falling price.
- Leverage. On futures, adding size pulls the liquidation price closer. Check with our crypto liquidation calculator.
- Trending markets. A DCA bot assumes bounces. In a steady downtrend, the bounces don't come in time.
- Backtests on rising markets. In a bull run nearly every cycle wins. That's not proof — it's one kind of market. Test on long drops too, and watch for overfitting (tuning settings until the past looks perfect).
See also does averaging down always work?.
If you test one, set these limits first
- Max money in one cycle. Add up the base and every safety order before starting: that's your true trade size. In our example it's $2,078, not $100.
- A hard stop. For example, if price closes below a clear turning point on the bigger chart, sell everything and stop. Work out the loss at that stop in advance — then size the base order so it's a small slice of the account.
- No leverage while learning.
- A daily loss limit and a kill switch you can use without code. See daily loss limit.
- Error handling and logging. Log every order and reply. After a disconnect, check open orders before placing more — a duplicate safety order is a bigger trade than planned.
More: trading bot risk controls. Then paper trade it through a falling market, not just a rising one. See paper trading a bot.
DCA bot vs grid bot
A grid bot buys equal amounts at fixed levels and sells each one a step higher. A DCA bot buys growing amounts and sells everything at one target above the average. Both add to positions that are going against them. Both need a hard stop.
Questions
What is a DCA bot?
A trading bot that buys more as price falls by set steps, often with each buy bigger than the last, to lower the average price. It sells everything when price rises a set % above that average.
Is a DCA bot the same as dollar-cost averaging?
No. Dollar-cost averaging as an investing habit buys a fixed amount on a schedule. A DCA bot adds bigger buys as price falls and aims to exit on a small bounce — a short-term trading tactic with different risks.
Can a DCA bot lose money?
Yes. If price keeps falling after the last safety order, the bot holds a much bigger position than it started with, and the loss can be far larger than many small wins combined.
What are safety orders in a DCA bot?
Extra buy orders placed at set steps below the first buy. They lower the average price, but they also increase how much money is in the trade.
Want the next step? We'll walk you through it.
Four free lessons by email, one every few days — each with a 10-minute exercise on a real chart.
Send Me the Free Lessons 4 short emails · No spam · Unsubscribe anytimeOr see the whole method, step by step:
See What’s Inside the Course Try everything free first. Decide when you're ready. · Open the free chart tool (works in the TradingView phone app)One chart idea a day, in plain English. Follow along: