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.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน