Skip to content
FXNook HubBeta

Alex / ZigZag Fibonacci Retracement Indicator for MT4

MetaTrader 4IndicatorMITCompiled · build 2425
AlexFirst version.build 2425v1.01 day ago1 version
  • FXN_ZigZagFibonacci.mq4First version.11 KB
  • FXN_ZigZagFibonacci.ex4Compiled by the Lab with MetaEditor build 242521 KB
README

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 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

InputDefaultWhat it does
ModeDepthDepth / deviation / backstep or percent reversal.
Depth12Bars the reversal bar must out-reach (depth mode).
Deviation50Minimum reversal size in points (depth mode).
Backstep3Minimum bars between a swing point and the reversal (depth mode).
Percent1.0Reversal size in percent of price (percent mode).
ZigZag colour / widthDodger blue / 2Look of the ZigZag line.
Show FibonaccitrueDraws the levels on the last completed swing.
Levels0,23.6,38.2,50,61.8,78.6,100Comma separated levels in percent.
Fibonacci colourGoldenrodColour of the level lines and labels.
Extend righttrueExtends the levels to the right edge of the chart.
Show labelstrueShows 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 read from the code

InputTypeDefaultNote
InpSep1string=== ZigZag ===---- ZigZag ----
InpModeENUM_ZZ_MODEZZ_MODE_DEPTHHow a swing reversal is detected
InpDepthint12Depth: reversal bar must make a new low/high of this many bars
InpDeviationint50Deviation: minimum reversal size in points (depth mode)
InpBackstepint3Backstep: minimum bars between two swing points (depth mode)
InpPercentdouble1.0Reversal size in percent of price (percent mode)
InpZigZagColorcolorclrDodgerBlueZigZag line colour
InpZigZagWidthint2ZigZag line width (1-5)
InpSep2string=== Fibonacci ===---- Fibonacci ----
InpShowFibbooltrueDraw Fibonacci levels on the last completed swing
InpFibLevelsstring0,23.6,38.2,50,61.8,78.6,100Levels in percent, comma separated
InpFibColorcolorclrGoldenrodColour of the Fibonacci lines and labels
InpExtendRightbooltrueExtend the levels to the right edge of the chart
InpShowLabelsbooltrueShow level and price labels

How to use it

  1. Download the compiled file (or the source and compile it in MetaEditor).
  2. Put it in MetaTrader: File → Open Data Folder → MQL4 → Indicators, then refresh the Navigator.
  3. Test it on a demo account before any real money.
  4. Want changes? Open a copy in your Lab and ask for them in plain words.