Heikin Ashi EMA Script

← All 56 scripts

  • Trend
  • On price
  • Beginner

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.

  • File iqow-heikin-ashi-ema.lua
  • Version 1.0.0
  • Size 155 lines · 5 KB
  • Timeframes 1-minute to 15-minute candles
  • License MIT
Heikin Ashi 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

A Heikin-Ashi candle closes above its open after two bearish Heikin-Ashi candles, while the real close is above EMA 50.

LOWER marker

A Heikin-Ashi candle closes below its open after two bullish Heikin-Ashi candles, while the real close is below EMA 50.

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 amber line is EMA 50. A green HIGHER triangle sits under the candle where the Heikin-Ashi colour turned bullish above the EMA; a red LOWER triangle sits above the candle where it turned bearish below the EMA. Switch on 'Heikin-Ashi candles' in the display settings to see the calculated candles.

Indicators used

  • Heikin-Ashi candles (calculated)
  • EMA (50)

Same view with built-in indicators: Switch the chart type to Heikin Ashi and add Exponential Moving Average (50).

Default settings

EMA period50
Run length before the turn2
Show Heikin-Ashi candlesoff

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

Key points

  1. Heikin-Ashi candles average the price, so a run of same-colour candles shows the current push clearly.
  2. We wait for two bearish Heikin-Ashi candles in a row, then the first bullish one.
  3. The EMA 50 acts as a filter: for a HIGHER marker the real close must be above it.
  4. The LOWER marker is the mirror: two bullish candles, a bearish turn, close below EMA 50.
  5. The script calculates Heikin-Ashi itself, so you can keep normal candles on the chart.
  6. Test it on a Practice balance and note how it behaves in choppy markets.

Limitations. Heikin-Ashi smoothing lags the real price, so the colour turn often shows after the move has already started. In choppy markets the colour flips back quickly and the EMA filter does not fully remove that. The article uses the built-in Heikin-Ashi chart type; this script adds the EMA 50 filter and the two-candle run as defaults. 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: 1e911d19e9501d098fb00a9463472ae7aca03d8519bd021123ccd8018782a3b1

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW Heikin Ashi EMA v1.0.0
--
-- Heikin-Ashi candles smooth price into runs of same-colour candles. A turn
-- from a bearish run to a bullish candle, taken only on the correct side of
-- EMA 50, marks a possible shift back to the longer-term direction.
-- The Heikin-Ashi values are calculated here; your chart can stay on normal
-- candles. Optional Heikin-Ashi candles can be drawn from the display inputs.
--
-- HIGHER: a Heikin-Ashi candle turns bullish (HA close above HA open) after two
--         bearish Heikin-Ashi candles, and the real close is above EMA 50.
-- LOWER:  a Heikin-Ashi candle turns bearish after two bullish Heikin-Ashi
--         candles, and the real close is 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 Heikin Ashi EMA",
    short_name = "IQOW HA EMA",
    overlay = true
}

input_group {
    "1. Trend filter",
    ema_period = input (50, "EMA period", input.integer, 2, 300),
    bearish_run = input (2, "Candles in the run before the turn", input.integer, 1, 5)
}

input_group {
    "Display and advice",
    lines_visible = input { default = true, type = input.plot_visibility },
    ha_candles_visible = input { default = false, 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",
    ema_color = input { default = "#FFB020", type = input.color },
    ha_up_color = input { default = "#25E154", type = input.color },
    ha_down_color = input { default = "#FF6C58", type = input.color },
    line_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 }
}

-- Heikin-Ashi candle: averaged close, open from the previous HA candle.
ha_close = ohlc4
ha_open = iff (na (ha_open [1]), (open + close) / 2, (ha_open [1] + ha_close [1]) / 2)
ha_high = max (high, ha_open, ha_close)
ha_low = min (low, ha_open, ha_close)

ema_filter = ema (close, ema_period)

-- Current-bar scalars for the Lua rule logic.
local ha_close_now = get_value (ha_close, nil)
local ha_open_now = get_value (ha_open, nil)
local close_now = get_value (close, nil)
local ema_now = get_value (ema_filter, nil)

local data_is_ready =
    ha_close_now ~= nil and
    ha_open_now ~= nil and
    close_now ~= nil and
    get_value (ema_filter [ema_period], nil) ~= nil and
    get_value (ha_open [bearish_run], nil) ~= nil

-- Count how many Heikin-Ashi candles in a row were bearish / bullish
-- immediately before the current candle.
local bearish_before = true
local bullish_before = true
if data_is_ready then
    for back = 1, bearish_run do
        if get_value (ha_close [back], 0) >= get_value (ha_open [back], 0) then
            bearish_before = false
        end
        if get_value (ha_close [back], 0) <= get_value (ha_open [back], 0) then
            bullish_before = false
        end
    end
end

-- Event: the Heikin-Ashi colour turns on this candle.
higher_setup = conditional (
    data_is_ready and ha_close_now > ha_open_now and bearish_before and close_now > ema_now
)
lower_setup = conditional (
    data_is_ready and ha_close_now < ha_open_now and bullish_before and close_now < ema_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 lines_visible then
    plot (ema_filter, "EMA filter", ema_color, line_width)
end

-- Optional Heikin-Ashi candles drawn over the price candles.
if ha_candles_visible then
    local ha_candle_color = ha_close_now ~= nil and ha_open_now ~= nil and ha_close_now >= ha_open_now
        and ha_up_color or ha_down_color
    plot_candle (ha_open, ha_high, ha_low, ha_close, "Heikin-Ashi", ha_candle_color)
end

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

    plot_shape (
        confirmed_lower,
        "HA EMA 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
  • Beginner

Well Defined EMA

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.

Indicators: EMA (20) · EMA (50)

  • Trend
  • On price
  • Beginner

Williams R EMA Pullback

Marks the Williams %R cross back out of its oversold or overbought zone, but only when price is on the matching side of the EMA 50. The EMA turns the article's plain %R cross into a pullback-in-trend setup.

Indicators: Williams %R (14, -80/-20) · EMA (50)

  • Trend
  • Context indicator
  • On price
  • Beginner

EMA Trend Ribbon

Plots a fast and slow exponential moving average over price and shades the space between them with a neutral ribbon, making the relationship between two smoothing speeds easier to see.

Indicators: EMA 9 · EMA 21

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.