Skip to content

PriceLevel

PriceLevel

A discriminated union describing how to express a stop-loss or take-profit. Pick the form that fits your strategy: an absolute price, a distance in pips, an ATR-based offset (period × multiple), or a reward-to-risk ratio (rr). The engine resolves it to a concrete price at order time.

Signature

export type PriceLevel =
| { type: 'price'; value: number }
| { type: 'pips'; value: number }
| { type: 'atr'; period: number; multiple: number }
| { type: 'rr'; value: number };

Example

indicators/atr-stop
import { ATR, defineStrategy } from '@nexpips/sdk-trading';
/**
* Dimensionner le stop avec la volatilité : un stop-loss exprimé en
* multiples d'ATR (`{ type: 'atr' }`) s'élargit quand le marché est agité
* et se resserre quand il est calme.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: { maxRiskPercentPerTrade: 1, maxOpenPositions: 1, maxDailyLossPercent: 5 },
setup: (api) => {
const atr = api.use(ATR, { period: 14 });
return {
onBar(ctx) {
if (!ctx.position.isFlat || ctx.position.hasPendingOrder) return;
// N'entrer que si la volatilité courante est mesurable.
if (atr.at(0) <= 0) return;
ctx.order.marketBuy({
riskPercent: 1,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
},
};
},
});

Express a stop-loss as an ATR multiple.

See also