Stop Loss and Profit Target#

Risk management is the most critical part of any trading strategy. Beyond manually coding exit conditions with Sell / BuyToCover, PowerLanguage provides 5 built-in risk management functions that automatically exit a position when it reaches a specified loss or profit amount:

FunctionDescription
SetStopLossFixed stop loss: exits when position loss reaches the specified amount
SetProfitTargetFixed profit target: exits when position profit reaches the specified amount
SetBreakEvenBreak-even stop: once profit reaches a threshold, moves the stop to the entry price
SetDollarTrailingTrailing stop (fixed amount): exits when profit falls from its peak by the specified amount
SetPercentTrailingTrailing stop (percentage): exits when profit falls from its peak by the specified percentage of that peak

Common characteristics of all 5 functions:

  • Applies to both long and short automatically: No need to write separate logic for long and short positions — the functions automatically calculate stop and target prices based on the current position direction
  • Whole position by default: Applied to the entire position (sum of all contracts), not per contract. To switch to per-contract mode, call SetStopContract first
  • Intrabar evaluation: All 5 functions are evaluated intrabar — they monitor continuously within each bar and can trigger an exit on the same bar as the entry

Converting Points to Currency#

The Amount parameter uses currency units (USD, EUR, etc.). To set a stop in points, multiply by BigPointValue:

Amount = Points × BigPointValue

Common BigPointValue values:

InstrumentBigPointValue
E-mini S&P 500 (ES)$50 / point
E-mini Nasdaq-100 (NQ)$20 / point
Micro E-mini S&P 500 (MES)$5 / point

Example: E-mini S&P 500 (ES), 1 contract, 10-point stop = SetStopLoss(10 * BigPointValue) = SetStopLoss(500)

Use BigPointValue in your code rather than hard-coding the multiplier so your strategy works across different instruments.

SetStopLoss#

SetStopLoss sets a fixed stop loss: when the position loss reaches Amount, a Stop order is sent to exit.

Syntax#

1
SetStopLoss(Amount);
ParameterDescription
AmountMaximum allowable loss for the entire position in currency. Long stop price = EntryPrice - Amount / BigPointValue; Short stop price = EntryPrice + Amount / BigPointValue

Example#

E-mini S&P 500 (ES), 1 contract, 10-point ($500) fixed stop loss:

1
2
3
4
5
6
Inputs: stopPoints(10);

If MarketPosition = 0 and Close crosses above Average(Close, 20) Then
  Buy("Long Entry") 1 Contract Next Bar Market;

SetStopLoss(stopPoints * BigPointValue);

Place SetStopLoss at the top level of your script — no need to wrap it in an If condition. The function automatically applies to the current position on every bar execution.

SetProfitTarget#

SetProfitTarget sets a fixed profit target: when the position profit reaches Amount, a Limit order is sent to exit.

Syntax#

1
SetProfitTarget(Amount);
ParameterDescription
AmountProfit target for the entire position in currency. Long target price = EntryPrice + Amount / BigPointValue; Short target price = EntryPrice - Amount / BigPointValue

Example#

E-mini S&P 500 (ES), 1 contract, 20-point ($1,000) profit target:

1
2
3
4
5
6
Inputs: targetPoints(20);

If MarketPosition = 0 and Close crosses above Average(Close, 20) Then
  Buy("Long Entry") 1 Contract Next Bar Market;

SetProfitTarget(targetPoints * BigPointValue);

SetBreakEven#

SetBreakEven sets a break-even stop: once the position profit reaches the Profit threshold, the stop is automatically moved to the entry price, eliminating the risk of a losing exit.

Syntax#

1
SetBreakEven(Profit);
ParameterDescription
ProfitProfit threshold (entire position, in currency) that triggers the break-even stop. Once profit reaches Profit, the stop price moves to EntryPrice

Example#

E-mini S&P 500 (ES), 1 contract — once profit reaches 8 points ($400), move stop to entry price:

1
2
3
4
5
6
Inputs: breakEvenPoints(8);

If MarketPosition = 0 and Close crosses above Average(Close, 20) Then
  Buy("Long Entry") 1 Contract Next Bar Market;

SetBreakEven(breakEvenPoints * BigPointValue);

SetBreakEven is commonly paired with SetStopLoss: SetStopLoss controls maximum loss in the early stage, and once the break-even threshold is reached, the stop moves to the entry price to ensure a no-loss exit.

SetBreakEven does not factor in commissions or slippage — triggering the break-even stop does not guarantee a net zero result in practice.

SetDollarTrailing#

SetDollarTrailing sets a trailing stop using a fixed dollar amount: it tracks the peak profit of the position and exits when profit falls from that peak by more than Amount. This is used in trend trading to lock in floating gains.

Syntax#

1
SetDollarTrailing(Amount);
ParameterDescription
AmountMaximum allowable profit drawdown from the peak profit (entire position, in currency). Exits when current profit < peak profit - Amount

Trailing stop behavior:

Position DirectionTracking BasisExit Condition
LongPeak profit during the tradeCurrent profit < Peak profit - Amount
ShortPeak profit during the tradeCurrent profit < Peak profit - Amount

To scale the trailing distance proportionally with profit growth, use SetPercentTrailing instead.

Example#

E-mini S&P 500 (ES), 1 contract, 80-point ($4,000) trailing stop:

1
2
3
4
5
6
Inputs: trailPoints(80);

If MarketPosition = 0 and Close crosses above Average(Close, 20) Then
  Buy("Long Entry") 1 Contract Next Bar Market;

SetDollarTrailing(trailPoints * BigPointValue);

Trailing stop profit walkthrough (ES entry price 5,000, Amount = $4,000, BigPointValue = 50):

SetDollarTrailing trailing stop diagram

BarCloseUnrealized ProfitPeak ProfitExit ThresholdNote
Entry5,000$0$0-$4,000Initial state
+15,050$2,500$2,500-$1,500New profit high, threshold updated
+25,120$6,000$6,000$2,000New profit high, threshold updated
+35,080$4,000$6,000$2,000No new high, threshold unchanged
+45,035$1,750$6,000$2,000Profit $1,750 < threshold $2,000 → Exit

Unrealized profit = (Close - EntryPrice) × BigPointValue, e.g. bar +2 = (5,120 - 5,000) × 50 = $6,000.

SetPercentTrailing#

SetPercentTrailing sets a percentage-based trailing stop: once profit first reaches the Profit threshold, it tracks the peak profit and exits when profit falls from that peak by more than Percentage%.

The key difference from SetDollarTrailing is that the trailing distance is relative — the higher the profit, the larger the allowable drawdown in dollar terms.

Syntax#

1
SetPercentTrailing(Profit, Percentage);
ParameterDescription
ProfitActivation threshold (entire position, in currency). The trailing stop does not activate until profit first reaches this level
PercentageMaximum allowable drawdown as a percentage of peak profit (0–100). Exit condition: current profit < peak profit × (1 - Percentage / 100)

Example#

E-mini S&P 500 (ES), 1 contract — activate when profit reaches $2,000, then exit if profit drops 50% from its peak:

1
2
3
4
5
6
Inputs: activateProfit(2000), trailPct(50);

If MarketPosition = 0 and Close crosses above Average(Close, 20) Then
  Buy("Long Entry") 1 Contract Next Bar Market;

SetPercentTrailing(activateProfit, trailPct);

Same scenario (ES entry price 5,000, BigPointValue = 50), SetPercentTrailing(2000, 50) behavior:

BarCloseUnrealized ProfitPeak ProfitExit Threshold (50%)Note
Entry5,000$0Not activated ($0 < $2,000)
+15,050$2,500$2,500$1,250First time threshold reached — activated! $2,500 × 50%
+25,120$6,000$6,000$3,000New profit high, threshold updated: $6,000 × 50%
+35,080$4,000$6,000$3,000No new high, threshold unchanged
+45,035$1,750$6,000$3,000Profit $1,750 < threshold $3,000 → Exit

Note: Before profit reaches the Profit activation threshold, SetPercentTrailing provides no downside protection. It should typically be combined with SetStopLoss to control losses in the early stage.

SetDollarTrailing vs. SetPercentTrailing#

SetDollarTrailingSetPercentTrailing
ParametersAmount (currency amount)Profit (activation threshold) + Percentage (percent)
Trailing distanceFixed amount, does not grow with profitScales proportionally with peak profit — larger profit allows larger drawdown
Activates immediatelyYes, no threshold requiredNo, profit must first reach the Profit threshold

Per-Contract Mode: SetStopContract#

Amount defaults to the whole-position total. If your strategy holds multiple contracts and you want each contract to have its own independent stop, call SetStopContract before the risk management function:

1
2
SetStopContract;          // Switch to per-contract mode
SetStopLoss(Amount);      // Amount now applies per contract

Call SetStopPosition to switch back to whole-position mode (the default).

Example: 2 ES contracts, each with a 10-point ($500) stop:

1
2
SetStopContract;
SetStopLoss(10 * BigPointValue);   // $500 per contract, $1,000 total

Without SetStopContract, SetStopLoss(500) would be a $500 stop for the entire 2-contract position (roughly $250 per contract).

Combined Example#

The following example combines 3 risk management functions to build a moving average strategy with complete risk control:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
Inputs:
  maLength(20),
  stopPoints(10),         // Initial fixed stop: 10 points ($500 on ES)
  breakEvenPoints(8),     // Break-even threshold: move stop to entry after 8 points profit
  trailPoints(20);        // Trailing stop: exit if profit pulls back 20 points from peak

Variables: ma(0);

ma = Average(Close, maLength);

// Entry: close crosses above MA
If MarketPosition = 0 and Close crosses above ma Then
  Buy("Long Entry") 1 Contract Next Bar Market;

// Exit: close crosses below MA
If MarketPosition = 1 and Close crosses below ma Then
  Sell("Exit Long") Next Bar Market;

// Risk management (automatically applies to both long and short)
SetStopLoss(stopPoints * BigPointValue);
SetBreakEven(breakEvenPoints * BigPointValue);
SetDollarTrailing(trailPoints * BigPointValue);

Exit logic explained:

  1. Fixed stop loss (SetStopLoss): Active immediately on entry — exits if loss reaches 10 points
  2. Break-even stop (SetBreakEven): Once profit reaches 8 points, the stop moves to the entry price, making the fixed stop ineffective
  3. Trailing stop (SetDollarTrailing): Continuously tracks peak profit — exits if profit pulls back 20 points from the peak
  4. MA exit: Exits when close crosses below the MA, regardless of stop conditions

Whichever exit condition triggers first causes the exit.

Notes#

Intrabar Evaluation#

All 5 functions monitor the position continuously intrabar (not just at bar close), so they can trigger an exit on the same bar as the entry.

Multiple Stops Triggering Simultaneously#

If both SetStopLoss and SetDollarTrailing reach their exit conditions within the same bar, whichever triggers first takes precedence.

Coexisting with Manual Exit Instructions#

Sell / BuyToCover instructions and all 5 risk management functions can coexist — whichever triggers first causes the exit.

Cannot Target a Specific Entry#

All 5 functions apply to every open entry in the strategy — it is not possible to assign different stop parameters to specific entry labels (EntryLabel).

Stop Only Moves in the Favorable Direction#

The exit threshold of SetDollarTrailing only rises as peak profit increases — it does not pull back down if profit retreats.

Signal Scripts Only#

All 5 functions can only be used in Signal scripts — they cannot be used in Indicator scripts.

Reference#

https://www.multicharts.com/trading-software/index.php?title=SetStopLoss

https://www.multicharts.com/trading-software/index.php?title=SetProfitTarget

https://www.multicharts.com/trading-software/index.php?title=SetBreakEven

https://www.multicharts.com/trading-software/index.php?title=SetDollarTrailing

https://www.multicharts.com/trading-software/index.php?title=SetPercentTrailing

https://www.multicharts.com/trading-software/index.php?title=SetStopPosition