OPEN-SOURCE SCRIPT
Mis à jour

0 Turtle Breakout Pro v6.13

2 308
0 Turtle Breakout Pro v6.12

Overview
The Turtle Breakout Pro is a modern, highly advanced homage to the legendary Turtle Trading system engineered by Richard Dennis and William Eckhardt. This script transforms a traditional Donchian Channel breakout indicator into a fully-fledged, institutional-grade risk management engine. It doesn't just trade price action; it trades volatility.

Designed for Pine Script v6, this strategy dynamically adapts to market conditions by calculating position sizes based on the Average True Range (ATR – the famous Turtle "N"). It includes a comprehensive backtesting dashboard that introduces advanced metrics, such as distinguishing between "Time in Market" and actual "Capital Deployed".

Core Mechanics & Strategy Logic

The Entry (Donchian Breakout): The system triggers entries based on price breakouts from the Donchian Channel. You can customize the channel lengths for the upper and lower bands independently.

Dynamic Position Sizing (The "N"): This is the heart of the Turtle philosophy. By enabling position sizing, the strategy calculates the exact quantity to buy/sell so that a hit to your ATR Stop Loss will only cost you a predefined percentage of your total equity (e.g., 2%).

The 2N Stop-Loss: The system features an optional, hard ATR-based stop loss. It calculates the ATR at the exact moment of entry and freezes the stop-loss level, protecting your capital from sudden market crashes.

Volatility Filter: An optional ATR SMA filter ensures the system only takes breakout setups when the market is actively expanding, filtering out choppy, low-momentum sideways markets.

Key Features & Upgrades

Pro Dashboard (Table): A sleek, non-intrusive UI panel displaying deep performance metrics:

Comparison against Buy & Hold

CAGR, Max Drawdown, and absolute Return

Sharpe Ratio and Calmar Ratio

Advanced Exposure Tracking: Clearly separates "Time in Market" (how often you are in a trade) from "Avg. Capital Deployed" (how much of your cash is actually at risk).

Live Exposure Labels: Plots a dynamic label directly on the chart for every executed trade, showing you exactly what percentage of your total equity is deployed in that specific position. The distance of the label is dynamically tied to the ATR to prevent overlapping with chart candles.

Crash-Proof Math Engine: The sizing formula is fortified against runtime errors (RE 10024). It seamlessly handles micro-fractions for Crypto and Forex markets while ignoring infinite values caused by broken broker data.

Time Filtering: Built-in date range inputs allow for precise historical backtesting without altering the code.

How to Use

Apply to your chart and open the settings (⚙️).

Set your Max Position Risk % (Standard Turtle rule is 1% to 2%).

Adjust the ATR Risk Offset and ATR Stop Multiplier (Standard is 2.0 to replicate the classic 2N-Stop).

Decide if you want to allow Short Trades or run the system as a Long-Only trend follower.

Disclaimer: Trend following systems typically experience a lower win rate but capture massive outliers. Ensure you understand the psychological requirements of sitting through drawdowns before trading this system live.
Notes de version

// v6.14: Fixed Max Position Exposure calculation and added visual plots for ATR Stop Loss (lines) & ATR Volatility Filter (background).
Notes de version
v6.16: Added Profit Factor, Win Rate, and Average Win/Loss Ratio to the performance dashboard.
Notes de version
v6.17: ATR Stop lines automatically disappear when trailing Donchian bands overtake them.
Notes de version
v6.18: Added optional Pyramiding (Scale-In) logic with remaining capital. Updated default ATR & Risk parameters.
Notes de version
// v6.22: Refactored Position Sizing to calculate exact Exposure based on anticipated execution (Stop) price.
// v6.23: Updated default parameters (ATR 2, Risk 2.25). Added dynamic Dashboard Positioning and Sortino Ratio.
Notes de version
// v6.25: Fixed Buy & Hold metrics to freeze when the Backtest End Date is reached instead of using current chart prices.
// v6.26: Fixed parsing error (line too long) by replacing nested ternary operators with a switch statement for dashboard position.
Notes de version
v6.27: Added Custom Interest Rate (Borrowing Costs) logic to adjust equity and metrics for realistic leverage simulation.
// v6.28: Fixed local scope history reference warning for 'adj_equity[1]' inside the performance metrics calculation.
Notes de version
// v6.29: Added Adj. Sortino and Calmar (by Capital Exposure). Reordered Dashboard.
// v6.30: Removed maxval=100 limit on Exposure for leverage support. Fixed accurate Label Calculation by reversing openprofit.
// v6.31: Integrated 3 Drawdown Calculations (Strict Float, TV Standard, Closed) with Intra-Bar accuracy into the dashboard.

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.