# ZigZag Fibonacci Retracement Indicator for MT4

> ZigZag swing indicator (depth or percent mode) that draws Fibonacci retracement levels over the last completed swing automatically.

## At a glance

- What it is: A free Indicator for MetaTrader 4, written in MQL4.
- What it does: ZigZag swing indicator (depth or percent mode) that draws Fibonacci retracement levels over the last completed swing automatically.
- Shared by: Alex
- Licence: MIT
- Version: 1.0 (1 Dec 2026)
- Settings: 14 inputs
- Lab check: Compiled with MetaEditor build 2425 for MT4 on 1 Dec 2026: 0 errors, 0 warnings.
- Price: Free to download
- Page: https://hub.fxnook.com/zigzag-fibonacci-retracement-indicator-for-mt4
- Download (compiled): https://hub.fxnook.com/download/9f02c2ca-87a5-4feb-a1a0-6b04fa9fb92b/compiled
- Download (source): https://hub.fxnook.com/download/9f02c2ca-87a5-4feb-a1a0-6b04fa9fb92b/source

## About

ZigZag Fibonacci finds swing highs and lows with its own ZigZag and draws Fibonacci retracement levels over the last completed swing, so you do not have to place the Fibonacci tool by hand every time a new swing forms. You can detect swings with the familiar depth, deviation and backstep settings or with a simple percent reversal.

## How it works

The ZigZag walks through the bars from oldest to newest and tracks the extreme of the current leg.

- In an up leg, every higher high moves the tentative swing high. The leg reverses when a bar meets the reversal rule; the swing high is then **confirmed** and a new down leg starts from that bar's low. Down legs work the same way.
- **Depth mode** reversal: the bar makes the lowest low (or highest high) of the last `Depth` bars, the move from the extreme is at least `Deviation` points, and at least `Backstep` bars have passed since the extreme.
- **Percent mode** reversal: price moves back from the extreme by at least the chosen percent of price.
- **Fibonacci**: the last completed swing runs from the second-to-last confirmed point A to the last confirmed point B. Each level is `B + (A - B) x level / 100`: level 0 is point B, where the swing ended, and level 100 is point A, where it started. The levels are redrawn only when a new swing is confirmed.

The swing state is stored per bar, so each tick only processes the newest bar.

## Inputs

| Input | Default | What it does |
|---|---|---|
| Mode | Depth | Depth / deviation / backstep or percent reversal. |
| Depth | 12 | Bars the reversal bar must out-reach (depth mode). |
| Deviation | 50 | Minimum reversal size in points (depth mode). |
| Backstep | 3 | Minimum bars between a swing point and the reversal (depth mode). |
| Percent | 1.0 | Reversal size in percent of price (percent mode). |
| ZigZag colour / width | Dodger blue / 2 | Look of the ZigZag line. |
| Show Fibonacci | true | Draws the levels on the last completed swing. |
| Levels | 0,23.6,38.2,50,61.8,78.6,100 | Comma separated levels in percent. |
| Fibonacci colour | Goldenrod | Colour of the level lines and labels. |
| Extend right | true | Extends the levels to the right edge of the chart. |
| Show labels | true | Shows each level's percent and price. |

## How to use it

1. In MetaTrader choose **File > Open Data Folder**.
2. MT4: copy `FXN_ZigZagFibonacci.mq4` into `MQL4/Indicators`. MT5: copy `FXN_ZigZagFibonacci.mq5` into `MQL5/Indicators`.
3. Restart the terminal, or right-click **Indicators** in the Navigator and choose **Refresh**. If the indicator does not appear, open the file in MetaEditor and press F7 to compile it.
4. Drag the indicator onto a chart, adjust the inputs and press OK.

Start with depth mode 12 / 50 / 3 on H1. For bigger swings raise Depth or Deviation; on daily charts percent mode with 2 to 5 percent often reads well. Add 127.2 and 161.8 to the levels list if you also want extension levels beyond the swing.

## Good to know

- **The last leg can change.** The newest ZigZag line ends at a tentative extreme that moves while price keeps going in the same direction, and it is only fixed when the reversal rule confirms it. Earlier, confirmed swing points do not change.
- Because the Fibonacci levels use only confirmed swing points, they stay in place until the next swing is confirmed, which always happens some bars after the actual high or low.
- This ZigZag uses its own rules, so its points can differ from the built-in ZigZag with the same numbers.
- Fibonacci levels are reference areas, not predictions. All objects use the prefix `FXN_ZZF_` and are removed with the indicator. It does not trade.

Trading carries risk. Test on a demo account first; past results do not predict future results.

## Settings (inputs)

| Input | Type | Default | Note |
|---|---|---|---|
| InpSep1 | string | === ZigZag === | ---- ZigZag ---- |
| InpMode | ENUM_ZZ_MODE | ZZ_MODE_DEPTH | How a swing reversal is detected |
| InpDepth | int | 12 | Depth: reversal bar must make a new low/high of this many bars |
| InpDeviation | int | 50 | Deviation: minimum reversal size in points (depth mode) |
| InpBackstep | int | 3 | Backstep: minimum bars between two swing points (depth mode) |
| InpPercent | double | 1.0 | Reversal size in percent of price (percent mode) |
| InpZigZagColor | color | clrDodgerBlue | ZigZag line colour |
| InpZigZagWidth | int | 2 | ZigZag line width (1-5) |
| InpSep2 | string | === Fibonacci === | ---- Fibonacci ---- |
| InpShowFib | bool | true | Draw Fibonacci levels on the last completed swing |
| InpFibLevels | string | 0,23.6,38.2,50,61.8,78.6,100 | Levels in percent, comma separated |
| InpFibColor | color | clrGoldenrod | Colour of the Fibonacci lines and labels |
| InpExtendRight | bool | true | Extend the levels to the right edge of the chart |
| InpShowLabels | bool | true | Show level and price labels |

Tags: zigzag, fibonacci, retracement, swing-high-low, auto-fibonacci, indicator

Shared code is the author's work, not financial advice. Test on a demo account first.
