PROTECTED SOURCE SCRIPT
Profit Trailing BBands

Profit Trailing Trend BBands v4.7.5 with Double Trailing SL
A TradingView Pine Script Strategy
Created by Kevin Bourn and refined with the help of Grok 3 (xAI)
Overview
Welcome to Profit Trailing Trend BBands v4.7.5, a dynamic trading strategy designed to ride trends and lock in profits with a unique double trailing stop-loss mechanism. Built for TradingView’s Pine Script v6, this strategy combines Bollinger Bands for trend detection with a smart trailing system that doubles down on profit protection. Whether you’re trading XRP or any other asset, this tool aims to maximize gains while keeping risk in check—all with a clean, visual interface.
What It Does
Identifies Trends: Uses Bollinger Bands to spot uptrends (price crossing above the upper band) and downtrends (price crossing below the lower band).
Enters Positions: Opens long or short trades based on trend signals, with customizable position sizing and leverage.
Trails Profits: Employs a two-stage trailing stop-loss:
Initial Trailing SL: Acts as a take-profit level, set as a percentage (%) or dollar ($) distance from the entry price.
Tightened Trailing SL: Once the initial profit target is hit, the stop-loss tightens to half the initial distance, locking in gains as the trend continues.
Manages Risk: Includes a margin call feature to exit losing positions before they blow up your account.
Visualizes Everything: Plots Bollinger Bands (blue upper, orange lower) and a red stepped trailing stop-loss line for easy tracking.
Why Built It?
Captures Trends: Bollinger Bands are a proven way to catch momentum, and we tuned them for responsiveness (short length, moderate multiplier).
Secures Profits: Traditional trailing stops often leave money on the table or exit too early. The double trailing SL first takes a chunk of profit, then tightens up to ride the rest of the move.
Stays Flexible: Traders can tweak price sources, stop-loss types (% or $), and position sizing to fit their style.
Looks Good: Clear visuals help you see the strategy in action without cluttering your chart.
Originally refined for XRP, it’s versatile enough for most markets — crypto, forex, stocks, you name it.
How It Works
Core Components
Bollinger Bands:
Double Trailing Stop-Loss:
Position Sizing:
Margin Call:
Backtesting Filter:
Trade Logic
How to Use It
Setup
Tips for Traders
Timeframes: Works on any timeframe, but test 1H or 4H for XRP—great balance of signals and noise.
Assets: Optimized for XRP, but tweak slValue and mult for other markets (e.g., tighter SL for low-volatility pairs).
Risk Management: Keep marginPercent low (5-10%) for volatile assets; adjust leverage based on your risk tolerance.
Visuals: The red stepped SL line shows only during trades—zoom in to see its tightening in action.
Visuals on the Chart
Blue Line: Upper Bollinger Band (trend entry for longs).
Orange Line: Lower Bollinger Band (trend entry for shorts).
Red Stepped Line: Trailing Stop-Loss (shifts tighter after the first profit target).
Order Labels: Short tags like "OL" (Open Long), "CS" (Close Short), "LSL" (Long Stop-Loss), etc., mark trades.
A TradingView Pine Script Strategy
Created by Kevin Bourn and refined with the help of Grok 3 (xAI)
Overview
Welcome to Profit Trailing Trend BBands v4.7.5, a dynamic trading strategy designed to ride trends and lock in profits with a unique double trailing stop-loss mechanism. Built for TradingView’s Pine Script v6, this strategy combines Bollinger Bands for trend detection with a smart trailing system that doubles down on profit protection. Whether you’re trading XRP or any other asset, this tool aims to maximize gains while keeping risk in check—all with a clean, visual interface.
What It Does
Identifies Trends: Uses Bollinger Bands to spot uptrends (price crossing above the upper band) and downtrends (price crossing below the lower band).
Enters Positions: Opens long or short trades based on trend signals, with customizable position sizing and leverage.
Trails Profits: Employs a two-stage trailing stop-loss:
Initial Trailing SL: Acts as a take-profit level, set as a percentage (%) or dollar ($) distance from the entry price.
Tightened Trailing SL: Once the initial profit target is hit, the stop-loss tightens to half the initial distance, locking in gains as the trend continues.
Manages Risk: Includes a margin call feature to exit losing positions before they blow up your account.
Visualizes Everything: Plots Bollinger Bands (blue upper, orange lower) and a red stepped trailing stop-loss line for easy tracking.
Why Built It?
Captures Trends: Bollinger Bands are a proven way to catch momentum, and we tuned them for responsiveness (short length, moderate multiplier).
Secures Profits: Traditional trailing stops often leave money on the table or exit too early. The double trailing SL first takes a chunk of profit, then tightens up to ride the rest of the move.
Stays Flexible: Traders can tweak price sources, stop-loss types (% or $), and position sizing to fit their style.
Looks Good: Clear visuals help you see the strategy in action without cluttering your chart.
Originally refined for XRP, it’s versatile enough for most markets — crypto, forex, stocks, you name it.
How It Works
Core Components
Bollinger Bands:
- Calculated using a simple moving average (SMA) and standard deviation.
- Default settings: 6-period length, 1.66 multiplier.
- Upper Band (blue): SMA + (1.66 × StdDev).
- Lower Band (orange): SMA - (1.66 × StdDev).
- Trend signals: Price crossing above the upper band triggers a long, below the lower band triggers a short.
Double Trailing Stop-Loss:
- Initial SL: Set via "Trailing Stop-Loss Value" (default 6% or $6). Trails the price at this distance and doubles as the first profit target.
- Tightened SL: Once price hits the initial SL distance in profit (e.g., +6%), the SL tightens to half (e.g., 3%) and continues trailing, locking in gains.
- Visualized as a red stepped line, only visible during active positions.
Position Sizing:
- Choose "% of Equity" (default 30%) or "Amount in $" to set trade size.
- Leverage (default 10x) amplifies positions, capped by available equity to avoid overexposure.
Margin Call:
- Exits positions if drawdown exceeds the "Margin %" (default 10%) to protect your account.
Backtesting Filter:
- Starts trading after a user-defined date (default: Jan 1, 2020) for focused historical analysis.
Trade Logic
- Long Entry: Price crosses above the upper Bollinger Band → Closes any short position, opens a long.
- Short Entry: Price crosses below the lower Bollinger Band → Closes any long position, opens a short.
- Exit: Position closes when price hits the trailing stop-loss or triggers a margin call.
How to Use It
Setup
- Add to TradingView:
- Open TradingView, go to the Pine Editor, paste the script, and click "Add to Chart."
- Ensure you’re using Pine Script v6 (the script includes version=6).
- Configure Inputs:
- Start Date for Backtesting: Set the date to begin historical testing (default: Jan 1, 2020).
- BB Length & Mult: Adjust Bollinger Band sensitivity (default: 6, 1.66).
- BB Price Source: Choose the price for BBands (default: Close).
- Trend Price Source: Choose the price for trend detection (default: Close).
- Trailing Stop-Loss Type: Pick "%" or "$" (default: Trailing SL %).
- Trailing Stop-Loss Value: Set the initial SL distance (default: 6).
- Margin %: Define the max drawdown before exit (default: 10%).
- Order Size Type & Value: Set position size as % of equity (default: 30%) or $ amount.
- Leverage: Adjust leverage (default: 10x).
- Run It:
- Use the Strategy Tester tab to backtest on your chosen asset and timeframe.
- Watch the chart for blue/orange Bollinger Bands and the red trailing SL line.
Tips for Traders
Timeframes: Works on any timeframe, but test 1H or 4H for XRP—great balance of signals and noise.
Assets: Optimized for XRP, but tweak slValue and mult for other markets (e.g., tighter SL for low-volatility pairs).
Risk Management: Keep marginPercent low (5-10%) for volatile assets; adjust leverage based on your risk tolerance.
Visuals: The red stepped SL line shows only during trades—zoom in to see its tightening in action.
Visuals on the Chart
Blue Line: Upper Bollinger Band (trend entry for longs).
Orange Line: Lower Bollinger Band (trend entry for shorts).
Red Stepped Line: Trailing Stop-Loss (shifts tighter after the first profit target).
Order Labels: Short tags like "OL" (Open Long), "CS" (Close Short), "LSL" (Long Stop-Loss), etc., mark trades.
Disclaimer
Trading involves risk. This strategy is for educational and experimental use—backtest thoroughly and use at your own risk. Past performance doesn’t guarantee future results. Not financial advice—just a tool from traders, for traders.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.
Skrip dilindungi
Skrip ini diterbitkan sebagai sumber tertutup. Akan tetapi, anda boleh menggunakannya dengan percuma dan tanpa had – ketahui lebih lanjut di sini.
Penafian
Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.