Pine Script v5 · Strategy
Crunchster's Turtle and Trend System
A Pine Script v5 strategy built on Lowest (low[1], 20), Highest (high[1], 20) and EMA (close[1], 10). It has 12 order rules, 4 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is 0.1 contracts and pays 0.06 commission. 19 settings; defaults include Source close, Lookback period for fast EMA 10 and Lookback period for Breakout 20.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Crunchster's Turtle and Trend System repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
- How did Crunchster's Turtle and Trend System do on BTCUSDT 1D with default settings?
- +17.99%
- From 26 Jan 2024 to 21 Oct 2026, over 31 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Crunchster's Turtle and Trend System run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 31 before, 31 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Crunchster's Turtle and Trend System use a stop loss?
- Yes
- strategy.exit sets a stop on line 72, 81, 91, 100.
- Does Crunchster's Turtle and Trend System run in Zeal Terminal?
- Yes
- It compiles in 44 ms and runs 1,000 bars in 117 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA Forecast
- Fast EMA
- Slow EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +17.99%
- $179.85
- Buy and hold
- +102.5%
- same period
- Closed trades
- 31
- 11 won · 20 lost
- Profitable
- 35.5%
- of closed trades
- Profit factor
- 1.36
- gross profit ÷ gross loss
- Max drawdown
- 16.69%
- −$204.51
One run with the author's default settings, $1,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
1 setting does nothing
“Source” is declared but never read.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Strategy Settings | |||
| Source | close | source | unused |
| Lookback period for fast EMAThis sets the lookback period for the fast exponential moving average. The slow EMA is 5x the fast EMA length | 10 | int · min 2 | fEMA sEMA |
| Lookback period for Breakout | 20 | int · min 5 · step 5 | lower upper |
| Strategy toggle | |||
| Long | true | bool | line 66 line 85 |
| ShortToggle long/short strategy on/off | true | bool | line 75 line 94 |
| Trend | false | bool | line 65 |
| BreakoutToggle trend/breakout strategy on/off | true | bool | line 84 |
| Risk Management Settings | |||
| Stop multipleMultiple for ATR, setting hard stop loss from entry price | 2 | float · step 0.5 | exit Stop Long exit Stop Short |
| Trail lookbackLookback period for the trailing stop | 10 | int · step 5 | tlower tupper |
| Max LeverageMax leverage sets maximum allowable leverage of total capital (initial capital + any net profit), capping maximum volatility adjusted position size | 1 | float · step 0.5 | shares line 51 |
| Annualised Volatility Target %Specify annual risk target, used to determine volatility adjusted position size. Annualised daily volatility is referenced to this value and position size adjusted accordingly | 15 | float · max 75 | shares |
| Compounding | true | bool | line 46 |
| %Toggle compounding of profit, and set % of profit to compound | 50 | float · step 5 | risk |
| Backtest range | |||
| From Day | 1 | int · min 1 · max 31 | start |
| From Mon | 1 | int · min 1 · max 12 | start |
| From YrSet start of backtesting period | 2018 | int · min 1900 | start |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Mon | 1 | int · min 1 · max 12 | finish |
| To YrSet end of backtesting period | 9999 | int · min 1900 | finish |
What it calculates
- Lowestlow[1], Lookback period for Breakout (20)
lower · line 30 - Highesthigh[1], Lookback period for Breakout (20)
upper · line 31 - EMAclose[1], Lookback period for fast EMA (10)
fEMA · line 35 - EMAclose[1], length*5
sEMA · line 36 - Stdevclose - close[1], 252
nemadiff · line 38 - SMAtr, 14
stopL · line 41 - Stdevclose-close[1], 14
stdev · line 42 - Lowestlow[1], Trail lookback (10)
tlower · line 60 - Highesthigh[1], Trail lookback (10)
tupper · line 61
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
The script has 61 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Trend Long! long | (longCondition2) | On | 70 |
| Exit Stop Long stop | strategy.position_size > 0 | On | 72 |
| Close Trend Long! | (exitlong) | On | 74 |
| Open Trend Short! short | (shortCondition2) | On | 79 |
| Exit Stop Short stop | strategy.position_size < 0 | On | 81 |
| Close Trend Short! | (exitshort) | On | 83 |
| Open Break Long! long | (longCondition1) | On | 89 |
| Exit Stop Long stop | strategy.position_size > 0 | On | 91 |
| Close Break Long! | (exitlong) | On | 93 |
| Open Break Short! short | (shortCondition1) | On | 98 |
| Exit Stop Short stop | strategy.position_size < 0 | On | 100 |
| Close Break Short! | (exitshort) | On | 102 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +18.0% | +102.5% | 31 | 35% | 1.36 | 16.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +0.2% | +5.5% | 30 | 30% | 1.00 | 14.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +9.3% | +9.8% | 31 | 42% | 1.24 | 8.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +22.2% | +8.4% | 27 | 26% | 1.45 | 15.7% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −6.7% | +16.7% | 33 | 27% | 0.83 | 16.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +22.8% | +21.5% | 29 | 28% | 1.51 | 13.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +32.6% | +148.3% | 27 | 33% | 1.71 | 26.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −15.9% | +17.1% | 36 | 28% | 0.62 | 22.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 9 | 22% | −$55.07 |
| Sideways market | 16 | 44% | $273.77 |
| Falling market | 6 | 33% | −$38.85 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
23.5%
The 95th percentile of the worst drawdown when the same 31 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.3% to 23.5%; the tick is what actually happened, 15.3%. Order luck alone moves it this much.
All 31 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 14 Feb 2024 51,795.30 | 19 Mar 2024 61,937.30 | 34 | $103.52 |
| short | 1 May 2024 58,364.90 | 4 May 2024 63,994.40 | 3 | −$31.82 |
| long | 15 May 2024 66,206.60 | 14 Jun 2024 66,043.90 | 30 | −$1.05 |
| short | 14 Jun 2024 66,043.90 | 14 Jul 2024 60,798.00 | 30 | $40.33 |
| long | 15 Jul 2024 64,724.20 | 2 Aug 2024 61,498.20 | 18 | −$15.23 |
| short | 4 Aug 2024 58,160.90 | 23 Aug 2024 64,523.90 | 19 | −$37.27 |
| long | 23 Aug 2024 64,037.30 | 27 Aug 2024 58,688.10 | 4 | −$28.06 |
| short | 6 Sep 2024 53,962.90 | 13 Sep 2024 58,763.40 | 7 | −$29.69 |
| long | 18 Sep 2024 61,760.10 | 1 Oct 2024 60,805.70 | 13 | −$5.77 |
| long | 15 Oct 2024 67,074.20 | 2 Feb 2025 97,700.50 | 110 | $204.50 |
| short | 24 Feb 2025 91,552.80 | 19 Mar 2025 86,846.00 | 23 | $23.54 |
| short | 6 Apr 2025 78,429.90 | 12 Apr 2025 85,373.70 | 6 | −$32.44 |
| long | 22 Apr 2025 93,443.10 | 30 May 2025 103,985.00 | 38 | $35.01 |
| short | 5 Jun 2025 101,509.00 | 9 Jun 2025 107,051.00 | 4 | −$31.31 |
| long | 9 Jul 2025 111,234.00 | 1 Aug 2025 113,298.00 | 23 | $12.50 |
| short | 1 Aug 2025 113,298.00 | 10 Aug 2025 118,095.00 | 9 | −$33.79 |
| long | 13 Aug 2025 123,307.00 | 15 Aug 2025 117,196.00 | 2 | −$31.07 |
| short | 25 Aug 2025 110,112.00 | 10 Sep 2025 113,960.00 | 16 | −$13.37 |
| long | 16 Sep 2025 116,789.00 | 22 Sep 2025 112,452.00 | 6 | −$40.08 |
| short | 25 Sep 2025 108,994.00 | 29 Sep 2025 113,244.00 | 4 | −$24.55 |
| long | 1 Oct 2025 118,595.00 | 10 Oct 2025 113,622.00 | 9 | −$19.70 |
| short | 4 Nov 2025 101,497.00 | 3 Dec 2025 93,430.10 | 29 | $28.59 |
| long | 4 Jan 2026 91,529.80 | 20 Jan 2026 88,427.60 | 16 | −$34.65 |
| short | 25 Jan 2026 86,670.30 | 4 Mar 2026 72,666.90 | 38 | $59.66 |
| long | 4 Mar 2026 72,666.90 | 7 Mar 2026 67,535.80 | 3 | −$20.64 |
| long | 16 Mar 2026 74,884.80 | 19 Mar 2026 69,088.80 | 3 | −$26.68 |
| long | 13 Apr 2026 74,418.10 | 16 May 2026 78,147.90 | 33 | $18.91 |
| short | 22 May 2026 75,539.40 | 14 Jun 2026 65,746.60 | 23 | $70.05 |
| long | 14 Jul 2026 65,044.10 | 15 Sep 2026 75,644.40 | 63 | $82.46 |
| short | 15 Sep 2026 75,644.40 | 18 Sep 2026 79,320.40 | 3 | −$20.93 |
| long | 21 Sep 2026 86,620.10 | 8 Oct 2026 81,730.00 | 17 | −$21.11 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Crunchster's Turtle and Trend System this page | — | v5 strategy | +18.0% | 31 | 16.7% |
| The Z-score by jensenvilhelm | sma stdev ema highest lowest | v5 strategy | +2.4% | 52 | 5.5% |
| MZ SRSI Strategy V1.0 by MightyZinger | ema sma highest lowest stdev | v4 strategy | No trades on this market | ||
| BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted by tathal | ema stdev sma highest lowest | v4 strategy | No trades on this market | ||
| WOMBO COMBO- EMA & VWAP & MACD & BB & STC by MakeMoneyCoESTB2020 | ema sma stdev highest lowest | v4 strategy | −0.5% | 6 | 2.2% |
| Lawyers Trend Pro Strategy by ErdemDemir | sma stdev lowest highest | v4 strategy | +12.1% | 102 | 41.7% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 6 settings use the untyped input() (line 6, 9, 10, 11, 12, 17). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 31 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.source()
- Line 9: input() → input.bool()
- Line 10: input() → input.bool()
- Line 11: input() → input.bool()
- Line 12: input() → input.bool()
- Line 17: input() → input.bool()
⋯// Inputs and Parameters-src = input(close, 'Source', group='Strategy Settings')+src = input.source(close, 'Source', group='Strategy Settings')length = input.int(title="Lookback period for fast EMA", defval=10, minval=2, group='Strategy Settings', tooltip='This sets the lookback period for the fast exponential moving average. The slow EMA is 5x the fast EMA length')blength = input.int(title="Lookback period for Breakout", defval=20, minval=5, step=5, group='Strategy Settings')-long = input(true, 'Long', inline='08', group='Strategy toggle')+long = input.bool(true, 'Long', inline='08', group='Strategy toggle')-short = input(true, 'Short', inline='08', group='Strategy toggle', tooltip='Toggle long/short strategy on/off')+short = input.bool(true, 'Short', inline='08', group='Strategy toggle', tooltip='Toggle long/short strategy on/off')-EMAwt = input(false, 'Trend', inline='01', group='Strategy toggle')+EMAwt = input.bool(false, 'Trend', inline='01', group='Strategy toggle')-breakwt = input(true, 'Breakout', inline='01', group='Strategy toggle', tooltip='Toggle trend/breakout strategy on/off')+breakwt = input.bool(true, 'Breakout', inline='01', group='Strategy toggle', tooltip='Toggle trend/breakout strategy on/off')stopMultiple = input.float(2, 'Stop multiple', step=0.5, group='Risk Management Settings', tooltip='Multiple for ATR, setting hard stop loss from entry price')⋯riskT = input.float(15, maxval=75, title='Annualised Volatility Target %', group='Risk Management Settings', tooltip='Specify annual risk target, used to determine volatility adjusted position size. Annualised daily volatility is referenced to this value and position size adjusted accordingly')-comp = input(true, 'Compounding', inline='09', group='Risk Management Settings')+comp = input.bool(true, 'Compounding', inline='09', group='Risk Management Settings')Comppct = input.float(50, '%', step=5, inline='09', group='Risk Management Settings', tooltip='Toggle compounding of profit, and set % of profit to compound')⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 31 before, 31 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Crunchster1-//@version=5+//@version=6strategy(title="Crunchster's Turtle and Trend System", shorttitle="Turtle Trend", overlay=true, slippage=10, pyramiding=1, precision = 4, calc_on_order_fills = false, calc_on_every_tick = false, default_qty_value = 0.1, initial_capital = 1000, commission_value = 0.06, process_orders_on_close = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 44 ms | With a workaround 1,000 bars in 117 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © Crunchster1//@version=5strategy(title="Crunchster's Turtle and Trend System", shorttitle="Turtle Trend", overlay=true, slippage=10, pyramiding=1, precision = 4, calc_on_order_fills = false, calc_on_every_tick = false, default_qty_value = 0.1, initial_capital = 1000, commission_value = 0.06, process_orders_on_close = true)// Inputs and Parameterssrc = input(close, 'Source', group='Strategy Settings')length = input.int(title="Lookback period for fast EMA", defval=10, minval=2, group='Strategy Settings', tooltip='This sets the lookback period for the fast exponential moving average. The slow EMA is 5x the fast EMA length')blength = input.int(title="Lookback period for Breakout", defval=20, minval=5, step=5, group='Strategy Settings')long = input(true, 'Long', inline='08', group='Strategy toggle')short = input(true, 'Short', inline='08', group='Strategy toggle', tooltip='Toggle long/short strategy on/off')EMAwt = input(false, 'Trend', inline='01', group='Strategy toggle')breakwt = input(true, 'Breakout', inline='01', group='Strategy toggle', tooltip='Toggle trend/breakout strategy on/off')stopMultiple = input.float(2, 'Stop multiple', step=0.5, group='Risk Management Settings', tooltip='Multiple for ATR, setting hard stop loss from entry price')trail = input.int(10, 'Trail lookback', step=5, group='Risk Management Settings', tooltip='Lookback period for the trailing stop')lev = input.float(1, 'Max Leverage', step=0.5, group='Risk Management Settings', tooltip='Max leverage sets maximum allowable leverage of total capital (initial capital + any net profit), capping maximum volatility adjusted position size')riskT = input.float(15, maxval=75, title='Annualised Volatility Target %', group='Risk Management Settings', tooltip='Specify annual risk target, used to determine volatility adjusted position size. Annualised daily volatility is referenced to this value and position size adjusted accordingly')comp = input(true, 'Compounding', inline='09', group='Risk Management Settings')Comppct = input.float(50, '%', step=5, inline='09', group='Risk Management Settings', tooltip='Toggle compounding of profit, and set % of profit to compound')// Backtesting periodFromDay = input.int(defval=1, title='From Day', minval=1, maxval=31, inline='04', group='Backtest range')FromMonth = input.int(defval=1, title='From Mon', minval=1, maxval=12, inline='04', group='Backtest range')FromYear = input.int(defval=2018, title='From Yr', minval=1900, inline='04', group='Backtest range', tooltip='Set start of backtesting period')ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31, inline='05', group='Backtest range')ToMonth = input.int(defval=1, title='To Mon', minval=1, maxval=12, inline='05', group='Backtest range')ToYear = input.int(defval=9999, title='To Yr', minval=1900, inline='05', group='Backtest range', tooltip='Set end of backtesting period')start = timestamp(FromYear, FromMonth, FromDay, 00, 00)finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)window = time >= start and time <= finish// Breakout strategylower = ta.lowest(low[1], blength)upper = ta.highest(high[1], blength)basis = math.avg(upper, lower)signal = 20*(close - basis) / (upper - lower)// Trend strategyfEMA = ta.ema(close[1], length)sEMA = ta.ema(close[1], length*5)emadiff = fEMA - sEMAnemadiff = 5*emadiff/(ta.stdev(close - close[1], 252))//Risk Management formulaetr = math.max(high - low, math.abs(high - close), math.abs(low - close)) //True rangestopL = ta.sma(tr, 14) //Average true rangestdev = ta.stdev(close-close[1], 14) //volatility of recent returnsmaxcapital = strategy.initial_capital+strategy.netprofit //Maximum capital available to invest - initial capital net of profitannvol = 100*math.sqrt(365)*stdev/close //converts recent volatility of returns into annualised volatility of returns - assumes daily timeframerisk = 1.1if comp risk := (strategy.initial_capital+(Comppct*strategy.netprofit/100))//adjust investment capital to include compoundingelse risk := strategy.initial_capitalshares = (risk * (riskT/annvol)) / close //calculates volatility adjusted position size, dependent on user specified annualised risk targetif ((shares*close) > lev*maxcapital) //ensures position size does not exceed available capital multiplied by user specified maximum leverage shares := lev*maxcapital/close//To set the price at the entry point of tradePosopen() => math.abs(strategy.position_size[1]) <= 0 and math.abs(strategy.position_size) > 0var float openN = naif Posopen() openN := stopL// Trailing stoptlower = ta.lowest(low[1], trail)tupper = ta.highest(high[1], trail)tbasis = math.avg(tupper, tlower)tsignal = 20*(close - tbasis) / (tupper - tlower)// Strategy Rulesif EMAwt if long longCondition2 = (nemadiff >2 and nemadiff[1] <2) and window exitlong = tsignal <= -10 if (longCondition2) strategy.entry('Trend Long!', strategy.long, qty=shares) if strategy.position_size > 0 strategy.exit('Stop Long', from_entry = 'Trend Long!', stop=(strategy.opentrades.entry_price(0) - (openN * stopMultiple))) if (exitlong) strategy.close('Trend Long!', immediately = true) if short shortCondition2 = (nemadiff <-1 and nemadiff[1] >-1) and window exitshort = tsignal >= 10 if (shortCondition2) strategy.entry('Trend Short!', strategy.short, qty=shares) if strategy.position_size < 0 strategy.exit('Stop Short', from_entry = 'Trend Short!', stop=(strategy.opentrades.entry_price(0) + (openN * stopMultiple))) if (exitshort) strategy.close('Trend Short!', immediately = true)if breakwt if long longCondition1 = (signal >= 10) and window exitlong = tsignal <= -10 if (longCondition1) strategy.entry('Break Long!', strategy.long, qty=shares) if strategy.position_size > 0 strategy.exit('Stop Long', from_entry = 'Break Long!', stop=(strategy.opentrades.entry_price(0) - (openN * stopMultiple))) if (exitlong) strategy.close('Break Long!', immediately = true) if short shortCondition1 = (signal <= -10) and window exitshort = tsignal >= 10 if (shortCondition1) strategy.entry('Break Short!', strategy.short, qty=shares) if strategy.position_size < 0 strategy.exit('Stop Short', from_entry = 'Break Short!', stop=(strategy.opentrades.entry_price(0) + (openN * stopMultiple))) if (exitshort) strategy.close('Break Short!', immediately = true)// Visuals of trend and directionplot(nemadiff, title='EMA Forecast', color=color.black, display=display.none)plot(ta.sma(ta.median(math.sqrt(math.pow(nemadiff,2)), 700), 350), 'Forecast mean', color=color.rgb(245, 0, 0), display=display.none)MAColor = fEMA > sEMA ? #00ff00 : #ff0000MA1 = plot(fEMA, title='Fast EMA', color=MAColor)MA2 = plot(sEMA, title='Slow EMA', color=MAColor)fill(MA1, MA2, title='Band Filler', color=MAColor)