DonchianChannel
DonchianChannel
At a glance — upper = highest high and lower = lowest low over the last
period bars; middle is their average. The series yields a
DonchianChannelOutput per bar.
The classic breakout channel.
Signature
const dc: Series<DonchianChannelOutput> = api.use(DonchianChannel, { period: 20 });| Field | Type | Description |
|---|---|---|
period | number (≥ 1) | Look-back window for the high/low extremes. |
Warm-up: period bars.
Example
import { defineStrategy, DonchianChannel } from '@nexpips/sdk-trading';
/** * Breakout de canal de Donchian. La série renvoie un * `DonchianChannelOutput` ({ upper, middle, lower }). Achat quand la clôture * dépasse le plus-haut des 20 barres précédentes ; stop sur le milieu du canal. */export default defineStrategy({ symbol: 'EURUSD', timeframe: 'H1', risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 }, setup: (api) => { const dc = api.use(DonchianChannel, { period: 20 });
return { onBar(ctx) { if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return; if (dc.length < 2) return;
const prevUpper = dc.at(1).upper; if (ctx.series.close.at(0) > prevUpper) { ctx.order.marketBuy({ riskPercent: 1, stopLoss: { type: 'price', value: dc.at(0).middle }, takeProfit: { type: 'rr', value: 2 }, }); } }, }; },});Buy when price breaks above the prior 20-bar high.
See also
DonchianChannelOutputATR— pair breakouts with a volatility stop