OPEN-SOURCE SCRIPT
已更新 Custom ATR Trailing Stop

This Script creates a custom ATR (Average True Range) trailing stop. It allows traders to set up automated stop-loss levels based on the ATR, which adjusts dynamically to market volatility. The script is designed to support both long and short trades, offering flexibility and precision in trade management.
When loading the indicator to your chart, simply click to set the trade begining time, confirm various settings and you are set.
Check tooltips for more details in the input settigns menu.
User Inputs
ATR Calculations
Signal Validation
Trailing Stop Logic
Plotting
When loading the indicator to your chart, simply click to set the trade begining time, confirm various settings and you are set.
Check tooltips for more details in the input settigns menu.
User Inputs
- Trade Setup: Allows users to set the trade direction (Long or Short), the signal source for entries, and the specific bar time for the trade setup.
- ATR Settings: Configurable ATR lookback period, ATR smoothing period, initial ATR multiplier for setting the stop-loss, breakeven ATR multiplier, and a manual breakeven level.
ATR Calculations
- Computes the ATR and its moving average.
- Determines initial and breakeven stop levels based on the ATR.
Signal Validation
- Validates long or short trade signals based on the specified bar time and trade direction.
- Triggers alerts when a valid trade signal is detected.
Trailing Stop Logic
- For long trades, adjusts the stop-loss level dynamically based on the ATR.
- For short trades, performs similar adjustments in the opposite direction.
- Updates the trailing stop level to ensure it follows the price, moving closer as the price moves favorably.
- Resets the trade state when the stop-loss is hit, triggering an alert.
Plotting
- Plots the trailing stop levels on the chart.
- Uses green for stop levels indicating profit and red for stop levels indicating a loss.
版本注释
V2- Large candles trailing stop bug fix
After a large candle closes, the recalculated trailing stop loss (TSL) would sometimes be higher than the candle's low (vice-versa for shorts). This led to the TSL not calculating anymore, causing issues with plots and alerts. This problem has been fixed: a dotted lines will now show in such cases and alerts will trigger correctly.
版本注释
V3- New trailing method: Percentage only
- Drop down menu to select trailing method
- Improved dotted lines display
- Source input bug fix
- Updated to Pinescript V6
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。
开源脚本
本着TradingView的真正精神,此脚本的创建者将其开源,以便交易者可以查看和验证其功能。向作者致敬!虽然您可以免费使用它,但请记住,重新发布代码必须遵守我们的网站规则。
免责声明
这些信息和出版物并不意味着也不构成TradingView提供或认可的金融、投资、交易或其它类型的建议或背书。请在使用条款阅读更多信息。