Skip to content

Buy with ATR stop and 1:2 R:R take-profit

Recipe — Buy market with ATR stop, 1:2 R:R take-profit

When to use — when you want a volatility-aware stop (instead of fixed pips) and a take-profit aligned with your risk-reward target. Works on any timeframe; ATR period and multiplier are the levers.

cookbook/buy-with-rr-stop
import { defineStrategy } from '@nexpips/sdk-trading';
/**
* Recette cookbook : achat market avec stop-loss ATR et take-profit en R:R 1:2.
*/
export default defineStrategy({
symbol: 'EURUSD',
timeframe: 'H1',
risk: {
maxRiskPercentPerTrade: 1,
maxOpenPositions: 1,
maxDailyLossPercent: 5,
},
setup: (api) => {
const riskPercent = api.input.float('riskPercent', 1, { min: 0.1, max: 2, step: 0.1 });
return {
onBar(ctx) {
if (!ctx.position.isFlat) return;
if (ctx.position.hasPendingOrder) return;
ctx.order.marketBuy({
riskPercent,
stopLoss: { type: 'atr', period: 14, multiple: 2 },
takeProfit: { type: 'rr', value: 2 },
});
},
};
},
});

Risk is exposed as an input; stop is ATR(14)×2; TP at 1:2.

What’s happening

  • api.input.float('riskPercent', 1, …) declares a user-tunable input (the user-facing form in NexPips IDE will expose it; default value is 1%).
  • stopLoss: { type: 'atr', period: 14, multiple: 2 } sets the stop at 2× ATR(14) away.
  • takeProfit: { type: 'rr', value: 2 } puts the TP at 2× the stop distance — so a winning trade is worth two times the risk taken.

See also