OPEN-SOURCE SCRIPT

LBB + RSI FX Edition

209
LBB + RSI ForeX Edition (FX) — Version v6.4.8-fx

**Combine Log Bollinger Bands, multi-level RSI signals, optional trend & pin-bar filters, ATR-based optional TP/SL and a compact signal table — all in one overlay.**

### 1. Key Features

* **Logarithmic Bollinger Bands (LBB):**

* Uses log-price SMA and standard deviation to derive upper/lower bands
* Provides a more symmetrical response to percentage-based moves
* **RSI Multi-Level Entries:**

* Generates long signals when price closes below the lower LBB and RSI < 30 / 35 / 40
* Generates short signals when price closes above the upper LBB and RSI > 60 / 65 / 70
* Three “strength” tiers for both buys and sells
* **Signal Filters (optional):**

* **EMA Trend Filter:** only take longs above a 50-period EMA or shorts below it
* **Pin-Bar Filter:** require a clear wick-to-body ratio on the signal candle
* **Confirmed Candle:** wait for candle close before signaling
* **ATR Display (optional):** show current ATR on the signal table
* **Flexible TP/SL Settings:**

* **Static (pips) or Dynamic (ATR-based) TP/SL**
* Toggle between pips and ticks for FX precision
* Minimum pip/tick threshold to avoid overly tight stops
* Separate TP/SL controls for longs and shorts
* **Visuals & Alerts:**

* Color-coded shapes for each RSI tier (green/orange/yellow for buys; blue/purple/red for sells)
* Customizable display of Bollinger Bands, ATR, signal table and win-rate stats
* Built-in `alertcondition` for each tier with clear emoji & strength label
* **Compact Signal Table:**

* Shows 📈/📉 entry price, RSI, ATR (if enabled), pin-bar ✔/–, timestamp (with UTC offset) and win-rate placeholder

---

### 2. Inputs & Groups

| Group | Input | Default | Notes |
| ---------------------- | ------------------------------------------ | ------- | ------------------------------------- |
| **Indicator Settings** | LBB Period (`lbbLength`) | 20 | Length for log-price SMA |
| | LBB Multiplier (`lbbMult`) | 2.0 | Std dev multiplier |
| | RSI Period (`rsiLength`) | 14 | |
| | ATR Period (`atrLength`) | 14 | |
| | Show ATR (`showATR`) | true | Toggles ATR in table |
| | UTC Offset Hours (`timeOffsetHours`) | 0 | Adjust table time to your timezone |
| **Signal Filters** | Use EMA Trend Filter (`useTrendFilter`) | false | |
| | EMA Period (`emaPeriod`) | 50 | |
| | Use Pin-Bar Filter (`usePinBarFilter`) | false | |
| | Pin-Bar Ratio (`pinBarRatio`) | 2.0 | Wick-to-body minimum |
| | Only on Confirmed Candle (`onlyConfirmed`) | false | |
| **TP/SL Settings** | Show TP/SL for Long (`showLongTpSl`) | false | |
| | Show TP/SL for Short (`showShortTpSl`) | false | |
| | Use Dynamic TP/SL (`useDynamicTpSl`) | false | ATR × multiplier |
| | TP/SL in Ticks (`useTicks`) | false | Instead of pips |
| | Min TP/SL Threshold (`minTpSlThreshold`) | 10.0 | In pips |
| | TP Long (pips) (`tpLongPips`) | 20 | Static targets |
| | SL Long (pips) (`slLongPips`) | 10 | |
| | TP Short (pips) (`tpShortPips`) | 20 | |
| | SL Short (pips) (`slShortPips`) | 10 | |
| | ATR Multiplier for TP (`atrMultiplierTP`) | 1.5 | |
| | ATR Multiplier for SL (`atrMultiplierSL`) | 1.0 | |
| **Visual Settings** | Show Signal Shapes (`showShapes`) | true | |
| | Show Bollinger Bands (`showBands`) | true | |
| | Show Statistics (`showStats`) | true | Win-rate currently placeholder “NaN%” |

---

### 3. Calculation Overview

1. **Log Bollinger Bands**

```pinescript
logClose = math.log(close)
logBasis = ta.sma(logClose, lbbLength)
logDev = lbbMult * ta.stdev(logClose, lbbLength)
lowerBand = math.exp(logBasis - logDev)
upperBand = math.exp(logBasis + logDev)
basisBand = math.exp(logBasis)
```

2. **RSI & ATR**

```pinescript
rsi = ta.rsi(close, rsiLength)
atrVal = ta.atr(atrLength)
```

3. **Pin-Bar Detection**

```pinescript
body = math.abs(close - open)
upperWick = high - math.max(close, open)
lowerWick = math.min(close, open) - low
isPinBarBull = lowerWick > body * pinBarRatio and upperWick < body
isPinBarBear = upperWick > body * pinBarRatio and lowerWick < body
```

4. **Trend & Confirmation Filters**

```pinescript
emaTrend = ta.ema(close, emaPeriod)
trendLong = close > emaTrend
trendShort = close < emaTrend
trendOkLong = useTrendFilter ? trendLong : true
trendOkShort= useTrendFilter ? trendShort: true
signalOk = onlyConfirmed ? barstate.isconfirmed : true
```

5. **Entry Conditions**

* **Long**: `close < lowerBand` + RSI < {30, 35, 40} + filters
* **Short**: `close > upperBand` + RSI > {60, 65, 70} + filters

---

### 4. Signal Plotting & Alerts

* **Shapes on Chart**

* 📈 LONG signals plotted below bar in green/orange/yellow triangles, sized by strength
* 📉 SHORT signals plotted above bar in blue/purple/red inverted triangles

* **Alert Conditions**

```pinescript
alertcondition(cond_rsi30_long, title="LBB LONG RSI <30", message="📈 LONG signal | Strong Buy | {{ticker}} @ {{close}} | {{interval}}")
// … and similarly for other tiers
```

---

### 5. TP/SL Management

1. **Delta Calculation**

```pinescript
rawTP = atrVal * atrMultiplierTP * tfMultiplier
rawSL = atrVal * atrMultiplierSL * tfMultiplier
pip = syminfo.mintick
pipMult = pip == 0.00001 ? 10 : pip == 0.01 ? 1 : 100
unitMult = useTicks ? 1 : pipMult
minDelta = minTpSlThreshold * pip * tfMultiplier * unitMult
```
2. **Dynamic TP/SL Lines**

* Deletes old lines and draws new dashed lines at `entry ± max(rawΔ, minDelta)` when signaled and `useDynamicTpSl` is enabled.
3. **Manual TP/SL Labels**

* On each bar checks if price hit the TP or SL level and drops a permanent label “TP @ …” or “SL @ …”.

---

### 6. Compact Signal Table

Positioned in the top-right corner, updates on each new signal:

| Column | Content |
| ------ | ----------------------------------------- |
| 0 | 📈/📉 Entry price with color background |
| 1 | `RSI: XX` |
| 2 | `ATR: X.XXXXX` (if enabled) |
| 3 | `PinBar: ✔` or `–` |
| 4 | `Time: DD-MM-YY HH:mm` (with UTC offset) |
| 5 | `Win Rate: NaN%` (placeholder if enabled) |

---

### 7. Recommendations & Best Practices

* **Timeframe Selection:** works best on FX pairs; adjust `tfMultiplier` sensitivity by avoiding ultra-low minute charts unless needed.
* **Trend Filter:** enable `useTrendFilter` to align signals with broader trend, reducing noise.
* **Pin-Bar Filter:** turn on `usePinBarFilter` when you need higher-quality reversal candles.
* **Dynamic TP/SL:** use ATR-based exits (`useDynamicTpSl=true`) to adapt stop levels to changing volatility.
* **Ticks vs Pips:** for very tight markets (e.g. FX majors on low timeframes), switch to ticks.
* **Backtest Thoroughly:** before deploying alerts, test across multiple symbols/timeframes to tune multipliers and thresholds.
* **Alert Integration:** set up TradingView alerts using the built-in `alertcondition` names for fully automated notifications.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.