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. קרא עוד ב־תנאי השימוש.