Well Defined EMA Script

← All 56 scripts

  • Trend
  • On price
  • Beginner

After the EMA 20 crosses the EMA 50, marks the first pullback of price to the EMA 20 that closes back in the direction of the new trend. It turns the article's two steps (cross, then pullback) into one marker.

  • File iqow-well-defined-ema.lua
  • Version 1.0.0
  • Size 160 lines · 5 KB
  • Timeframes Article uses the 1-hour chart; works on any timeframe
  • License MIT
Well Defined EMA 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

After EMA(20) crosses above EMA(50), the first candle whose range touches EMA(20) and that closes bullish above EMA(20) is marked HIGHER.

LOWER marker

After EMA(20) crosses below EMA(50), the first candle whose range touches EMA(20) and that closes bearish below EMA(20) 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 yellow line is EMA 20 and the blue line is EMA 50. A green HIGHER triangle under a candle means price pulled back to the yellow line after an upward cross and closed bullish above it; a red LOWER triangle above a candle is the mirror case in a downtrend.

Indicators used

  • EMA (20)
  • EMA (50)

Same view with built-in indicators: Add two IQ Option Moving Averages of type EMA with periods 20 and 50.

Default settings

Fast EMA period20
Slow EMA period50

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

Key points

  1. Add two EMAs to the chart: a 20 and a 50.
  2. Step one: the EMA 20 crosses the EMA 50, which suggests a new trend direction.
  3. Step two: we wait for price to pull back to the EMA 20 instead of chasing the move.
  4. The marker appears when that pullback candle touches the line and closes back in the trend direction.
  5. Only the first qualifying pullback after each cross is marked.
  6. Test it on a Practice balance, and compare timeframes before trusting any setup.

Limitations. Only the first qualifying pullback after each cross is marked, so a long trend gives one marker. The article uses a plain touch of the line; this script also asks for a candle close in the trend direction. Choppy markets cross the EMAs often. 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: 27657fb7eeab7e33e12d1fbd7b560041c8517532c469813755268cd033fea8b2

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW Well Defined EMA v1.0.0
--
-- Two EMAs (20 and 50), as in the related article. After the fast EMA crosses
-- the slow EMA, the script waits for the first pullback of price to the fast EMA
-- and marks the candle that touches it and closes back in the trend direction.
--
-- HIGHER: after EMA 20 crossed above EMA 50, the first candle that touches EMA 20
--         with its low closes bullish above EMA 20 (EMA 20 still above EMA 50).
-- LOWER:  after EMA 20 crossed below EMA 50, the first candle that touches EMA 20
--         with its high closes bearish below EMA 20 (EMA 20 still below EMA 50).
--
-- 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 Well Defined EMA",
    short_name = "IQOW EMA PB",
    overlay = true
}

input_group {
    "1. Exponential moving averages",
    fast_period = input (20, "Fast EMA period", input.integer, 2, 100),
    slow_period = input (50, "Slow EMA period", input.integer, 3, 300)
}

input_group {
    "Display and advice",
    averages_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",
    fast_color = input { default = "#FFD166", type = input.color },
    slow_color = input { default = "#56CEFF", type = input.color },
    average_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 }
}

fast_ema = ema (close, fast_period)
slow_ema = ema (close, slow_period)

local fast_now = get_value (fast_ema, nil)
local slow_now = get_value (slow_ema, nil)
local fast_previous = get_value (fast_ema [1], nil)
local slow_previous = get_value (slow_ema [1], nil)
local close_now = get_value (close, nil)
local open_now = get_value (open, nil)
local high_now = get_value (high, nil)
local low_now = get_value (low, nil)

local periods_are_valid = fast_period < slow_period

local data_is_ready =
    periods_are_valid and
    get_value (close [slow_period], nil) ~= nil and
    fast_now ~= nil and
    slow_now ~= nil and
    fast_previous ~= nil and
    slow_previous ~= nil and
    close_now ~= nil and
    open_now ~= nil and
    high_now ~= nil and
    low_now ~= nil

-- Event: the fast EMA crosses the slow EMA.
local crosses_up = data_is_ready and fast_previous <= slow_previous and fast_now > slow_now
local crosses_down = data_is_ready and fast_previous >= slow_previous and fast_now < slow_now

-- A candle touches the fast EMA when its range reaches the line.
local touches_fast = data_is_ready and low_now <= fast_now and high_now >= fast_now

-- "Armed" means a cross happened and no pullback marker has fired since.
local was_long_armed = get_value (long_armed [1], false)
local was_short_armed = get_value (short_armed [1], false)

-- Event: a pullback candle touches the fast EMA and closes in trend direction.
local pullback_up =
    was_long_armed and touches_fast and
    close_now > open_now and close_now > fast_now and fast_now > slow_now

local pullback_down =
    was_short_armed and touches_fast and
    close_now < open_now and close_now < fast_now and fast_now < slow_now

long_armed = conditional (
    data_is_ready and fast_now > slow_now and
    (crosses_up or (was_long_armed and not pullback_up))
)

short_armed = conditional (
    data_is_ready and fast_now < slow_now and
    (crosses_down or (was_short_armed and not pullback_down))
)

higher_setup = conditional (pullback_up)
lower_setup = conditional (pullback_down)

-- 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 averages_visible then
    plot (fast_ema, "Fast EMA", fast_color, average_width)
    plot (slow_ema, "Slow EMA", slow_color, average_width)
end

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

    plot_shape (
        confirmed_lower,
        "EMA PB 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
  • On price
  • Advanced

Fractal Alligator

Marks a close through the last confirmed fractal level when that level lies beyond the Alligator teeth. The Alligator gives the trend reference and the fractal gives the breakout level.

Indicators: Williams Fractals (5) · Alligator (13/8/5, shifted 8/5/3)

  • Trend
  • On price
  • Beginner

Heikin Ashi EMA

Marks the first bullish or bearish Heikin-Ashi candle after a run of two opposite candles, only when price closes on the matching side of EMA 50. Heikin-Ashi is calculated inside the script, so the chart can stay on regular candles.

Indicators: Heikin-Ashi candles (calculated) · EMA (50)

  • Trend
  • On price
  • Advanced

Ichimoku Kijun Cloud

Marks a close back across the Kijun-sen when price is already on the trend side of a coloured Ichimoku cloud. The cloud sets direction and the Kijun cross sets the timing.

Indicators: Ichimoku Cloud (9, 26, 52, displacement 26)

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.