Appearance
Whale flow
Reacts to large pool trades (onTrade).
Kind strategy · Resolution 15m
Follows large traders: buys when big pool buys outweigh big sells, and exits when the big sellers take over.
Needs the Precise fill model
The strategy counts individual pool trades in event.onTrade, which only runs in precise and 1B backtests and on the live stream. In a quick backtest it never sees a trade and never buys. Set Fill model to Precise in the strategy's Properties.
Counting. Every pool trade of at least Big trade ≥ TAO adds to that bar's big-buy or big-sell total.
Entry. At the bar's close: big buys reach Buy flow per bar ≥ TAO, are at least Buys / sells ≥ times the big sells, and the close is above the moving price. The buy must stay under 0.25 % impact, half the risk limit, so the exit fits too.
Exit. Big sells reach the threshold and exceed big buys, or the trailing stop placed in onPositionOpened triggers.
Risk. maxIntentsPerHour: 12 throttles the strategy if the flow is noisy.
Try it
On the chart, press /, open Strategies and choose Whale flow. Or copy the source below into the AlphaScript editor and click Add to chart.
Inputs
| Input | Type | Default |
|---|---|---|
| Big trade ≥ TAO | float | 5 |
| Buy flow per bar ≥ TAO | float | 20 |
| Buys / sells ≥ | float | 2 |
| Trailing stop % | float | 4 |
| Size % of equity | float | 30 |
Source
From packages/alphascript/examples/whale_flow.as.js.
js
strategy({ name: "Whale flow", version: "0.1", market: "ALPHA:61", resolution: "15m",
capital: { tao: 100 }, actOn: "confirmed", fill: { mode: "precise", latencyBlocks: 2 },
risk: { maxPriceImpactPct: 0.5, maxPositionTao: 60, maxIntentsPerHour: 12 } });
const minTao = input.float("Big trade ≥ TAO", 5, { min: 0.5, max: 500, step: 0.5 });
const flowTao = input.float("Buy flow per bar ≥ TAO", 20, { min: 1, max: 5000, step: 1 });
const ratio = input.float("Buys / sells ≥", 2, { min: 1, max: 10, step: 0.5 });
const trailPct = input.float("Trailing stop %", 4, { min: 0.5, max: 20, step: 0.5 });
const sizePct = input.float("Size % of equity", 30, { min: 1, max: 100 });
const mp = candle.movingPrice;
plot(mp, { title: "moving price", color: "#f2b544", style: "step" });
plot(block.volume, { title: "pool volume / block", color: "#5c6878", style: "histogram", pane: 1 });
let bigBuy = 0, bigSell = 0;
event.onTrade((t) => {
if (t.tao < minTao) return;
if (t.side === "Buy") bigBuy += t.tao; else bigSell += t.tao;
});
event.onCandle((bar) => {
const pos = account.position();
const buyers = bigBuy >= flowTao && bigBuy >= bigSell * ratio;
if (pos.alpha === 0 && buyers && bar.close > mp.value) {
const tao = account.equity() * sizePct / 100;
if (pool.impact(tao) * 100 < 0.25) {
trade.buy({ tao, maxPrice: pool.price() * 1.01, ttlBlocks: 4, reason: `whales ${bigBuy.toFixed(1)}τ` });
}
} else if (pos.alpha > 0 && bigSell >= flowTao && bigSell > bigBuy) {
trade.closePosition({ reason: "whales selling" });
}
bigBuy = 0; bigSell = 0;
});
event.onPositionOpened(() => trade.trailingStop({ pct: trailPct, reason: "trail" }));
event.onFill((f) => log(f.side, f.alpha.toFixed(2), "α at", f.price.toFixed(7), `${f.impactBps.toFixed(1)} bps`));