LRS Williams R Script

← All 56 scripts

  • Trend
  • On price
  • Intermediate

Uses the slope of a 100-candle regression line as the trend filter and Williams %R leaving its extreme zone as the timing event. The regression line is drawn on the price chart so the slope direction is visible.

  • File iqow-lrs-williams-r.lua
  • Version 1.0.0
  • Size 150 lines · 5 KB
  • Timeframes 1-minute to 5-minute candles
  • License MIT
LRS Williams R 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 Linear Regression Slope(100) is above zero and Williams %R(14) closes above -80 after being at or below -80 on the previous candle.

LOWER marker

The Linear Regression Slope(100) is below zero and Williams %R(14) closes below -20 after being at or above -20 on the previous candle.

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 yellow line on the price chart is the 100-candle linear regression line: rising means the slope is above zero, falling means it is below. A green HIGHER triangle under a candle means %R closed back above -80 while the line was rising; a red LOWER triangle above a candle is the mirror case. Williams %R itself is not drawn on the price chart.

Indicators used

  • Linear Regression Slope (100)
  • Williams %R (14, levels -80/-20)

Same view with built-in indicators: Add IQ Option's Linear Regression Slope (period 100) and Williams %R (period 14, levels -20/-80); optionally add Linear Regression Forecast or the regression line on price.

Default settings

Regression period100
Williams %R period14
Oversold level-80
Overbought level-20

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

Key points

  1. Linear regression fits a straight line through the last 100 closes. Its slope tells us the trend direction.
  2. A slope above zero means the line is rising; below zero means it is falling.
  3. Williams %R shows where the close sits inside the recent 14-candle range.
  4. With a rising line, we wait for %R to close back above minus 80, and mark HIGHER.
  5. With a falling line, a close back below minus 20 is marked LOWER.
  6. As always, markers confirm on a completed candle; practise on the Practice balance first.

Limitations. The regression slope turns slowly, so after a reversal it can keep the old direction for many candles. Williams %R also leaves its zones often in choppy markets, which makes some markers weak. 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: 64a3c778c7f6264a34fb03e3c44b747c469812e36378d9c0f0e4232a7bf7483e

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW LRS Williams R v1.0.0
--
-- Combines the Linear Regression Slope(100) with Williams %R(14). The slope is
-- the one-candle change of the 100-candle linear regression line (official
-- Quadcode formula): above zero the regression line rises, below zero it
-- falls. Williams %R leaving its extreme zone gives the timing.
--
-- HIGHER: the slope is above zero and Williams %R closes above -80 after
--         being at or below -80 on the previous candle.
-- LOWER:  the slope is below zero and Williams %R closes below -20 after
--         being at or above -20 on the previous candle.
--
-- 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 LRS Williams R",
    short_name = "IQOW LRS %R",
    overlay = true
}

input_group {
    "1. Linear regression slope",
    slope_period = input (100, "Regression period", input.integer, 5, 500)
}

input_group {
    "2. Williams %R",
    williams_period = input (14, "Williams %R period", input.integer, 2, 100),
    oversold_level = input (-80, "Oversold level", input.double, -99, -51, 1, false),
    overbought_level = input (-20, "Overbought level", input.double, -49, -1, 1, false)
}

input_group {
    "Display and advice",
    regression_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",
    regression_color = input { default = "#DBCF0D", type = input.color },
    regression_width = input { default = 2, 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 }
}

-- Linear regression line and its slope (value now minus value one bar back).
regression_line = linreg (close, slope_period, 0)
regression_slope = regression_line - linreg (close, slope_period, 1)

-- Williams %R: close position inside the recent range, -100..0.
highest_high = highest (high, williams_period)
lowest_low = lowest (low, williams_period)
williams_r = iff (
    highest_high > lowest_low,
    100 * (close - highest_high) / max (highest_high - lowest_low, 1e-10),
    -50
)

-- Current-bar scalars for the Lua rule logic.
local slope_now = get_value (regression_slope, nil)
local williams_now = get_value (williams_r, nil)
local williams_previous = get_value (williams_r [1], nil)

local levels_are_valid = oversold_level < overbought_level

local has_history = get_value (close [slope_period], nil) ~= nil

local data_is_ready =
    levels_are_valid and
    has_history and
    slope_now ~= nil and
    williams_now ~= nil and
    williams_previous ~= nil

-- Event: %R closes back across its level while the slope has the same sign.
higher_setup = conditional (
    data_is_ready and
    slope_now > 0 and
    williams_previous <= oversold_level and
    williams_now > oversold_level
)

lower_setup = conditional (
    data_is_ready and
    slope_now < 0 and
    williams_previous >= overbought_level and
    williams_now < overbought_level
)

-- 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 regression_visible then
    plot (regression_line, "Linear regression", regression_color, regression_width)
end

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

    plot_shape (
        confirmed_lower,
        "LRS %R 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 trend scripts

  • Trend
  • Signal engine
  • On price
  • Intermediate

IQ_WIKI_SCRIP_V1.0.1

A selective confluence overlay with five readable filters: EMA trend alignment and slope, RSI momentum without chasing extremes, ADX/DMI strength, ATR activity and a candle-quality guard.

Indicators: EMA 9/21/50 · RSI (14) · ADX/DMI (14) · ATR (14)

  • Trend
  • On price
  • Intermediate

ADX EMA28 Cross

Marks a candle that closes through the EMA 28 in the direction that +DI or -DI already favours. The DI lines act as a direction filter, the EMA cross as the trigger.

Indicators: ADX +DI / -DI (5) · EMA (28)

  • Trend
  • Own panel
  • Beginner

Aroon Oscillator Zero Cross

Marks the candle where the Aroon Oscillator crosses its zero line. A cross up means the latest 25-candle high is now more recent than the latest low; a cross down means the opposite.

Indicators: Aroon Oscillator (25)

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.