Fractal Alligator Script

← All 56 scripts

  • Trend
  • On price
  • Advanced

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.

  • File iqow-fractal-alligator.lua
  • Version 1.0.0
  • Size 164 lines · 6 KB
  • Timeframes 5-minute to 15-minute candles
  • License MIT
Fractal Alligator 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 last confirmed up-fractal level after the previous close was at or below it, and that level is above the Alligator teeth.

LOWER marker

The candle closes below the last confirmed down-fractal level after the previous close was at or above it, and that level is below the Alligator teeth.

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

Blue, red and green lines are the Alligator jaw, teeth and lips, drawn shifted forward. The white dotted levels are the last confirmed up and down fractals. A green HIGHER triangle means a close above the last up-fractal with that level above the teeth; the red LOWER triangle is the mirror case.

Indicators used

  • Williams Fractals (5)
  • Alligator (13/8/5, shifted 8/5/3)

Same view with built-in indicators: Add Fractal (5) and Alligator (13/8/5) and watch for closes through a fractal level beyond the teeth line.

Default settings

Jaw period / shift13 / 8
Teeth period / shift8 / 5
Lips period / shift5 / 3
Fractal size5 candles

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

Key points

  1. A fractal is five candles with the highest high or lowest low in the middle.
  2. It is only confirmed two candles later, so the script never uses future candles.
  3. The script remembers the last up and down fractal levels.
  4. The Alligator teeth show the trend reference, shifted forward by five candles.
  5. A close through a fractal level on the trend side of the teeth is marked HIGHER or LOWER.
  6. Practise on the Practice balance and watch what happens in sideways markets.

Limitations. A fractal is confirmed only two candles after its middle candle, so levels appear with a delay. The article describes fractals on their own without the Alligator rule, so the Alligator filter is this library's addition; ties with the neighbouring highs or lows still count as a fractal, as in the official fractal bands. 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: e68442c95bce26c5e639bab25350fd6a468206234f05b81afc6d7182e23b2d14

-- SPDX-License-Identifier: MIT
-- IQOptionWiki QCS Library
-- IQOW Fractal Alligator v1.0.0
--
-- Combines Williams fractals (five candles, confirmed two candles after the
-- middle one) with the Alligator (SMMA of the median price, jaw 13 shifted
-- 8, teeth 8 shifted 5, lips 5 shifted 3). The Alligator teeth act as the
-- trend reference: a fractal level beyond the teeth means the break comes
-- from the trend side.
--
-- HIGHER: close crosses above the last up-fractal level, and that level is
--         above the Alligator teeth.
-- LOWER:  close crosses below the last down-fractal level, and that level is
--         below the Alligator teeth.
--
-- 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 Fractal Alligator",
    short_name = "IQOW FR ALLIG",
    overlay = true
}

input_group {
    "1. Alligator",
    jaw_period = input (13, "Jaw period", input.integer, 2, 100),
    jaw_shift = input (8, "Jaw shift", input.integer, 0, 30),
    teeth_period = input (8, "Teeth period", input.integer, 2, 100),
    teeth_shift = input (5, "Teeth shift", input.integer, 0, 30),
    lips_period = input (5, "Lips period", input.integer, 2, 100),
    lips_shift = input (3, "Lips shift", input.integer, 0, 30)
}

input_group {
    "Display and advice",
    alligator_visible = input { default = true, type = input.plot_visibility },
    fractals_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",
    jaw_color = input { default = "#56CEFF", type = input.color },
    teeth_color = input { default = "#FF6C58", type = input.color },
    lips_color = input { default = "#25E154", type = input.color },
    fractal_color = input { default = rgba(255, 255, 255, 0.6), 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 }
}

-- Alligator lines: SMMA (ssma) of the median price.
jaw_line = ssma (hl2, jaw_period)
teeth_line = ssma (hl2, teeth_period)
lips_line = ssma (hl2, lips_period)

-- Williams fractal: the middle candle of five has the highest high (or lowest
-- low). It is only confirmed two candles later, so the pivot is read at [2]
-- and the level is remembered until the next fractal appears. No future bars.
local pivot_high = get_value (high [2], nil)
local pivot_low = get_value (low [2], nil)

local is_up_fractal =
    pivot_high ~= nil and get_value (high [4], nil) ~= nil and
    get_value (high, 0) <= pivot_high and get_value (high [1], 0) <= pivot_high and
    get_value (high [3], 0) <= pivot_high and get_value (high [4], 0) <= pivot_high

local is_down_fractal =
    pivot_low ~= nil and get_value (low [4], nil) ~= nil and
    get_value (low, 0) >= pivot_low and get_value (low [1], 0) >= pivot_low and
    get_value (low [3], 0) >= pivot_low and get_value (low [4], 0) >= pivot_low

up_fractal_level = iff (is_up_fractal, high [2], up_fractal_level [1])
down_fractal_level = iff (is_down_fractal, low [2], down_fractal_level [1])

-- The Alligator is drawn shifted forward. The value shown under the current
-- candle is the teeth calculated teeth_shift candles ago.
local teeth_now = get_value (teeth_line [teeth_shift], nil)
local up_level = get_value (up_fractal_level, nil)
local down_level = get_value (down_fractal_level, nil)
local close_now = get_value (close, nil)
local close_previous = get_value (close [1], nil)

local data_is_ready =
    teeth_now ~= nil and up_level ~= nil and down_level ~= nil and
    close_now ~= nil and close_previous ~= nil

higher_setup = conditional (
    data_is_ready and
    up_level > teeth_now and
    close_now > up_level and close_previous <= up_level
)

lower_setup = conditional (
    data_is_ready and
    down_level < teeth_now and
    close_now < down_level and close_previous >= down_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 alligator_visible then
    plot (jaw_line, "Jaw", jaw_color, line_width, jaw_shift)
    plot (teeth_line, "Teeth", teeth_color, line_width, teeth_shift)
    plot (lips_line, "Lips", lips_color, line_width, lips_shift)
end

if fractals_visible then
    plot (up_fractal_level, "Last up fractal", fractal_color, line_width, 0, style.points)
    plot (down_fractal_level, "Last down fractal", fractal_color, line_width, 0, style.points)
end

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

    plot_shape (
        confirmed_lower,
        "Fractal 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

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)

  • Trend
  • On price
  • Intermediate

KAMA Trend

Marks closes that cross Kaufman's Adaptive Moving Average in the direction the average is already sloping. The slope check removes crosses where the flat, slow-moving KAMA is merely being touched by price.

Indicators: KAMA (10, 2, 30)

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.