Overview
ZigZag swing indicator (depth or percent mode) that draws Fibonacci retracement levels over the last completed swing automatically.
- 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
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
Depthbars, the move from the extreme is at leastDeviationpoints, and at leastBackstepbars 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
- In MetaTrader choose File > Open Data Folder.
- MT4: copy
FXN_ZigZagFibonacci.mq4intoMQL4/Indicators. MT5: copyFXN_ZigZagFibonacci.mq5intoMQL5/Indicators. - 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.
- 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 read from the code
| 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 |
How to use it
- Download the compiled file (or the source and compile it in MetaEditor).
- Put it in MetaTrader: File → Open Data Folder → MQL4 → Indicators, then refresh the Navigator.
- Test it on a demo account before any real money.
- Want changes? Open a copy in your Lab and ask for them in plain words.