Skip to content

Timeframe

Timeframe

The bar interval a strategy runs on, from one-minute (M1) candles up to weekly (W1). You declare it once in your StrategyDefinition, and the engine feeds your hooks one closed bar of that size at a time.

Signature

export type Timeframe = 'M1' | 'M5' | 'M15' | 'M30' | 'H1' | 'H4' | 'D1' | 'W1';

Example

order/market-buy-simple
import { defineStrategy } from '@nexpips/sdk-trading';
/**
* Acheter au marché si on est flat, avec un stop-loss à 20 pips.
*
* Pattern : entrée propre — vérifier `hasPendingOrder` ET `isFlat`
* pour éviter d'envoyer un ordre alors qu'un précédent est encore
* en attente de confirmation broker.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: {
maxRiskPercentPerTrade: 1,
maxOpenPositions: 1,
maxDailyLossPercent: 5,
},
setup: () => ({
onBar(ctx) {
if (!ctx.position.isFlat) return;
if (ctx.position.hasPendingOrder) return;
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'pips', value: 20 },
takeProfit: { type: 'rr', value: 2 },
});
},
}),
});

A strategy declares its timeframe and reacts on each closed bar.

See also