Appearance
DCA with liquidity guard
Dollar-cost averages into the pool only while liquidity is deep.
Kind strategy · Resolution 1h
Dollar-cost averaging that refuses to buy into a thin pool.
Buying. Every Every N bars bars it buys a fixed TAO per buy, unless:
- the pool holds less than Min TAO in pool TAO, or
- the buy's impact would exceed Max impact %; it then logs the pool's capacity at that impact, from
pool.capacity().
Each buy uses partialOk: false, so it fills completely within the price limit or not at all.
Selling. The whole position is sold once the price is Take profit % above the average entry price.
Risk. minPoolTao: 500 makes the engine itself reject fills while the pool holds less than 500 TAO, as a second guard.
What to read. The journal shows each skipped buy and why: a record of how often the pool was too thin.
Try it
On the chart, press /, open Strategies and choose DCA with liquidity guard. Or copy the source below into the AlphaScript editor and click Add to chart.
Inputs
| Input | Type | Default |
|---|---|---|
| Every N bars | int | 4 |
| TAO per buy | float | 5 |
| Min TAO in pool | float | 1000 |
| Max impact % | float | 0.2 |
| Take profit % | float | 8 |
Source
From packages/alphascript/examples/dca_liquidity_guard.as.js.
js
strategy({ name: "DCA with liquidity guard", version: "0.1", market: "ALPHA:61", resolution: "1h",
capital: { tao: 100 }, actOn: "confirmed", risk: { maxPriceImpactPct: 0.3, minPoolTao: 500 } });
const everyN = input.int("Every N bars", 4, { min: 1, max: 48 });
const chunk = input.float("TAO per buy", 5, { min: 0.1, max: 100, step: 0.5 });
const minDepth = input.float("Min TAO in pool", 1000, { min: 0, max: 100000, step: 100 });
const maxImp = input.float("Max impact %", 0.2, { min: 0.01, max: 2, step: 0.01 });
const tpPct = input.float("Take profit %", 8, { min: 1, max: 100 });
plot(block.taoIn, { title: "TAO in pool", color: "#2bb889", style: "area", pane: 1 });
event.onCandle(() => {
const pos = account.position();
if (pos.alpha > 0 && pool.price() > pos.avgPrice * (1 + tpPct / 100)) {
trade.closePosition({ reason: "take-profit" });
return;
}
if (barstate.index % everyN !== 0) return;
const depth = pool.reserves().taoIn;
const impact = pool.impact(chunk) * 100;
if (depth < minDepth) { log("skip: pool depth", depth.toFixed(0), "τ"); return; }
if (impact > maxImp) { log("skip: impact", impact.toFixed(3), "% — capacity at", maxImp, "% is", pool.capacity(maxImp / 100).toFixed(2), "τ"); return; }
if (account.cash() < chunk) return;
trade.buy({ tao: chunk, maxPrice: pool.price() * (1 + maxImp / 100), ttlBlocks: 5, partialOk: false, reason: "dca" });
});