RSI Trendline Breakouts EA
- Experts
-
Robert Davis Waweru Mugure
experienced algo trader .. 4 years of experience coding my own EAs and using them for myself. Found it wise to share some of my best EAs at a small token of appreciation .
also Washignton Accorded MECHATRONICS ENGINEER. - Versione: 2.20
- Attivazioni: 7
This EA is a highly specialized breakout strategy that ignores price levels entirely—it draws and trades trendlines directly on the RSI oscillator, detecting breakouts before they happen on the price chart.
🧠 Core Concept
Instead of standard support/resistance on price, this EA:
-
Identifies pivot highs and pivot lows on the RSI line.
-
Connects consecutive lower highs to form a descending resistance line.
-
Connects consecutive higher lows to form an ascending support line.
-
Waits for the RSI to break beyond these lines (with a user‑defined buffer).
-
Executes a BUY when RSI breaks above the descending resistance (bullish breakout).
-
Executes a SELL when RSI breaks below the ascending support (bearish breakdown).
All logic is evaluated strictly on fully closed candles, exactly as TradingView does.
🔍 How It Works – Step by Step
1. Pivot Detection (The Foundation)
For every closed bar, the EA checks if it forms a swing high or swing low over a Lookback Range (default 4):
-
Pivot High: The central bar’s RSI is higher than the Lookback Range bars on both its left and right sides.
-
Pivot Low: The central bar’s RSI is lower than the Lookback Range bars on both sides.
Once detected, the bar’s bar index (X) and RSI value (Y) are stored as a raw pivot point.
2. Trendline Formation (TV‑Style)
-
Resistance (PH) – Only connects pivots when the new pivot high is lower than the previous one. This creates a descending line.
-
Support (PL) – Only connects pivots when the new pivot low is higher than the previous one. This creates an ascending line.
When two valid consecutive pivots exist, the trendline becomes “active”, and the EA stores its start/end coordinates.
3. Breakout Monitoring
On every new bar, the EA:
-
Projects the active trendline to the current bar index (X‑coordinate).
-
Compares the current RSI value against the projected Y‑value plus/minus the RSI Difference buffer.
-
A breakout is triggered only if the RSI closes beyond the line by the specified buffer amount.
4. Trade Execution
-
Buy Signal: RSI breaks above a descending resistance line ( ph_active ) → market BUY order.
-
Sell Signal: RSI breaks below an ascending support line ( pl_active ) → market SELL order.
-
Once a breakout is registered, the corresponding trendline is immediately deactivated to prevent re‑entries on the same line.
5. Position Management
-
Fixed Stop Loss and Take Profit (in points) are attached to every trade.
-
No position‑sizing logic, no trailing stops, no grid—each trade is independent and closed purely by SL/TP.
✅ Key Advantages
| Advantage | Description |
|---|---|
| Leading Indicator | RSI breakouts often precede price breakouts, giving you an early entry advantage. |
| Dynamic & Adaptive | Trendlines are not static; they constantly update as new pivots form, automatically adjusting to changing market structure. |
| False‑Signal Filter | The RSI Difference buffer prevents tiny, insignificant crosses from triggering premature entries. |
| No Repainting | Since all logic is evaluated on closed bars, signals are final and do not change on subsequent ticks. |
| Clear Visual Feedback | Large arrows (⬆ / ⬇) are drawn on the main price chart at the signal candle for immediate visual confirmation. |
⚙️ Input Parameters
| Styling | InpPLowCol | clrRed | Color for pivot low markers (visual only, currently not drawn in code but reserved). |
| InpPHighCol | clrSeaGreen | Color for pivot high markers (visual only, reserved). |
🎯 Strategy Philosophy
-
Mean‑Reversion on RSI? – No. This is a breakout system that uses RSI structure rather than overbought/oversold levels.
-
Why RSI trendlines? – The RSI often forms cleaner, more consistent patterns than raw price, leading to earlier and more reliable breakout signals.
-
Fixed Risk/Reward – Every trade has a fixed 1:2 risk‑reward ratio , ensuring statistical consistency over many trades.
💡 Best Use Cases
-
Timeframes: Works well from 15‑minute to 4‑hour charts. Lower timeframes may generate too many pivots; higher timeframes produce very few signals.
-
Instruments: Best on liquid forex pairs, and commodities (Gold, Oil) where RSI exhibits clear swing structure.
-
Market Conditions: Excels in trending markets where breakouts of RSI trendlines lead to sustained moves. Can be whipsawed in extremely choppy, sideways markets.
⚠️ Important Nuances & Limitations
| Nuance | Explanation |
|---|---|
| No Trade Overlap | A trendline is deactivated immediately after its breakout. A new trendline must form (requiring two new pivots) before another signal can occur. |
| RSI Pivot Strictness | The pivot definition requires strict inequality (higher/lower), not equal. This matches TradingView’s ta.pivothigh / ta.pivotlow logic. |
| History Depth | The EA scans back 1500 bars to build the initial state. Ensure your chart has enough history. |
| Visual Arrows | The arrows are drawn on the main price chart, not on the RSI sub‑window, to make signals easier to spot. |
| Fixed Point Values | SL and TP are in points, not pips. For a 5‑digit broker, 350 points = 35.0 pips. Adjust according to your broker’s point size. |
| No Partial Closes | Positions are either fully closed by SL/TP or remain open until then. No scaling in/out. |
