OPEN-SOURCE SCRIPT
[Top] Simple ATR TP/SL

Simple TP/SL from ATR (Locked per Bar) - Advanced Position Management Tool
What This Indicator Does:
Original Features That Make This Script Unique:
How The Algorithm Works:
Direction Modes Explained:
Key Input Parameters:
How To Use This Indicator:
Visual Style Customization:
Best Practices:
What This Indicator Does:
- Automatically calculates and displays Take Profit (TP) and Stop Loss (SL) levels based on Average True Range (ATR)
- Locks ATR values and direction signals at the start of each bar to prevent repainting and provide consistent levels
- Offers multiple direction detection modes including real-time candle-based positioning for dynamic trading approaches
- Displays entry, TP, and SL levels as clean horizontal lines that extend from the current bar
Original Features That Make This Script Unique:
- Bar-Locked ATR System: ATR values are captured and frozen at bar open, ensuring levels remain stable throughout the bar's progression
- Multi-Modal Direction Detection: Four distinct modes for determining TP/SL positioning - Trend Following (EMA-based), Bullish Only, Bearish Only, and real-time Candle Based
- Real-Time Candle Flipping: In Candle Based mode, TP/SL levels flip immediately when the current candle changes from bullish to bearish or vice versa
- Persistent Line Management: Uses efficient line object management to prevent ghost lines and maintain clean visual presentation
- Flexible Base Price Selection: Choose between Open (static), Close (dynamic), or midpoint (H+L)/2 for entry level calculation
How The Algorithm Works:
- ATR Calculation: Captures ATR value at each bar open using specified length parameter, maintaining consistency throughout the bar
- Direction Determination: Uses different methods based on selected mode - EMA crossover for trend following, or real-time candle color for dynamic positioning
- Level Calculation: TP level = Base Price + (Direction × TP Multiplier × ATR), SL level = Base Price - (Direction × SL Multiplier × ATR)
- Visual Management: Creates persistent line objects once, then updates their positions every bar for optimal performance
Direction Modes Explained:
- Trend Following: Uses 5-period and 12-period EMA relationship to determine trend direction (locked at bar open)
- Bullish Only: Always places TP above and SL below entry (traditional long setup)
- Bearish Only: Always places TP below and SL above entry (traditional short setup)
- Candle Based: Dynamically adjusts based on current candle direction - flips in real-time as candle develops
Key Input Parameters:
- ATR Length: Period for ATR calculation (default 14) - longer periods provide smoother volatility measurement
- TP Multiplier: Take profit distance as multiple of ATR (default 1.0) - higher values target larger profits
- SL Multiplier: Stop loss distance as multiple of ATR (default 1.0) - higher values allow more room for price movement
- Base Price: Reference point for level calculations - Open for static entry, Close for dynamic tracking
- Direction Mode: Method for determining whether TP goes above or below entry level
How To Use This Indicator:
- For Position Sizing: Use the displayed SL distance to calculate appropriate position size based on your risk tolerance
- For Entry Timing: Wait for price to approach the entry level before taking positions
- For Risk Management: Set your actual stop loss orders at or near the displayed SL level
- For Profit Taking: Use the TP level as initial profit target, consider scaling out at this level
- Mode Selection: Choose Candle Based for scalping and quick reversals, Trend Following for swing trading
Visual Style Customization:
- Line Colors: Customize TP line color (default teal) and SL line color (default orange) for easy identification
- Line Widths: Adjust TP/SL line thickness (1-5) and entry line thickness (1-3) for visibility preferences
- Clean Display: Lines extend 3 bars forward from current bar and update position dynamically
Best Practices:
- Use on clean charts without multiple overlapping indicators for clearest visual interpretation
- Combine with volume analysis and key support/resistance levels for enhanced decision making
- Adjust ATR length based on your trading timeframe - shorter for scalping, longer for position trading
- Test different TP/SL multipliers based on the volatility characteristics of your chosen instruments
- Consider using Trend Following mode during strong trending periods and Candle Based during ranging markets
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.
Açık kaynak kodlu komut dosyası
Gerçek TradingView ruhuna uygun olarak, bu komut dosyasının oluşturucusu bunu açık kaynaklı hale getirmiştir, böylece yatırımcılar betiğin işlevselliğini inceleyip doğrulayabilir. Yazara saygı! Ücretsiz olarak kullanabilirsiniz, ancak kodu yeniden yayınlamanın Site Kurallarımıza tabi olduğunu unutmayın.
Feragatname
Bilgiler ve yayınlar, TradingView tarafından sağlanan veya onaylanan finansal, yatırım, işlem veya diğer türden tavsiye veya tavsiyeler anlamına gelmez ve teşkil etmez. Kullanım Şartları'nda daha fazlasını okuyun.