DonchianChannelOutput
DonchianChannelOutput
At a glance — The per-bar value produced by the
DonchianChannel indicator. Read the
latest value with dc.at(0).
Signature
export interface DonchianChannelOutput { upper: number; middle: number; lower: number;}| Field | Description |
|---|---|
upper | Highest high over the last period bars. |
middle | Average of upper and lower. |
lower | Lowest low over the last 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 }, }); } }, }; },});Break above the prior upper bound.