Indicator · Pine Script v6 · On the chart

Daddy's Turtle Strategy

by timoanttila

Daddy's Turtle Strategy is an indicator that marks long and short entries when a candle closes beyond the highest high or lowest low of a configurable lookback, plus an ATR buffer.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code111
Settings7inputs
LicenceGPL-3.0
Last update2 months ago15 Aug 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

111 lines of Pine Script v6 from Turtle.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.

Turtle.pine
// Breakout-based trend indicator that enters when price breaks user-defined highs or lows,
// adds positions as the trend continues, and uses ATR for stops.
// © Timo Anttila, Tuspe Design Oy

//@version=6
indicator("Daddy's Turtle Strategy", shorttitle="Turtle", overlay=true, max_labels_count=200)

group1 = "Numbers of clearing bars"
entry_bars = input.int(20, "Entry", group=group1)
exit_bars = input.int(10, "Exit", group=group1)

group2 = "Average True Range"
atr_length = input.int(20, "Length", group=group2)
atr_buffer_m = input.float(0.1, "Buffer multiplier", group=group2)
atr_max_m = input.float(3.5, "Max candle size multiplier", group=group2)

group4 = "Entry Settings"
min_body_perc = input.float(20, "Min entry candle body %", minval=20, maxval=95, group=group4)
only_longs = input.bool(false, "Only longs", group=group4)


// ----------
//  GLOBAL VARIABLES
// ----------

bool is_bear = close < open
bool is_bull = close > open
float atr = ta.atr(atr_length)
int entry = na
int exit = na
var bool entry_taken = false
var float candle_exit = na
var float pullback = na
var int trend = na


// ----------
//  EXIT / ATR FIX
// ----------

float exit_highest = ta.highest(high, exit_bars)[1]
float exit_lowest = ta.lowest(low, exit_bars)[1]

if entry_taken
    if trend == 1 and (close < exit_lowest or close < candle_exit)
        exit := 1

    else if trend == 2 and (close > exit_highest or close > candle_exit)
        exit := 2

    if not na(exit)
        entry_taken := false


// ----------
//  ENTRY
// ----------

float entry_highest = ta.highest(high, entry_bars)[1]
float entry_lowest = ta.lowest(low, entry_bars)[1]

if not entry_taken
    float body_size = math.abs(close - open)
    float candle_size = math.abs(high - low)

    if body_size / candle_size >= min_body_perc / 100 and candle_size < atr * atr_max_m
        float atr_buffer = atr * atr_buffer_m

        if is_bull and close > entry_highest + atr_buffer
            entry := 1
            trend := 1

        else if not only_longs and is_bear and close < entry_lowest - atr_buffer
            entry := 2
            trend := 2

        if not na(entry)
            float atr_exit = atr * 2
            candle_exit := trend == 1 ? close - atr_exit : close + atr_exit
            entry_taken := true

            if not na(exit)
                exit := na


// ----------
//  VISUAL
// ----------

entry_color = color.new(color.white, 30)
plot_size = size.tiny
plot_bull = location.belowbar
plot_bear = location.abovebar

plotshape(entry == 1, title="Turtle Long", style=shape.triangleup, location=plot_bull, color=entry_color, size=plot_size)
plotshape(entry == 2, title="Turtle Short", style=shape.triangledown, location=plot_bear, color=entry_color, size=plot_size)

plot_style = shape.xcross
plot_color = color.new(color.gray, 20)

plotshape(exit == 1, title="Long Exit", style=plot_style, location=plot_bull, color=plot_color, size=plot_size)
plotshape(exit == 2, title="Short Exit", style=plot_style, location=plot_bear, color=plot_color, size=plot_size)


// ----------
//  ALERTS
// ----------

bool alert_check = not na(entry)
alertcondition(alert_check, title="New Signal", message="New signal detected. Confirm the direction of the next candle before entering. Happy trading!")
alertcondition(not na(exit), title="Cash Out", message="It might be a good time to close your position now.")

Overview

Candles must have a minimum body share and must not exceed a maximum ATR size. Exits are marked when price closes beyond the shorter exit window or an ATR-based stop set from the entry candle. A long-only option and alerts are included. It draws on the price chart.

Details

Published by

timoanttila on GitHub

Type

Indicator, Pine Script v6

Draws

On the price chart

Category

Breakout, Trend, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingpinescripttradingtrading-algorithmstrading-strategiestrading-strategytradingvew

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Entryint20entry_bars
Exitint10exit_bars
Lengthint20atr_length
Buffer multiplierfloat0.1atr_buffer_m
Max candle size multiplierfloat3.5atr_max_m
Min entry candle body %float20min_body_perc
Only longsboolfalseonly_longs
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

114 stars

This indicator adapts Michael Chalek's Dual Thrust trading concept to plot breakout levels and overlay bands directly on the price chart. It calculates lookback ranges based on historical price action and provides two algorithmic variations along with multiple

Indicator v4 TrendBreakout Repaints
Updated 1 year ago · None stated GitHub repository of Dual Thrust Trading Algorithm

The Market Tradability Engine calculates multi-factor tradability, balance, compression, and direction scores to evaluate market regime quality. It classifies market conditions into eight distinct states, including Balance, Compression, Ready, Breakout, Trend,

Indicator v6 TrendVolatility & bands
Updated 2 days ago · MIT GitHub repository of Market Tradability Engine [WavesUnchained]

GainzAlgo V2 Alpha

by Bakomebandias
8 stars

This overlay indicator scores breakouts of recent highs and lows against failed-breakout checks, EMA trend alignment, RSI momentum, and an ATR volatility band. It plots green buy and red sell labels when conditions pass a minimum score, and it prints ATR-based

Indicator v6 TrendOscillators & momentum
Updated 6 months ago · None stated GitHub repository of GainzAlgo V2 Alpha
3 stars

Greeffer's Long Study calculates Donchian Channels alongside a volume moving average filter to generate trade signals. When price touches the lower or upper channel boundaries combined with volume exceeding a custom moving average multiplier, the indicator tri

Indicator v4 TrendVolatility & bands
Updated 4 years ago · CC0-1.0 GitHub repository of Greeffer's Long Study

Bollinger Bands

by Web3Degenerate
2 stars

This overlay indicator plots customized asymmetrical Bollinger Bands on the price chart to detect breakout trade signals. It calculates a middle simple moving average and standard deviation bands using separate standard deviation multipliers for upper and lowe

Indicator v5 Volatility & bandsBreakout
Updated 2 years ago · None stated GitHub repository of Bollinger Bands

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers