Hi Team,
I need to understand the trailing Stop Loss (SL) logic for options and stocks, including how to implement it. A video tutorial would be great if available. Specifically, I’m looking at (ATR + fixed point) trailing SL.
For example:
- Initial Entry: 100, SL: 70
- Market moves to 110, SL trails to 75
- Market moves to 120, SL trails to 80
In this case, for every 10-point favorable market move, the SL trails by 5 points.
Would the ATR-based trailing work the same way?
Thanks!
Hi @mahendra.beit ,
Yes, ATR-based trailing can work in a similar manner.
For example, suppose:
- Entry Price = 100
- Initial SL = 70
- ATR = 8
- Fixed buffer = 3
Then:
- ATR + fixed buffer = 8 + 3 = 11 points
For a buy trade, trailing SL can be calculated as:
- New SL = Current Price - 11
So if price moves:
- Price = 110 → SL = 110 - 11 = 99
- Price = 120 → SL = 120 - 11 = 109
- Price = 130 → SL = 130 - 11 = 119
This means the stop loss keeps moving upward as price moves in your favor, based on the ATR value plus the fixed points buffer.
which one is best ATR or fixed SL move is best in this case and give me code level some idea on this ?
HI @mahendra.beit ,
The stop-loss movement method should be chosen based on the nature of the strategy.
Refer the below sample code :
if side == "BUY":
sl_price = entry_price - sl_points
if ltp >= entry_price + trail_start_points:
steps = int((ltp - (entry_price + trail_start_points)) // trail_step_points) + 1
new_sl = entry_price + (steps * trail_move_points)
sl_price = max(sl_price, new_sl)
elif side == "SELL":
sl_price = entry_price + sl_points
if ltp <= entry_price - trail_start_points:
steps = int(((entry_price - trail_start_points) - ltp) // trail_step_points) + 1
new_sl = entry_price - (steps * trail_move_points)
sl_price = min(sl_price, new_sl)