How to Setup Exit Conditions
Problem
You need to define precise rules for when your algorithm should exit trades to protect profits and limit losses. Proper exit conditions are crucial for risk management and maximizing returns.
Prerequisites
- Basic algorithm configuration completed (Step 1)
- Position sizing configured (Step 2)
- Entry conditions configured (Step 3)
- Understanding of risk management principles
Exit Priority Order
When multiple exit conditions are met simultaneously, only the first one in priority order executes:
- Opposite Signal - Reverse position
- Partial Exits - Scale out at targets
- Break-even Stop - Move stop to entry
- Stop Loss - Limit losses
- Trailing Stop - Lock in profits
- Take Profit - Realize gains
- Time Exit - Close after duration
Stop Loss Types
1. Fixed Stop Loss
Exit at a specific price level.
{
"exitConditions": {
"stopLoss": {
"type": "fixed",
"price": 495
}
}
}
When to Use:
- Support/resistance levels
- Specific price targets
- Manual risk management
Example:
- Entry: ₹500
- Stop Loss: ₹495
- Risk: ₹5 per share
2. Percentage Stop Loss
Exit when price moves against you by a percentage.
{
"exitConditions": {
"stopLoss": {
"type": "percentage",
"percentage": 2.0
}
}
}
Calculation:
Long Position:
Stop Price = Entry Price × (1 - Stop %)
Short Position:
Stop Price = Entry Price × (1 + Stop %)
Examples:
Long Position:
- Entry: ₹500
- Stop: 2%
- Stop Price: ₹500 × (1 - 0.02) = ₹490
- Risk: ₹10 per share
Short Position:
- Entry: ₹500
- Stop: 2%
- Stop Price: ₹500 × (1 + 0.02) = ₹510
- Risk: ₹10 per share
Recommended Percentages by Volatility:
| Volatility | Stop % | Use Case |
|---|---|---|
| Low | 1-2% | Large caps, stable stocks |
| Medium | 2-3% | Mid caps, normal volatility |
| High | 3-5% | Small caps, volatile stocks |
3. ATR-Based Stop Loss
Dynamic stop based on Average True Range (volatility).
{
"exitConditions": {
"stopLoss": {
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.0
}
}
}
Calculation:
Stop Distance = ATR(period) × Multiplier
Stop Price = Entry Price ± Stop Distance
Examples:
Low Volatility (ATR = ₹5):
- Entry: ₹500
- ATR: ₹5
- Multiplier: 2.0
- Stop Distance: ₹5 × 2.0 = ₹10
- Stop Price: ₹490 (long) or ₹510 (short)
High Volatility (ATR = ₹25):
- Entry: ₹500
- ATR: ₹25
- Multiplier: 2.0
- Stop Distance: ₹25 × 2.0 = ₹50
- Stop Price: ₹450 (long) or ₹550 (short)
ATR Period Selection:
- 14 periods (default): Standard, balanced
- 20 periods: Smoother, less sensitive
- 10 periods: More responsive
ATR Multiplier Effects:
- 1.5: Tighter stops, more stopped out
- 2.0: Balanced (recommended)
- 2.5: Wider stops, fewer false stops
- 3.0: Very wide, for trending markets
Advantages:
- Adapts to market volatility
- Wider stops in volatile markets
- Tighter stops in calm markets
- Reduces false stops
4. Indicator-Based Stop Loss
Use technical indicators as dynamic stops.
{
"exitConditions": {
"stopLoss": {
"type": "indicator",
"indicator": "EMA",
"period": 20
}
}
}
Common Indicators:
Moving Average Stop:
{
"stopLoss": {
"type": "indicator",
"indicator": "EMA",
"period": 20
}
}
- Long: Exit if price closes below EMA(20)
- Short: Exit if price closes above EMA(20)
Parabolic SAR Stop:
{
"stopLoss": {
"type": "indicator",
"indicator": "ParabolicSAR"
}
}
- Automatically adjusts with price movement
- Excellent for trending markets
Bollinger Band Stop:
{
"stopLoss": {
"type": "indicator",
"indicator": "Bollinger_Middle",
"period": 20
}
}
- Exit if price crosses middle band
When to Use:
- Trend-following strategies
- Dynamic risk management
- Letting winners run
Update Frequency:
- Stops update every candle close
- Never moves against you (only in your favor)
Take Profit Types
1. Fixed Take Profit
Exit at a specific price level.
{
"exitConditions": {
"takeProfit": {
"type": "fixed",
"price": 520
}
}
}
When to Use:
- Resistance levels
- Round numbers
- Specific targets
Example:
- Entry: ₹500
- Take Profit: ₹520
- Profit: ₹20 per share (4%)
2. Percentage Take Profit
Exit when profit reaches a percentage.
{
"exitConditions": {
"takeProfit": {
"type": "percentage",
"percentage": 5.0
}
}
}
Calculation:
Long Position:
Target Price = Entry Price × (1 + Profit %)
Short Position:
Target Price = Entry Price × (1 - Profit %)
Examples:
Long Position:
- Entry: ₹500
- Target: 5%
- Target Price: ₹500 × 1.05 = ₹525
- Profit: ₹25 per share
Short Position:
- Entry: ₹500
- Target: 5%
- Target Price: ₹500 × 0.95 = ₹475
- Profit: ₹25 per share
Typical Percentages:
| Strategy | Target % | Holding Period |
|---|---|---|
| Scalping | 0.5-1% | Minutes |
| Day Trading | 1-3% | Hours |
| Swing Trading | 3-10% | Days |
| Position Trading | 10-30% | Weeks/Months |
3. Risk-Reward Based Take Profit
Calculate take profit based on stop loss distance.
{
"exitConditions": {
"takeProfit": {
"type": "risk_reward",
"ratio": 2.0
},
"stopLoss": {
"type": "percentage",
"percentage": 2.0
}
}
}
Calculation:
Profit Target = Stop Loss Distance × Risk-Reward Ratio
Examples:
1:2 Risk-Reward:
- Entry: ₹500
- Stop Loss: 2% (₹490)
- Risk: ₹10
- Ratio: 2.0
- Profit Target: ₹10 × 2 = ₹20
- Target Price: ₹520 (4% profit)
1:3 Risk-Reward:
- Entry: ₹500
- Stop Loss: 2% (₹490)
- Risk: ₹10
- Ratio: 3.0
- Profit Target: ₹10 × 3 = ₹30
- Target Price: ₹530 (6% profit)
Recommended Ratios:
| Ratio | Win Rate Needed | Use Case |
|---|---|---|
| 1:1 | 50%+ | High win rate strategies |
| 1:2 | 35%+ | Balanced (recommended) |
| 1:3 | 25%+ | Trend-following |
| 1:4 | 20%+ | Strong trends only |
4. Trailing Take Profit
Take profit that moves with price (rarely used, trailing stop is better).
{
"exitConditions": {
"takeProfit": {
"type": "trailing",
"trailPercentage": 2.0,
"activationThreshold": 3.0
}
}
}
How It Works:
- Activates after 3% profit
- Trails 2% behind peak price
- Exits if price drops 2% from peak
Note: Trailing stops are more commonly used for this purpose.
5. Multiple Targets (Partial Exits)
Scale out at different profit levels.
{
"exitConditions": {
"takeProfit": {
"type": "multiple_targets",
"targets": [
{
"percentage": 2.0,
"exitPercentage": 33
},
{
"percentage": 4.0,
"exitPercentage": 33
},
{
"percentage": 6.0,
"exitPercentage": 34
}
]
}
}
}
See Partial Exits section for details.
Trailing Stops
Lock in profits while letting winners run.
Percentage-Based Trailing
{
"exitConditions": {
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 2.0,
"activationThreshold": 3.0
}
}
}
How It Works:
- Activation: Trailing starts after 3% profit
- Tracking: System tracks peak price
- Trailing: Stop trails 2% behind peak
- Exit: Triggers if price drops 2% from peak
Example:
| Event | Price | Peak | Stop | Status |
|---|---|---|---|---|
| Entry | ₹500 | - | ₹490 (2% fixed) | Initial stop |
| +2% profit | ₹510 | - | ₹490 | Not activated yet |
| +3% profit | ₹515 | ₹515 | ₹504.70 | Activated! (2% trail) |
| +5% profit | ₹525 | ₹525 | ₹514.50 | Stop moved up |
| +7% profit | ₹535 | ₹535 | ₹524.30 | Stop moved up |
| Pullback | ₹530 | ₹535 | ₹524.30 | Still in trade |
| Pullback | ₹524 | ₹535 | ₹524.30 | Exit triggered! |
Final Result: Entered at ₹500, exited at ₹524 = 4.8% profit (locked in most of the 7% move)
ATR-Based Trailing
{
"exitConditions": {
"trailingStop": {
"enabled": true,
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.0,
"activationThreshold": 2.0
}
}
}
Advantages:
- Adapts to volatility
- Wider trail in volatile markets
- Tighter trail in calm markets
Example:
Low Volatility (ATR = ₹5):
- Peak: ₹525
- ATR: ₹5
- Multiplier: 2.0
- Trail Distance: ₹10
- Stop: ₹515
High Volatility (ATR = ₹15):
- Peak: ₹525
- ATR: ₹15
- Multiplier: 2.0
- Trail Distance: ₹30
- Stop: ₹495
Activation Threshold
{
"trailingStop": {
"activationThreshold": 3.0 // Start trailing after 3% profit
}
}
Why Use Activation Threshold:
- Prevents premature trailing
- Lets position breathe initially
- Only trails when in profit
Recommended Thresholds:
| Strategy | Threshold | Reason |
|---|---|---|
| Scalping | 0.5-1% | Quick profits |
| Day Trading | 1-2% | Small moves |
| Swing Trading | 2-5% | Larger moves |
| Position Trading | 5-10% | Major trends |
Trailing Stop Best Practices
- Set activation threshold - Don't trail immediately
- Match to volatility - Use ATR for volatile stocks
- Don't trail too tight - Give room for normal pullbacks
- Combine with take profit - Partial exit + trailing stop
Partial Exits
Scale out of positions at multiple profit levels.
Configuration
{
"exitConditions": {
"partialExits": {
"enabled": true,
"targets": [
{
"profitPercentage": 2.0,
"exitPercentage": 33,
"moveStopTo": "breakeven"
},
{
"profitPercentage": 4.0,
"exitPercentage": 33,
"moveStopTo": "entry_plus_1"
},
{
"profitPercentage": 6.0,
"exitPercentage": 34,
"moveStopTo": null
}
]
}
}
}
How It Works
Initial Position: 300 shares at ₹500
Target 1 (2% profit - ₹510):
- Exit: 33% = 100 shares
- Remaining: 200 shares
- Move stop to breakeven (₹500)
Target 2 (4% profit - ₹520):
- Exit: 33% = 100 shares
- Remaining: 100 shares
- Move stop to entry + 1% (₹505)
Target 3 (6% profit - ₹530):
- Exit: 34% = 100 shares
- Remaining: 0 shares
- Position closed
Profit Targets
{
"targets": [
{ "profitPercentage": 2.0 }, // First target
{ "profitPercentage": 4.0 }, // Second target
{ "profitPercentage": 6.0 } // Third target
]
}
Common Patterns:
Conservative (2%, 4%, 6%):
- Quick profits
- Reduces risk fast
- Good for choppy markets
Moderate (3%, 6%, 9%):
- Balanced approach
- Standard spacing
- Most common
Aggressive (5%, 10%, 15%):
- Lets winners run
- Higher risk
- Trending markets only
Exit Percentages
{
"targets": [
{ "exitPercentage": 33 }, // Exit 1/3
{ "exitPercentage": 33 }, // Exit 1/3
{ "exitPercentage": 34 } // Exit remaining
]
}
Common Patterns:
Equal Thirds (33%, 33%, 34%):
- Balanced scaling
- Most common
Front-Loaded (50%, 30%, 20%):
- Lock in profits quickly
- Reduce risk fast
Back-Loaded (20%, 30%, 50%):
- Let winners run
- Higher risk
Move Stop To
{
"targets": [
{ "moveStopTo": "breakeven" }, // Move to entry price
{ "moveStopTo": "entry_plus_1" }, // Move to entry + 1%
{ "moveStopTo": "entry_plus_2" } // Move to entry + 2%
]
}
Options:
null: Don't move stop"breakeven": Move to entry price"entry_plus_1": Move to entry + 1%"entry_plus_2": Move to entry + 2%"entry_plus_3": Move to entry + 3%
Strategy:
- First target: Move to breakeven (risk-free)
- Second target: Lock in small profit
- Third target: Let remaining run
Hit Targets Tracking
System tracks which targets have been hit:
{
"hitTargets": [true, true, false]
}
- Target 1: ✅ Hit
- Target 2: ✅ Hit
- Target 3: ❌ Not hit yet
Remaining Position Management
After partial exits, remaining position continues with:
- Original stop loss (or moved stop)
- Trailing stop (if enabled)
- Remaining take profit targets
Break-Even Stop
Automatically move stop to entry price after profit threshold.
{
"exitConditions": {
"breakEvenStop": {
"enabled": true,
"triggerProfit": 1.0,
"offset": 0.1
}
}
}
How It Works:
- Trigger: After 1% profit
- Move Stop: To entry + 0.1% (safety buffer)
- Result: Risk-free trade
Example:
- Entry: ₹500
- Initial Stop: ₹490 (2% stop loss)
- Price reaches: ₹505 (1% profit)
- Stop moves to: ₹500.50 (entry + 0.1%)
- Now risk-free!
Offset Purpose:
- Prevents stop from being exactly at entry
- Avoids exit on minor pullback to entry
- 0.1% buffer is standard
Recommended Settings:
| Strategy | Trigger | Offset |
|---|---|---|
| Scalping | 0.5% | 0.05% |
| Day Trading | 1% | 0.1% |
| Swing Trading | 2% | 0.2% |
Exit on Opposite Signal
Close position when opposite entry signal occurs.
{
"exitConditions": {
"exitOnOppositeSignal": {
"enabled": true,
"closeImmediately": true
}
}
}
How It Works:
Long Position:
- Holding long position
- Short entry signal triggers
- Close long immediately
- Optionally enter short
Short Position:
- Holding short position
- Long entry signal triggers
- Close short immediately
- Optionally enter long
Close Immediately Options:
{
"closeImmediately": true // Market order, instant exit
}
{
"closeImmediately": false // Wait for next candle close
}
When to Use:
- Reversal strategies
- Mean reversion
- Oscillating markets
- Quick direction changes
Example:
{
"entryConditions": {
"positionType": "both",
"longConditions": [
{ "indicator": "RSI", "comparison": "below", "value": 30 }
],
"shortConditions": [
{ "indicator": "RSI", "comparison": "above", "value": 70 }
]
},
"exitConditions": {
"exitOnOppositeSignal": {
"enabled": true,
"closeImmediately": true
}
}
}
- Long when RSI < 30
- Exit long when RSI > 70
- Enter short when RSI > 70
- Exit short when RSI < 30
Time-Based Exits
Close positions after a maximum hold time.
{
"exitConditions": {
"timeBasedExit": {
"enabled": true,
"maxHoldMinutes": 240
}
}
}
Examples:
// Scalping (5-30 minutes)
{
"maxHoldMinutes": 30
}
// Day Trading (1-4 hours)
{
"maxHoldMinutes": 240
}
// Swing Trading (1-5 days)
{
"maxHoldMinutes": 7200 // 5 days
}
When to Use:
- Intraday strategies (must close by EOD)
- Time-decay strategies (options)
- Prevent overnight risk
- Scalping strategies
Partial Time Exits
Exit portions of position over time:
{
"exitConditions": {
"timeBasedExit": {
"enabled": true,
"partialExits": [
{
"minutes": 60,
"exitPercentage": 50
},
{
"minutes": 120,
"exitPercentage": 50
}
]
}
}
}
- After 1 hour: Exit 50%
- After 2 hours: Exit remaining 50%
Complete Exit Configuration Examples
Example 1: Conservative Day Trading
{
"exitConditions": {
"stopLoss": {
"type": "percentage",
"percentage": 1.5
},
"takeProfit": {
"type": "risk_reward",
"ratio": 2.0
},
"breakEvenStop": {
"enabled": true,
"triggerProfit": 1.0,
"offset": 0.1
},
"timeBasedExit": {
"enabled": true,
"maxHoldMinutes": 240
}
}
}
Logic:
- 1.5% stop loss
- 3% take profit (1:2 risk-reward)
- Move to breakeven after 1% profit
- Close after 4 hours
Example 2: Swing Trading with Partial Exits
{
"exitConditions": {
"stopLoss": {
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.0
},
"partialExits": {
"enabled": true,
"targets": [
{
"profitPercentage": 3.0,
"exitPercentage": 33,
"moveStopTo": "breakeven"
},
{
"profitPercentage": 6.0,
"exitPercentage": 33,
"moveStopTo": "entry_plus_2"
},
{
"profitPercentage": 9.0,
"exitPercentage": 34,
"moveStopTo": null
}
]
},
"trailingStop": {
"enabled": true,
"type": "percentage",
"trailPercentage": 3.0,
"activationThreshold": 5.0
}
}
}
Logic:
- ATR-based stop (adapts to volatility)
- Scale out at 3%, 6%, 9%
- Move stop to breakeven, then entry+2%
- Trailing stop activates after 5% profit
Example 3: Trend Following with Trailing Stop
{
"exitConditions": {
"stopLoss": {
"type": "indicator",
"indicator": "EMA",
"period": 20
},
"trailingStop": {
"enabled": true,
"type": "atr",
"atrPeriod": 14,
"atrMultiplier": 2.5,
"activationThreshold": 3.0
},
"exitOnOppositeSignal": {
"enabled": true,
"closeImmediately": false
}
}
}
Logic:
- EMA(20) as initial stop
- ATR trailing stop after 3% profit
- Exit on opposite signal
Verification
After configuring exit conditions, verify:
-
Stop loss is appropriate
- Not too tight (false stops)
- Not too wide (excessive risk)
- Matches volatility
-
Take profit is realistic
- Based on historical moves
- Risk-reward ratio is favorable
- Achievable in timeframe
-
Trailing stop settings
- Activation threshold is reasonable
- Trail distance allows for pullbacks
- Matches strategy style
-
Partial exits make sense
- Targets are achievable
- Exit percentages are balanced
- Stop management is logical
-
Priority order is correct
- Most important exits have priority
- No conflicts between exits
Troubleshooting
Stopped Out Too Often
Problem: Stop loss triggers frequently.
Solutions:
- Widen stop loss percentage
- Use ATR-based stops (adapts to volatility)
- Increase ATR multiplier
- Use indicator-based stops
- Add confirmation candles to entries
Never Hitting Take Profit
Problem: Take profit targets are never reached.
Solutions:
- Reduce take profit percentage
- Use partial exits (scale out)
- Implement trailing stops
- Check if targets are realistic
- Analyze historical price moves
Trailing Stop Too Tight
Problem: Trailing stop exits too early.
Solutions:
- Increase trail percentage
- Use ATR-based trailing
- Increase ATR multiplier
- Raise activation threshold
- Give more room for pullbacks
Partial Exits Not Executing
Problem: Partial exit targets never hit.
Solutions:
- Reduce profit percentages
- Check if targets are realistic
- Verify position size is divisible
- Ensure targets are in correct order
Break-Even Stop Triggered Immediately
Problem: Stop moves to breakeven and exits immediately.
Solutions:
- Increase trigger profit threshold
- Add larger offset (0.2-0.5%)
- Wait for more profit before moving stop
- Use trailing stop instead