Donchian Turtle Breakout Script

← All 56 scripts

  • Breakout
  • On price
  • Intermediate

Marks a close beyond the previous 20-candle high or low when ATR is above its 50-period average. It is a simplified channel breakout in the spirit of the Turtle rules, with an ATR filter to ask for expanding volatility.

  • File iqow-donchian-turtle-breakout.lua
  • Version 1.0.0
  • Size 133 lines · 4 KB
  • Timeframes 5-minute to 15-minute candles
  • License MIT
Donchian Turtle Breakout drawn on synthetic candles
How the script draws, shown on synthetic candles generated for testing. It is an illustration of the markers and lines, not real market data or a result.

The rules

HIGHER marker

The candle closes above the highest high of the previous 20 candles while ATR(14) is above the SMA(50) of ATR.

LOWER marker

The candle closes below the lowest low of the previous 20 candles while ATR(14) is above the SMA(50) of ATR.

A marker appears after the next candle opens and is drawn on the candle that completed the setup. It is a chart observation, not an instruction to trade.

How to read it

The green line is the highest high of the previous 20 candles and the red line is the lowest low. A green HIGHER triangle under a candle means it closed above the green line with ATR expanding; a red LOWER triangle above a candle is the mirror case.

Indicators used

  • Donchian breakout (20)
  • ATR (14)
  • SMA of ATR (50)

Same view with built-in indicators: Add Donchian Channels (20) and compare ATR (14) with a 50-period average of ATR.

Default settings

Breakout period20
ATR period14
ATR average period50

Every value is an input in the script settings. Platform advice is off by default.

Key points

  1. The Turtle traders bought breakouts of the recent high and sold breakouts of the recent low.
  2. Here the lines show the highest high and lowest low of the previous 20 candles, excluding the current one.
  3. A close beyond a line is a breakout candidate.
  4. We only accept it when ATR is above its 50-period average, so volatility is expanding.
  5. Markers confirm on a completed candle, so they never repaint.
  6. Test it on the Practice balance, especially in ranging markets where breakouts often fail.

Limitations. Breakouts often fail in ranging markets and the ATR filter does not prevent that. The Turtle article describes the original futures system (entries on channel breakouts and volatility-based sizing); this script keeps only the entry and the ATR filter, not the exits or position sizing. Test on the Practice balance before risking real funds.

Learn the strategy: read the full guide on IQOptionWiki →

Install it in four steps

  1. Download and inspectDownload one .lua file and open it in a plain-text editor if you want to read it first. If you downloaded the ZIP, extract it.
  2. Open Chart Analysis → ScriptsIn the IQ Option traderoom, choose the Practice balance, open the chart analysis panel, select Scripts and choose Import script.
  3. Save and add to chartSelect the downloaded file, review the imported code, choose Save, then use the + control to add it to the chart.
  4. Change one input at a timeConfirm the default view first. Then adjust periods, levels or colours one setting at a time and note what changes.

Complete source code

The download and this preview resolve to the same reviewed file. SHA-256: 2ec52dfdd0a6cfe7e831d85df1caf287ba7b81894752ad0481889c7651da7064

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW Donchian Turtle Breakout v1.0.0
--
-- A simplified Turtle-style channel breakout: price closing beyond the
-- highest high or lowest low of the previous N candles, accepted only when
-- volatility is expanding (ATR above its own longer average).
--
-- HIGHER: close is above the previous 20-candle high and ATR(14) is above
--         the SMA(50) of ATR.
-- LOWER:  close is below the previous 20-candle low and ATR(14) is above
--         the SMA(50) of ATR.
--
-- Markers use the previous completed candle: they appear after the next candle
-- opens and are shifted back one bar onto the candle that qualified.
-- Educational chart tool only. It does not place trades, choose an expiry,
-- predict outcomes, or guarantee results. Test on a Practice balance first.

instrument {
    name = "IQOW Donchian Turtle Breakout",
    short_name = "IQOW TURTLE",
    overlay = true
}

input_group {
    "1. Breakout channel",
    channel_period = input (20, "Breakout period", input.integer, 2, 200)
}

input_group {
    "2. Volatility filter",
    atr_period = input (14, "ATR period", input.integer, 2, 100),
    atr_average_period = input (50, "ATR average period", input.integer, 2, 300)
}

input_group {
    "Display and advice",
    channel_visible = input { default = true, type = input.plot_visibility },
    signals_visible = input { default = true, type = input.plot_visibility },
    advice_enabled = input { default = false, name = "Enable platform advice", type = input.boolean }
}

input_group {
    "Colors",
    upper_color = input { default = "#25E154", type = input.color },
    lower_color_line = input { default = "#FF6C58", type = input.color },
    channel_width = input { default = 1, type = input.line_width },
    higher_color = input { default = "#25E154", type = input.color },
    lower_color = input { default = "#FF6C58", type = input.color },
    signal_text_color = input { default = "#FFFFFF", type = input.color }
}

-- Previous N candles only: the current candle is excluded so a breakout is
-- a close beyond the range that already existed.
prior_high = highest (high, channel_period) [1]
prior_low = lowest (low, channel_period) [1]

atr_value = rma (tr, atr_period)
atr_average = sma (atr_value, atr_average_period)

local prior_high_now = get_value (prior_high, nil)
local prior_low_now = get_value (prior_low, nil)
local atr_now = get_value (atr_value, nil)
local atr_average_now = get_value (atr_average, nil)
local close_now = get_value (close, nil)

local data_is_ready =
    prior_high_now ~= nil and
    prior_low_now ~= nil and
    atr_now ~= nil and
    atr_average_now ~= nil and
    close_now ~= nil

-- Volatility expansion: ATR above its own average.
local volatility_is_expanding = data_is_ready and atr_now > atr_average_now

higher_setup = conditional (volatility_is_expanding and close_now > prior_high_now)
lower_setup = conditional (volatility_is_expanding and close_now < prior_low_now)

-- Confirm only a new setup on the previous completed candle.
confirmed_higher = conditional (
    get_value (higher_setup [1], false) and
    not get_value (higher_setup [2], false)
)

confirmed_lower = conditional (
    get_value (lower_setup [1], false) and
    not get_value (lower_setup [2], false)
)

if channel_visible then
    plot (prior_high, "Previous high", upper_color, channel_width)
    plot (prior_low, "Previous low", lower_color_line, channel_width)
end

if signals_visible then
    plot_shape (
        confirmed_higher,
        "Turtle HIGHER",
        shape_style.triangleup,
        shape_size.small,
        higher_color,
        shape_location.belowbar,
        -1,
        "HIGHER",
        signal_text_color
    )

    plot_shape (
        confirmed_lower,
        "Turtle LOWER",
        shape_style.triangledown,
        shape_size.small,
        lower_color,
        shape_location.abovebar,
        -1,
        "LOWER",
        signal_text_color
    )
end

-- QCS advice is a platform notification state only; it does not place trades.
if advice_enabled and
    get_value (confirmed_higher, false) and
    not get_value (confirmed_lower, false) then
    advise (advice.buy)
elseif advice_enabled and
    get_value (confirmed_lower, false) and
    not get_value (confirmed_higher, false) then
    advise (advice.sell)
else
    advise (advice.neutral)
end

More breakout scripts

  • Breakout
  • On price
  • Beginner

BB1 Bollinger

Marks the first candle that closes outside a narrow Bollinger Band (deviation 1) after two candles closed inside it. It follows the BB1 rule from the related article, where the move out of the band is read in the direction of the break.

Indicators: Bollinger Bands (20, deviation 1)

  • Breakout
  • On price
  • Intermediate

Fractal Chaos Bands Break

Marks a close through the Fractal Chaos Bands: the upper band is the last confirmed fractal high and the lower band the last confirmed fractal low.

Indicators: Fractal Chaos Bands

Download all 56 scripts as one ZIP · MIT License, provided “as is”, without warranty. IQOptionWiki is independent of the IQ Option platform operator. Nothing here is investment advice or a guarantee of results.

GENERAL RISK WARNING

The financial products offered by the company carry a high level of risk and can result in the loss of all your funds. You should never invest money that you cannot afford to lose.
Kindly note that this article does not provide any investment advice. The information presented regarding past events or potential future developments is solely an opinion and cannot be guaranteed as factual, including the provided examples. We caution readers accordingly.