OPEN-SOURCE SCRIPT
ATR-Based SL/TP Strategy

This Pine Script strategy demonstrates how to use the Average True Range (ATR) as a dynamic method for setting stop loss and take profit levels. It is provided as an*educational resource to help traders understand how volatility-based exits can be implemented in automated strategies.
Full credit for the source code to Intertia
How It Works:
1. Entry Logic:
- The strategy uses the Relative Strength Index (RSI) to identify potential entry points.
- A long trade is triggered when the RSI crosses above the oversold threshold.
- A short trade is triggered when the RSI crosses below the overbought threshold.
2. Exit Logic (ATR-Based):
- Once in a trade, the strategy calculates the Average True Range (ATR) to determine a stop loss and take profit based on recent price volatility.
- For long trades, the stop loss is set below the entry price by a multiple of the ATR, and the take profit is set above the entry by a larger multiple.
- For short trades, the stop loss is above and the take profit is below the entry, also based on ATR multipliers.
- This ensures exit levels adjust automatically depending on current market volatility.
3. Customizable Parameters:
- Traders can adjust the ATR length, stop loss multiplier, and take profit multiplier to match their risk preferences.
- RSI settings (period, overbought, and oversold levels) are also configurable to adapt to different market conditions.
Visualization:
- ATR is calculated but hidden by default from the chart view for a cleaner layout.
- Entry points are optionally marked with labels for easier debugging and educational review.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.
Skrip sumber terbuka
Dalam semangat TradingView sebenar, pencipta skrip ini telah menjadikannya sumber terbuka, jadi pedagang boleh menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupuan anda boleh menggunakan secara percuma, ingat bahawa penerbitan semula kod ini tertakluk kepada Peraturan Dalaman.
Penafian
Maklumat dan penerbitan adalah tidak bertujuan, dan tidak membentuk, nasihat atau cadangan kewangan, pelaburan, dagangan atau jenis lain yang diberikan atau disahkan oleh TradingView. Baca lebih dalam Terma Penggunaan.