Donchian RSI Reversal Script

← All 56 scripts

  • Reversal
  • On price
  • Beginner

Marks the moment RSI leaves its oversold or overbought zone after price touched the matching Donchian band in the same excursion. The channel shows where price is stretched; RSI shows when momentum starts to turn.

  • File iqow-donchian-rsi-reversal.lua
  • Version 1.0.0
  • Size 163 lines · 6 KB
  • Timeframes 1-minute to 5-minute candles
  • License MIT
Donchian RSI Reversal 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

While RSI(14) is at or below 30, a candle touches the lower Donchian(20) band; the first candle on which RSI closes back above 30 is marked HIGHER.

LOWER marker

While RSI(14) is at or above 70, a candle touches the upper Donchian(20) band; the first candle on which RSI closes back below 70 is marked LOWER.

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 blue lines are the 20-candle high and low with a faint middle line between them. A green HIGHER triangle under a candle means RSI just recovered from oversold after a lower-band touch; a red LOWER triangle above a candle is the mirror case at the upper band.

Indicators used

  • Donchian Channel (20)
  • RSI (14, 30/70)

Same view with built-in indicators: Add IQ Option's Donchian Channels (20) and Relative Strength Index (14, levels 70/30).

Default settings

Donchian period20
RSI period14
Oversold level30
Overbought level70

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

Key points

  1. The Donchian Channel draws the highest high and the lowest low of the last 20 candles.
  2. When a candle touches the lower band while RSI is below 30, price is stretched to a recent extreme.
  3. We wait: the marker appears only when RSI closes back above 30, the first sign that selling pressure is fading.
  4. The upper band and RSI 70 give the same picture in reverse, marked LOWER.
  5. Markers confirm on a completed candle, so they never repaint while a candle is still forming.
  6. Practise it on the Practice balance first and watch how it behaves in trends versus ranges.

Limitations. In a strong trend price can ride the band while RSI stays extreme for a long time, and a return across 30 or 70 can be followed by a fresh push in the trend direction. It works best in ranging or slowing markets. 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: bcf6d68c7210a28da6d423f44faeccb3f9fcbcfc2bbf6617ed02eac3e39db37b

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW Donchian RSI Reversal v1.0.0
--
-- Combines a Donchian Channel (the highest high and lowest low of the last
-- N candles) with RSI. A touch of the outer band shows price stretched to a
-- recent extreme; RSI returning from its extreme zone shows momentum turning.
--
-- HIGHER: during an RSI oversold excursion (RSI at or below 30) a candle
--         touched the lower Donchian band, and RSI now closes back above 30.
-- LOWER:  during an RSI overbought excursion (RSI at or above 70) a candle
--         touched the upper Donchian band, and RSI now closes back below 70.
--
-- 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 RSI Reversal",
    short_name = "IQOW DC RSI",
    overlay = true
}

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

input_group {
    "2. RSI",
    rsi_period = input (14, "RSI period", input.integer, 2, 100),
    oversold_level = input (30, "Oversold level", input.double, 5, 45, 1, false),
    overbought_level = input (70, "Overbought level", input.double, 55, 95, 1, false)
}

input_group {
    "Display and advice",
    channel_visible = input { default = true, type = input.plot_visibility },
    middle_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",
    channel_color = input { default = "#56CEFF", type = input.color },
    middle_color = input { default = rgba(255, 255, 255, 0.35), type = input.color },
    channel_fill_color = input { default = rgba(86, 206, 255, 0.06), 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 }
}

-- Donchian Channel: inclusive rolling extremes, as on the IQ Option chart.
upper_band = highest (high, channel_period)
lower_band = lowest (low, channel_period)
middle_band = (upper_band + lower_band) / 2

rsi_value = rsi (close, rsi_period)

-- Current-bar scalars for the Lua rule logic.
local rsi_now = get_value (rsi_value, nil)
local rsi_previous = get_value (rsi_value [1], nil)
local upper_now = get_value (upper_band, nil)
local lower_now = get_value (lower_band, nil)

local levels_are_valid = oversold_level < 50 and overbought_level > 50

local data_is_ready =
    levels_are_valid and
    rsi_now ~= nil and
    rsi_previous ~= nil and
    upper_now ~= nil and
    lower_now ~= nil

-- A band touch: this candle set the channel's extreme.
local touched_lower = data_is_ready and get_value (low, 0) <= lower_now
local touched_upper = data_is_ready and get_value (high, 0) >= upper_now

-- "Armed" stays true while RSI remains in its extreme zone after a touch, so
-- the touch must belong to the same oversold or overbought excursion.
local was_long_armed = get_value (long_armed [1], false)
local was_short_armed = get_value (short_armed [1], false)

long_armed = conditional (
    data_is_ready and rsi_now <= oversold_level and (was_long_armed or touched_lower)
)

short_armed = conditional (
    data_is_ready and rsi_now >= overbought_level and (was_short_armed or touched_upper)
)

-- Event: RSI closes back across its level on this candle.
local rsi_recovers =
    data_is_ready and rsi_previous <= oversold_level and rsi_now > oversold_level

local rsi_fades =
    data_is_ready and rsi_previous >= overbought_level and rsi_now < overbought_level

higher_setup = conditional (rsi_recovers and was_long_armed)
lower_setup = conditional (rsi_fades and was_short_armed)

-- 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
    fill (upper_band, lower_band, "Donchian area", channel_fill_color)
    plot (upper_band, "Upper Donchian", channel_color, channel_width)
    plot (lower_band, "Lower Donchian", channel_color, channel_width)
end

if middle_visible then
    plot (middle_band, "Donchian middle", middle_color, 1)
end

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

    plot_shape (
        confirmed_lower,
        "DC RSI 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 reversal scripts

  • Reversal
  • On price
  • Beginner

Bollinger RSI Reversal

Marks the first candle that closes back inside the Bollinger Bands after a close outside a band with RSI in its oversold or overbought zone. The bands show how stretched price is and RSI adds a second view of the same stretch.

Indicators: Bollinger Bands (20, 2) · RSI (14, 30/70)

  • Reversal
  • Own panel
  • Beginner

DeMarker 30 70 Cross

Marks the candle where DeMarker closes back out of its oversold or overbought zone. The 30 and 70 levels are the ones used in the related guide.

Indicators: DeMarker (14, levels 30/70)

  • Reversal
  • Own panel
  • Intermediate

Double Stochastic

Marks the candle where a slow Stochastic confirms a reversal cross that the fast Stochastic already showed in the same oversold or overbought zone. Using two settings asks the same question on two time scales before a marker appears.

Indicators: Stochastic fast (8, 3, 5) · Stochastic slow (17, 3, 7)

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.