OPEN-SOURCE SCRIPT
SR Breakout Arrows

# SR Breakout Arrows - Documentation
> **Version**: v1.0
> **Author**: jeffprotrader168
> **Pine Script Version**: v6
> **License**: Mozilla Public License 2.0
---
## 📊 Overview
A fractal-based Support/Resistance breakout detection indicator. Uses `ta.pivothigh` / `ta.pivotlow` to identify local highs and lows as S/R levels, then signals with arrows when price breaks through these levels. Features optional RSI/CCI filtering and anti-repaint protection. Works on all markets and timeframes.
Ported from MQL4 (originally by Barry Stander 2004 / Lennoi Anderson 2015 / rewritten by Jeff Reed).
---
## 🎯 Key Features
- **Fractal-based S/R Detection**: Confirms fractals with 2 bars on each side, auto-extends horizontal lines until next fractal
- **Breakout Arrow Signals**: Draws triangle arrows below/above bars when close breaks S/R levels
- **Anti-Repaint Guarantee**: Signals only confirmed after bar close by default; historical arrows never disappear
- **RSI/CCI Filtering**: Optional dual-filter to reduce false breakouts
- **Deduplication**: Each S/R level triggers only one signal, preventing consecutive duplicate arrows
- **Bilingual Interface**: English / Traditional Chinese toggle
- **Full Color Customization**: S/R lines and arrow colors are fully configurable
---
## ⚙️ Configuration
### ⚙️ Basic Settings
| Parameter | Default | Description |
|-----------|---------|-------------|
| `i_language` | EN | Language selection (EN / Traditional Chinese) |
### 📊 Signal Settings
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| `i_signal_dots` | 3 | [1, 50] | Minimum bars after fractal before breakout is valid; higher = more conservative |
| `i_apply_to_close` | true | — | When enabled, signals only appear after bar closes (anti-repaint) |
### 🔍 RSI/CCI Filter
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| `i_rsicci_filter` | false | — | Enable RSI+CCI dual filtering |
| `i_rsi_period` | 14 | [2, 200] | RSI calculation period |
| `i_rsi_overbought` | 75.0 | — | RSI overbought level (buy signals require RSI below this) |
| `i_rsi_oversold` | 25.0 | — | RSI oversold level (sell signals require RSI above this) |
| `i_cci_period` | 14 | [2, 200] | CCI calculation period |
| `i_cci_buy_level` | 50.0 | — | CCI buy threshold (buy signals require CCI above this) |
| `i_cci_sell_level` | -50.0 | — | CCI sell threshold (sell signals require CCI below this) |
### 🎨 Display
| Parameter | Default | Description |
|-----------|---------|-------------|
| `i_show_arrows` | true | Show breakout arrows |
| `i_show_sr_lines` | true | Show S/R extension lines |
| `i_res_color` | Red | Resistance line color |
| `i_sup_color` | Blue | Support line color |
| `i_arrow_up_color` | Blue | Breakout up arrow color |
| `i_arrow_dn_color` | Magenta | Breakout down arrow color |
---
## 📈 Visual Elements
### Chart Elements
- **Resistance Line** (red stepline): Extends horizontally from upper fractal high until a new upper fractal appears
- **Support Line** (blue stepline): Extends horizontally from lower fractal low until a new lower fractal appears
- **Breakout Up Arrow** (blue triangle ▲ + BUY): Below the breakout bar, indicating bullish breakout
- **Breakout Down Arrow** (magenta triangle ▼ + SELL): Above the breakout bar, indicating bearish breakout
### Color Scheme
| Element | Default Color | Description |
|---------|--------------|-------------|
| Resistance Line | Red | Current resistance level |
| Support Line | Blue | Current support level |
| Breakout Up Arrow | Blue | Resistance Breakout: BUY |
| Breakout Down Arrow | Magenta | Support Breakout: SELL |
---
## 🔔 Alert Conditions
### Alert 1: SR Breakout: BUY
**Trigger Condition**: Close price breaks above resistance level (all filter conditions passed)
**Message Format**: `{ticker} Resistance Breakout: BUY at {close} ({interval})`
### Alert 2: SR Breakout: SELL
**Trigger Condition**: Close price breaks below support level (all filter conditions passed)
**Message Format**: `{ticker} Support Breakout: SELL at {close} ({interval})`
### Alert 3: SR Breakout: Any
**Trigger Condition**: Any direction breakout signal
**Message Format**: `{ticker} S/R Breakout at {close} ({interval})`
---
## 💡 Usage Tips
1. **Best Timeframes**: M15 to H4; fractals are more reliable on higher timeframes
2. **Complementary Indicators**: Pair with trend indicators (MA, ADX) to confirm breakout direction
3. **Trading Hours**: Avoid low-liquidity sessions (e.g., late Asian session) where breakout quality is lower
4. **Risk Management**: Arrows are entry references; combine with fixed or ATR-based stop-loss
### Suggested Configurations
**Conservative** (fewer false breakouts):
```
i_signal_dots = 5
i_rsicci_filter = true
i_rsi_overbought = 70, i_rsi_oversold = 30
```
**Aggressive** (fast reaction):
```
i_signal_dots = 1
i_rsicci_filter = false
```
**Balanced** (recommended default):
```
i_signal_dots = 3
i_rsicci_filter = false
i_apply_to_close = true
```
---
## 🔍 Technical Details
### Algorithm Explanation
The indicator follows a three-step process:
**Step 1: Fractal Detection**
Uses `ta.pivothigh(high, 2, 2)` and `ta.pivotlow(low, 2, 2)` to detect local highs and lows. Requires 2 bars on each side for confirmation, consistent with the classic fractal definition. When a fractal is detected, the corresponding S/R level is updated and the bar counter resets.
**Step 2: S/R Extension and Counting**
Each bar increments the counter until a new fractal resets it. The counter ensures breakouts occur sufficiently far from the fractal (`>= i_signal_dots`), avoiding false signals near the fractal point.
**Step 3: Breakout Detection**
When close price exceeds the S/R level, the counter meets the threshold, and the level hasn't been broken before, a breakout signal fires. Optional RSI/CCI filtering further screens low-quality breakouts.
### Anti-Repaint Mechanism
| Layer | Mechanism | Description |
|-------|-----------|-------------|
| 1 | `barstate.isconfirmed` gate | Only evaluates breakout after bar close |
| 2 | `var` persistence | State accumulates bar-by-bar; historical results are fixed |
| 3 | `last_broken_res/sup` dedup | Each S/R value triggers only once |
### Performance Considerations
- All visuals use `plot()` / `plotshape()` — no dynamic drawing object limits
- RSI/CCI computed once per bar, referenced via function to avoid redundant calls
---
## 📝 Version History
| Version | Date | Changes |
|---------|------|---------|
| v1.0 | 2026-04-03 | Initial release: full port from MQL4 to Pine Script v6 |
---
## 📌 FAQ
### Q1: How does this differ from the MQL4 version?
A: Core logic (fractal → S/R → breakout) is identical. The Pine version removes MQL4-specific GlobalVariable persistence (Pine auto-recalculates all history on load), arrow symbol codes (replaced with `plotshape`), and notification channel toggles (managed by TradingView platform). Adds color customization and bilingual interface.
### Q2: Why are some breakouts missing arrows?
A: Possible reasons: (1) `i_signal_dots` is set too high — not enough bars since fractal; (2) RSI/CCI filter is enabled but conditions aren't met; (3) The S/R level was already triggered by a previous breakout (dedup mechanism).
### Q3: Can both up and down arrows appear on the same bar?
A: Yes. Up and down breakouts are evaluated independently, allowing simultaneous signals in extreme market conditions.
### Q4: What happens with `i_apply_to_close = false`?
A: The latest unconfirmed bar participates in breakout evaluation, which may cause arrows to appear then disappear (repainting). Recommended to keep the default value `true`.
---
## 📞 Support & Feedback
For any questions or suggestions about this indicator, please feel free to open an Issue or Discussion.
---
*Last Updated: 2026-04-03*
> **Version**: v1.0
> **Author**: jeffprotrader168
> **Pine Script Version**: v6
> **License**: Mozilla Public License 2.0
---
## 📊 Overview
A fractal-based Support/Resistance breakout detection indicator. Uses `ta.pivothigh` / `ta.pivotlow` to identify local highs and lows as S/R levels, then signals with arrows when price breaks through these levels. Features optional RSI/CCI filtering and anti-repaint protection. Works on all markets and timeframes.
Ported from MQL4 (originally by Barry Stander 2004 / Lennoi Anderson 2015 / rewritten by Jeff Reed).
---
## 🎯 Key Features
- **Fractal-based S/R Detection**: Confirms fractals with 2 bars on each side, auto-extends horizontal lines until next fractal
- **Breakout Arrow Signals**: Draws triangle arrows below/above bars when close breaks S/R levels
- **Anti-Repaint Guarantee**: Signals only confirmed after bar close by default; historical arrows never disappear
- **RSI/CCI Filtering**: Optional dual-filter to reduce false breakouts
- **Deduplication**: Each S/R level triggers only one signal, preventing consecutive duplicate arrows
- **Bilingual Interface**: English / Traditional Chinese toggle
- **Full Color Customization**: S/R lines and arrow colors are fully configurable
---
## ⚙️ Configuration
### ⚙️ Basic Settings
| Parameter | Default | Description |
|-----------|---------|-------------|
| `i_language` | EN | Language selection (EN / Traditional Chinese) |
### 📊 Signal Settings
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| `i_signal_dots` | 3 | [1, 50] | Minimum bars after fractal before breakout is valid; higher = more conservative |
| `i_apply_to_close` | true | — | When enabled, signals only appear after bar closes (anti-repaint) |
### 🔍 RSI/CCI Filter
| Parameter | Default | Range | Description |
|-----------|---------|-------|-------------|
| `i_rsicci_filter` | false | — | Enable RSI+CCI dual filtering |
| `i_rsi_period` | 14 | [2, 200] | RSI calculation period |
| `i_rsi_overbought` | 75.0 | — | RSI overbought level (buy signals require RSI below this) |
| `i_rsi_oversold` | 25.0 | — | RSI oversold level (sell signals require RSI above this) |
| `i_cci_period` | 14 | [2, 200] | CCI calculation period |
| `i_cci_buy_level` | 50.0 | — | CCI buy threshold (buy signals require CCI above this) |
| `i_cci_sell_level` | -50.0 | — | CCI sell threshold (sell signals require CCI below this) |
### 🎨 Display
| Parameter | Default | Description |
|-----------|---------|-------------|
| `i_show_arrows` | true | Show breakout arrows |
| `i_show_sr_lines` | true | Show S/R extension lines |
| `i_res_color` | Red | Resistance line color |
| `i_sup_color` | Blue | Support line color |
| `i_arrow_up_color` | Blue | Breakout up arrow color |
| `i_arrow_dn_color` | Magenta | Breakout down arrow color |
---
## 📈 Visual Elements
### Chart Elements
- **Resistance Line** (red stepline): Extends horizontally from upper fractal high until a new upper fractal appears
- **Support Line** (blue stepline): Extends horizontally from lower fractal low until a new lower fractal appears
- **Breakout Up Arrow** (blue triangle ▲ + BUY): Below the breakout bar, indicating bullish breakout
- **Breakout Down Arrow** (magenta triangle ▼ + SELL): Above the breakout bar, indicating bearish breakout
### Color Scheme
| Element | Default Color | Description |
|---------|--------------|-------------|
| Resistance Line | Red | Current resistance level |
| Support Line | Blue | Current support level |
| Breakout Up Arrow | Blue | Resistance Breakout: BUY |
| Breakout Down Arrow | Magenta | Support Breakout: SELL |
---
## 🔔 Alert Conditions
### Alert 1: SR Breakout: BUY
**Trigger Condition**: Close price breaks above resistance level (all filter conditions passed)
**Message Format**: `{ticker} Resistance Breakout: BUY at {close} ({interval})`
### Alert 2: SR Breakout: SELL
**Trigger Condition**: Close price breaks below support level (all filter conditions passed)
**Message Format**: `{ticker} Support Breakout: SELL at {close} ({interval})`
### Alert 3: SR Breakout: Any
**Trigger Condition**: Any direction breakout signal
**Message Format**: `{ticker} S/R Breakout at {close} ({interval})`
---
## 💡 Usage Tips
1. **Best Timeframes**: M15 to H4; fractals are more reliable on higher timeframes
2. **Complementary Indicators**: Pair with trend indicators (MA, ADX) to confirm breakout direction
3. **Trading Hours**: Avoid low-liquidity sessions (e.g., late Asian session) where breakout quality is lower
4. **Risk Management**: Arrows are entry references; combine with fixed or ATR-based stop-loss
### Suggested Configurations
**Conservative** (fewer false breakouts):
```
i_signal_dots = 5
i_rsicci_filter = true
i_rsi_overbought = 70, i_rsi_oversold = 30
```
**Aggressive** (fast reaction):
```
i_signal_dots = 1
i_rsicci_filter = false
```
**Balanced** (recommended default):
```
i_signal_dots = 3
i_rsicci_filter = false
i_apply_to_close = true
```
---
## 🔍 Technical Details
### Algorithm Explanation
The indicator follows a three-step process:
**Step 1: Fractal Detection**
Uses `ta.pivothigh(high, 2, 2)` and `ta.pivotlow(low, 2, 2)` to detect local highs and lows. Requires 2 bars on each side for confirmation, consistent with the classic fractal definition. When a fractal is detected, the corresponding S/R level is updated and the bar counter resets.
**Step 2: S/R Extension and Counting**
Each bar increments the counter until a new fractal resets it. The counter ensures breakouts occur sufficiently far from the fractal (`>= i_signal_dots`), avoiding false signals near the fractal point.
**Step 3: Breakout Detection**
When close price exceeds the S/R level, the counter meets the threshold, and the level hasn't been broken before, a breakout signal fires. Optional RSI/CCI filtering further screens low-quality breakouts.
### Anti-Repaint Mechanism
| Layer | Mechanism | Description |
|-------|-----------|-------------|
| 1 | `barstate.isconfirmed` gate | Only evaluates breakout after bar close |
| 2 | `var` persistence | State accumulates bar-by-bar; historical results are fixed |
| 3 | `last_broken_res/sup` dedup | Each S/R value triggers only once |
### Performance Considerations
- All visuals use `plot()` / `plotshape()` — no dynamic drawing object limits
- RSI/CCI computed once per bar, referenced via function to avoid redundant calls
---
## 📝 Version History
| Version | Date | Changes |
|---------|------|---------|
| v1.0 | 2026-04-03 | Initial release: full port from MQL4 to Pine Script v6 |
---
## 📌 FAQ
### Q1: How does this differ from the MQL4 version?
A: Core logic (fractal → S/R → breakout) is identical. The Pine version removes MQL4-specific GlobalVariable persistence (Pine auto-recalculates all history on load), arrow symbol codes (replaced with `plotshape`), and notification channel toggles (managed by TradingView platform). Adds color customization and bilingual interface.
### Q2: Why are some breakouts missing arrows?
A: Possible reasons: (1) `i_signal_dots` is set too high — not enough bars since fractal; (2) RSI/CCI filter is enabled but conditions aren't met; (3) The S/R level was already triggered by a previous breakout (dedup mechanism).
### Q3: Can both up and down arrows appear on the same bar?
A: Yes. Up and down breakouts are evaluated independently, allowing simultaneous signals in extreme market conditions.
### Q4: What happens with `i_apply_to_close = false`?
A: The latest unconfirmed bar participates in breakout evaluation, which may cause arrows to appear then disappear (repainting). Recommended to keep the default value `true`.
---
## 📞 Support & Feedback
For any questions or suggestions about this indicator, please feel free to open an Issue or Discussion.
---
*Last Updated: 2026-04-03*
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.