This Pine Script code plots the "ATR+StdTR Band and Trailing Stop," serving as a tool for volatility-based risk management and trend detection. While bands are typically set using a multiple of ATR, this script uses StdTR (the True Range standard deviation) and sets the band width based on ±(ATR + n times StdTR). StdTR is a great tool for detecting price volatility and anomalies, allowing traders to adapt to rapid changes in extreme market conditions. This helps traders proactively manage risk during sudden market fluctuations.
The following features are provided:
Table Display
A table is shown on the chart, allowing traders to visually track the current ATR value, StdTR (σ), and the long/short stop-loss levels (±ATR ± nσ). This enables real-time monitoring of risk management data.
Band Plots
The script plots bands that combine ATR with StdTR (nσ).
The upper and lower bands are calculated using the previous candle’s closing price (the source is customizable) and are plotted as ±(ATR + nσ), providing a clear visual of the price range.
ATR ± nσ Trailing Stop
The trailing stop dynamically adjusts the stop-loss levels based on price movements. In an uptrend, the stop-loss rises, while in a downtrend, it lowers, helping traders lock in profits while minimizing losses during significant reversals.
Breakout Detection
Breakouts are detected when the price exceeds the upper band or drops below the lower band. A visual marker (X) is displayed on the chart, allowing traders to quickly recognize when the price has moved beyond normal volatility ranges, making it easier to respond to trend formations or reversals.
Customization Points:
The ATR period and StdTR (n) are fully customizable.
The source for ATR band calculation can be adjusted, allowing traders to choose from close, open, high, low, etc.
The table’s display position and design (text color, size, etc.) can be customized to present the information clearly and effectively.