Loading…

Fibonacci Retracement Extension And Projection Levels

Retracement, extension and projection are usually presented as three separate tools, but they reduce to the same arithmetic: level = a + (b - a) * ratio, applied to two anchor prices with a different ratio set and a different choice of which price is a and which is b. Recognising that is what keeps this header small - FibLevel holds the one formula, and every other function is a specific way of calling it. Retracement levels answer "where might price pull back to, inside a swing that already happened". FibRetracementLevels anchors at the swing's END and walks back toward its START across the standard ratio set (0, 23.6%, 38.2%, 50%, 61.8%, 78.6%, 100%). Because the formula only ever sees two raw prices and never assumes which is larger, the same function handles an up-swing or a down-swing with no direction parameter - the demo runs the identical two prices both ways to make that explicit rather than asking you to take it on faith. Extension levels answer "where might price reach beyond where the swing already went, continuing the same direction". FibExtensionLevels anchors at the swing's START instead, across ratios greater than 1 (127.2%, 161.8%, 200%, 261.8%). Projection answers a different question: "given how far one leg of a pattern moved, how far might a later leg reach, measured from a different point" - the standard AB=CD measurement, where the length of leg A is projected forward from point C rather than from leg A's own end. FibProjection and FibProjectionLevels take the length of one swing and apply it from a caller-supplied anchor, using the same extension ratio set. FibRatioLabel formats a ratio as a percentage string for printing or naming chart objects, so callers building a Fibonacci drawing tool do not each reimplement the same DoubleToString call. Notes and limitations - This header only computes price LEVELS. It draws nothing - no OBJ_FIBO, no trend lines, no labels on the chart. Drawing is a separate concern the calling program owns, shown only as a one-line example in How To Use. - The ratio sets (7 retracement, 4 extension/projection) are the common defaults, not the only ratios ever used in practice. There is no way to request an arbitrary ratio set through the batch functions - call FibLevel or FibProjection directly with any ratio you want instead. - Swing identification (which two points count as the "swing" in the first place) is entirely the caller's responsibility. This header has no opinion on what makes a valid swing high or low. - FibStandardRetracementRatio and FibStandardExtensionRatio return -1.0 on an out-of-range index rather than stopping execution - a caller looping with a hardcoded count larger than the actual ratio set will get -1.0 values silently, so keep the loop bound tied to ArraySize on the batch functions' output, not a separately hardcoded number.

Script · MT5 · v1.0 · Free

About Fibonacci Retracement Extension And Projection Levels

Fibonacci Retracement Extension And Projection Levels is a script for MetaTrader 5. It has 3 settings, such as Swing low, Swing high and Project from. MQL source code included.

Files in the download: FibonacciUtils.mq5.mqh, FibonacciUtils.txt, FibonacciUtilsDemo.ex5, FibonacciUtilsDemo.mq5.

Settings

SettingDefaultWhat it does
Swing low1.1000Up-swing example: swing low
Swing high1.1500Up-swing example: swing high
Project from1.1250Anchor point for the AB=CD projection example

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the script onto a chart to run it once.

Download the PDF guide

Tags: Fibonacci · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria