Aller au contenu

Source

Ce contenu n’est pas encore disponible dans votre langue.

Source

The derived price input an indicator computes on. Beyond the raw OHLC fields you can pick blended sources: hl2 (high+low)/2, hlc3 (high+low+close)/3, or ohlc4 (open+high+low+close)/4. Most indicators default to close.

Signature

export type Source = 'open' | 'high' | 'low' | 'close' | 'hl2' | 'hlc3' | 'ohlc4';

Example

indicators/sma-trend
import { defineStrategy, SMA } from '@nexpips/sdk-trading';
/**
* Filtre de tendance : n'acheter que lorsque la clôture est au-dessus de
* la moyenne mobile simple SMA(50).
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const sma = api.use(SMA, { source: 'close', period: 50 });
return {
onBar(ctx) {
if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
if (ctx.series.close.at(0) > sma.at(0)) {
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
}
},
};
},
});

Choose the price source feeding an indicator.

See also