Skip to main content
Skip to main content
Version: Next 🚧

How to Implement Trailing Stops

Problem

You want to protect profits on winning trades while allowing them to continue running in your favor. Fixed take profit targets can leave money on the table during strong trends, while trailing stops dynamically adjust to lock in gains.

Prerequisites

  • Basic algorithm configuration completed
  • Exit conditions configured (Step 4)
  • Understanding of stop loss concepts

What is a Trailing Stop?

A trailing stop is a dynamic stop loss that moves with the price to lock in profits. Unlike a fixed stop loss that stays at the entry level, a trailing stop "trails" the price at a fixed distance, only moving in the profitable direction.

Key Characteristics:

  • Moves up (for long positions) or down (for short positions) as price moves favorably
  • Never moves against you (doesn't widen the stop)
  • Triggers when price retraces by the trail distance from the peak
  • Helps capture large trends while protecting profits

Trailing Stop Types

x3Algo supports two trailing stop methods:

  1. Percentage-based - Trail at a fixed percentage from peak price
  2. ATR-based - Trail at a dynamic distance based on volatility

Method 1: Percentage-Based Trailing

When to Use

  • Simple, easy to understand
  • Consistent across all instruments
  • Good for trending markets
  • Suitable for most trading styles

Configuration

{
"exitConditions": {
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 3.0,
"activationThreshold": 2.0
}
}
}

How It Works

For Long Positions:

  1. Track the highest price reached (peak)
  2. Set stop at: Peak Price × (1 - Trail Percentage)
  3. If price falls below stop, exit the position

For Short Positions:

  1. Track the lowest price reached (trough)
  2. Set stop at: Trough Price × (1 + Trail Percentage)
  3. If price rises above stop, exit the position

Example: Long Position

Entry: ₹500
Trail Percentage: 3%
Activation Threshold: 2%

Price Movement:
₹500 → ₹510 (2% profit) → Trailing activates
Peak: ₹510, Stop: ₹494.70 (510 × 0.97)

₹510 → ₹520 → Peak updates
Peak: ₹520, Stop: ₹504.40 (520 × 0.97)

₹520 → ₹530 → Peak updates
Peak: ₹530, Stop: ₹514.10 (530 × 0.97)

₹530 → ₹512 → Stop triggered at ₹514.10
Exit: ₹514.10
Profit: ₹14.10 per share (2.82%)

Example: Short Position

Entry: ₹500
Trail Percentage: 3%
Activation Threshold: 2%

Price Movement:
₹500 → ₹490 (2% profit) → Trailing activates
Trough: ₹490, Stop: ₹504.70 (490 × 1.03)

₹490 → ₹480 → Trough updates
Trough: ₹480, Stop: ₹494.40 (480 × 1.03)

₹480 → ₹470 → Trough updates
Trough: ₹470, Stop: ₹484.10 (470 × 1.03)

₹470 → ₹486 → Stop triggered at ₹484.10
Exit: ₹484.10
Profit: ₹15.90 per share (3.18%)

Choosing Trail Percentage

Tight Trailing (1-2%)

  • Locks in profits quickly
  • More trades stopped out early
  • Good for: Scalping, volatile markets
  • Risk: May exit too early in strong trends

Moderate Trailing (3-5%)

  • Balanced approach (recommended)
  • Allows room for normal retracements
  • Good for: Swing trading, most strategies
  • Risk: Moderate profit give-back

Wide Trailing (6-10%)

  • Lets winners run longer
  • Fewer premature exits
  • Good for: Position trading, strong trends
  • Risk: Larger profit give-back on reversals

Activation Threshold

The activation threshold determines when trailing starts:

{
"trailingStop": {
"activationThreshold": 2.0 // Start trailing after 2% profit
}
}

Why Use Activation Threshold?

  • Prevents trailing from activating immediately
  • Gives the trade room to develop
  • Avoids being stopped out by normal volatility near entry

Example Without Threshold:

Entry: ₹500
Trail: 3%
No threshold

₹500 → ₹505 → ₹498 → Stopped at ₹489.15
Loss despite initial profit!

Example With Threshold:

Entry: ₹500
Trail: 3%
Threshold: 2%

₹500 → ₹505 → ₹498 → No stop (threshold not reached)
₹498 → ₹512 → Trailing activates at ₹510 (2% profit)

Scalping (1-5 minute timeframes):

{
"trailingStop": {
"trailPercentage": 1.5,
"activationThreshold": 1.0
}
}

Day Trading (5-30 minute timeframes):

{
"trailingStop": {
"trailPercentage": 2.5,
"activationThreshold": 1.5
}
}

Swing Trading (1-4 hour timeframes):

{
"trailingStop": {
"trailPercentage": 4.0,
"activationThreshold": 2.0
}
}

Position Trading (daily timeframes):

{
"trailingStop": {
"trailPercentage": 7.0,
"activationThreshold": 3.0
}
}

Method 2: ATR-Based Trailing

When to Use

  • Adapting to market volatility
  • Trading different instruments with varying volatility
  • More sophisticated risk management
  • Professional trading strategies

Configuration

{
"exitConditions": {
"trailingStop": {
"enabled": true,
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.0,
"activationThreshold": 1.5
}
}
}

How It Works

ATR (Average True Range) measures volatility:

  • High volatility = Wider trailing distance
  • Low volatility = Tighter trailing distance

For Long Positions:

Stop = Peak Price - (ATR × Multiplier)

For Short Positions:

Stop = Trough Price + (ATR × Multiplier)

Example: Low Volatility Stock

Entry: ₹500
ATR (14): ₹5
Multiplier: 2.0
Activation: 1.5%

Price Movement:
₹500 → ₹508 (1.6% profit) → Trailing activates
Peak: ₹508, ATR: ₹5
Stop: ₹508 - (₹5 × 2.0) = ₹498

₹508 → ₹520 → Peak updates
Peak: ₹520, ATR: ₹6 (volatility increased)
Stop: ₹520 - (₹6 × 2.0) = ₹508

₹520 → ₹505 → Stop triggered at ₹508
Exit: ₹508
Profit: ₹8 per share (1.6%)

Example: High Volatility Stock

Entry: ₹500
ATR (14): ₹25
Multiplier: 2.0
Activation: 1.5%

Price Movement:
₹500 → ₹520 (4% profit) → Trailing activates
Peak: ₹520, ATR: ₹25
Stop: ₹520 - (₹25 × 2.0) = ₹470

₹520 → ₹550 → Peak updates
Peak: ₹550, ATR: ₹28 (volatility increased)
Stop: ₹550 - (₹28 × 2.0) = ₹494

₹550 → ₹490 → Stop triggered at ₹494
Exit: ₹494
Profit: -₹6 per share (-1.2%)

Note: Wide ATR gives more room but can result in larger give-backs.

ATR Period Selection

{
"trailingStop": {
"atrPeriod": 14 // Number of candles
}
}

10 periods:

  • More responsive to recent volatility
  • Adapts quickly to changing conditions
  • Can be choppy in ranging markets

14 periods (default):

  • Standard setting, balanced
  • Good for most strategies
  • Recommended starting point

20 periods:

  • Smoother, less sensitive
  • Better for longer-term trades
  • Reduces false signals

ATR Multiplier Effects

{
"trailingStop": {
"atrMultiplier": 2.0
}
}

1.5x Multiplier:

  • Tighter stops
  • Locks in profits faster
  • More trades stopped out early
  • Good for: Scalping, mean reversion

2.0x Multiplier (recommended):

  • Balanced approach
  • Standard for most strategies
  • Good room for retracements

2.5-3.0x Multiplier:

  • Wider stops
  • Lets trends run longer
  • Fewer premature exits
  • Good for: Trend following, position trading

Volatility Adaptation Example

Low Volatility Period:
ATR: ₹5, Multiplier: 2.0
Trail Distance: ₹10 (tight)

High Volatility Period:
ATR: ₹20, Multiplier: 2.0
Trail Distance: ₹40 (wide)

The stop automatically adjusts to market conditions!

Peak Price Tracking

How Peak is Tracked

For Long Positions:

  • Peak = Highest high since entry
  • Updates only when new high is reached
  • Never decreases

For Short Positions:

  • Trough = Lowest low since entry
  • Updates only when new low is reached
  • Never increases

Example: Peak Tracking

Long Position Entry: ₹500

Candle 1: High ₹505, Low ₹498
Peak: ₹505

Candle 2: High ₹503, Low ₹500
Peak: ₹505 (unchanged)

Candle 3: High ₹510, Low ₹502
Peak: ₹510 (updated)

Candle 4: High ₹508, Low ₹504
Peak: ₹510 (unchanged)

Candle 5: High ₹515, Low ₹507
Peak: ₹515 (updated)

Drawdown Calculation

Drawdown from Peak = (Current Price - Peak) / Peak × 100

Example:

Peak: ₹520
Current: ₹505
Drawdown: (505 - 520) / 520 × 100 = -2.88%

If trail percentage is 3%, stop triggers at -3%

Combining Trailing Stops with Other Exits

Priority Order

When multiple exit conditions are configured, they execute in this order:

  1. Opposite Signal
  2. Partial Exits
  3. Break-even Stop
  4. Stop Loss
  5. Trailing Stop ← 5th priority
  6. Take Profit
  7. Time Exit

Example: Trailing Stop vs Take Profit

{
"exitConditions": {
"takeProfit": {
"enabled": true,
"type": "percentage",
"percentage": 5.0
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 3.0,
"activationThreshold": 2.0
}
}
}

Scenario 1: Take Profit Reached First

Entry: ₹500
Take Profit: 5% = ₹525
Trail: 3%, Activation: 2%

₹500 → ₹510 → ₹520 → ₹525
Exit at ₹525 (take profit)
Trailing never triggers

Scenario 2: Trailing Stop Triggers First

Entry: ₹500
Take Profit: 5% = ₹525
Trail: 3%, Activation: 2%

₹500 → ₹510 (trailing activates)
₹510 → ₹520 (peak: ₹520, stop: ₹504.40)
₹520 → ₹505 (stop triggered)
Exit at ₹504.40 (trailing stop)

Combining with Partial Exits

{
"exitConditions": {
"partialExits": {
"enabled": true,
"targets": [
{ "profitPercentage": 2.0, "exitPercentage": 33 },
{ "profitPercentage": 4.0, "exitPercentage": 33 }
]
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 3.0,
"activationThreshold": 1.0
}
}
}

How It Works:

  1. At 2% profit: Exit 33% of position
  2. At 4% profit: Exit another 33% of position
  3. Remaining 34%: Managed by trailing stop

This locks in some profits while letting the rest run!

Visual Diagram: Trailing Stop Behavior

Long Position Example:

Price

│ ╱╲
│ ╱ ╲ ╱╲
│ ╱ ╲ ╱ ╲
│ ╱ ╲ ╱ ╲
│ ╱ ╲ ╱ ╲
│╱ ╲ ╱ ╲___
├────────────┴──────────────► Time
│ │
│ └─ Stop triggered here

Stop Line (trails below price):
│ ___
│ _╱ ╲___
│ _╱ ╲___
│ _╱ ╲
│_╱
└────────────────────────────► Time

Key Points:
- Stop only moves up (never down)
- Maintains fixed distance from peak
- Triggers when price crosses stop line

Complete Configuration Examples

Example 1: Conservative Day Trading

{
"name": "Conservative Day Trading with Trailing",
"exitConditions": {
"stopLoss": {
"enabled": true,
"type": "percentage",
"percentage": 2.0
},
"takeProfit": {
"enabled": true,
"type": "percentage",
"percentage": 6.0
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 2.0,
"activationThreshold": 1.5
}
}
}

Strategy:

  • 2% stop loss protects downside
  • 6% take profit caps maximum gain
  • 2% trailing stop locks in profits after 1.5% gain
  • Good for: Consistent, moderate gains

Example 2: Aggressive Trend Following

{
"name": "Aggressive Trend Following",
"exitConditions": {
"stopLoss": {
"enabled": true,
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.0
},
"trailingStop": {
"enabled": true,
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.5,
"activationThreshold": 2.0
}
}
}

Strategy:

  • ATR-based stop loss adapts to volatility
  • Wide ATR trailing (2.5x) lets trends run
  • No take profit - let winners run indefinitely
  • Good for: Capturing large moves

Example 3: Scalping with Tight Trailing

{
"name": "Scalping Strategy",
"exitConditions": {
"stopLoss": {
"enabled": true,
"type": "percentage",
"percentage": 0.5
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 0.3,
"activationThreshold": 0.2
},
"timeBasedExit": {
"enabled": true,
"maxHoldTime": 15
}
}
}

Strategy:

  • Very tight stops (0.5%)
  • Very tight trailing (0.3%)
  • Activates quickly (0.2%)
  • Maximum 15 minutes hold time
  • Good for: Quick scalps in liquid markets

Example 4: Swing Trading with Partial Exits

{
"name": "Swing Trading with Scaling Out",
"exitConditions": {
"stopLoss": {
"enabled": true,
"type": "percentage",
"percentage": 3.0
},
"partialExits": {
"enabled": true,
"targets": [
{ "profitPercentage": 3.0, "exitPercentage": 50 }
],
"moveStopToEntry": true
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 4.0,
"activationThreshold": 2.0
}
}
}

Strategy:

  • 3% stop loss
  • Exit 50% at 3% profit, move stop to entry
  • Remaining 50% managed by 4% trailing stop
  • Good for: Risk-free runners

Verification

After configuring trailing stops, verify:

  1. Activation threshold is appropriate

    • Should be > 0 to avoid immediate activation
    • Typically 1-3% for most strategies
    • Test in paper trading first
  2. Trail distance matches your style

    • Tighter for scalping/day trading
    • Wider for swing/position trading
    • Consider average volatility of instruments
  3. Interaction with other exits is clear

    • Understand priority order
    • Test scenarios where multiple exits could trigger
    • Ensure take profit isn't too close to activation threshold
  4. ATR settings are reasonable (if using ATR-based)

    • Check ATR values for your instruments
    • Ensure multiplier gives adequate room
    • Verify period matches your timeframe

Troubleshooting

Trailing Stop Activates Too Early

Problem: Stop triggers immediately after activation, missing larger moves.

Solution:

  • Increase trail percentage/ATR multiplier
  • Increase activation threshold
  • Consider market volatility
{
"trailingStop": {
"trailPercentage": 4.0, // Increased from 2.0
"activationThreshold": 2.5 // Increased from 1.5
}
}

Trailing Stop Never Activates

Problem: Activation threshold is never reached.

Solution:

  • Reduce activation threshold
  • Check if stop loss is too tight
  • Verify strategy generates profitable trades
{
"trailingStop": {
"activationThreshold": 1.0 // Reduced from 3.0
}
}

Giving Back Too Much Profit

Problem: Trailing stop allows too much profit give-back.

Solution:

  • Reduce trail percentage/ATR multiplier
  • Consider using partial exits to lock in some profit
  • Use tighter trailing for volatile instruments
{
"trailingStop": {
"trailPercentage": 2.0 // Reduced from 4.0
}
}

ATR-Based Stop Too Wide

Problem: ATR-based trailing gives too much room.

Solution:

  • Reduce ATR multiplier
  • Use shorter ATR period for more responsiveness
  • Consider percentage-based trailing instead
{
"trailingStop": {
"atrMultiplier": 1.5, // Reduced from 2.5
"atrPeriod": 10 // Reduced from 14
}
}

Conflicts with Take Profit

Problem: Take profit always triggers before trailing stop.

Solution:

  • Increase take profit target
  • Reduce trailing activation threshold
  • Consider removing take profit to let trailing manage exits
{
"takeProfit": {
"percentage": 8.0 // Increased from 4.0
},
"trailingStop": {
"activationThreshold": 1.0 // Reduced from 2.0
}
}

Best Practices

  1. Start with moderate settings

    • 3% trail, 2% activation for swing trading
    • Test in paper trading before going live
  2. Match trailing to timeframe

    • Shorter timeframes = tighter trailing
    • Longer timeframes = wider trailing
  3. Consider market conditions

    • Trending markets: Use wider trailing
    • Ranging markets: Use tighter trailing or disable
  4. Combine with partial exits

    • Lock in some profit at fixed targets
    • Let remainder run with trailing stop
  5. Monitor and adjust

    • Review stopped trades
    • Check if stops are too tight or too wide
    • Optimize based on performance data
  6. Use ATR for multi-instrument strategies

    • Automatically adapts to different volatilities
    • More robust across various instruments
  7. Don't over-optimize

    • Simple settings often work best
    • Avoid curve-fitting to historical data
    • Focus on robust, logical parameters