Guide
How does the Trailing Stop Snippet strategy work ?
The Trailing Stop Snippet is designed to enhance your trading strategy with a dynamic stop-loss mechanism. The key components are the trailing stop itself and the option to activate it once the price reaches a specific percentage gain from your entry point. The mechanism works as follows:
- Initialise the strategy by specifying the length for the momentum calculation and the percentage values for trailing stop activation (tsact) and trailing stop (ts).
- Identify if you're in a long or short position based on your current position size.
- Dynamically update the trailing stop's level as the price moves favorably for your position. For a long position, the script will increase the trailing stop when a new high is reached. For a short position, it will update when a new low is formed.
- If the trailing stop activation is set, the trailing stop will not engage until the price has moved in your favor by the specified percentage. For instance, if you want the trailing stop to activate once you're up 5%, tsact should be set to 5.
- The trailing stop will then maintain a stop-loss at the specified distance (ts) from the highest (for longs) or lowest (for shorts) price since activation.
- Entry signals are generated based on momentum conditions, and the strategy will close positions if the trailing stop criterion is met.
This strategic snippet, facilitated by TradingView's Pine Script, allows for an adjustable safety net that can help protect gains or limit losses dynamically as market conditions change.