Gann Trend Indicator: A Midline Between the 14-Bar Extremes

Written by Dominic Walsh · Published · Last updated

The gann trend indicator reduces trend reading to one question: is price above or below the middle of its recent range? It takes the highest high and lowest low of the last fourteen bars, plots the midpoint between them, and colours the chart background by which side the close finished on. An arrow marks each side change.

This build ships as a compiled .ex4 for MT4 and .ex5 for MT5; the screenshots below come from EURUSD H1.

Platforms MT4 (.ex4) + MT5 (.ex5)
Chart window Main price chart
Plots 3: Gann Midline, Gann Up, Gann Down
Alerts popup, push notification, email, sound
Inputs 10

What the Gann trend Indicator draws on the chart

Gann Midline is the gold line running through the centre of the recent range.

Gann Up places a lime arrow beneath the bar where the close moves above the midline.

Gann Down places a red arrow above the bar on a move below it.

Rectangle objects shade the background dark green or maroon behind the bars, matching the state.

  • Gann Midline: line, gold, width 2
  • Gann Up: arrow, lime, width 2, arrow code 233
  • Gann Down: arrow, red, width 2, arrow code 234
Gann trend indicator on EURUSD H1 with the range midline and shaded trend background
Gann trend indicator on EURUSD H1 with the range midline and shaded trend background

How the Gann trend Indicator calculates its values

Finding the middle of the range

iHighest and iLowest run over `GannPeriod` bars to give hh and ll. mid takes their average, and MidBuf stores it. Using the extremes rather than an average of closes means the line sits where the range is centred, which reacts differently from a moving average when one large bar appears.

Reading which side the close finished

trend_now takes 1 when close[i] sits above mid, minus 1 when below, and 0 when they match exactly. The code then rebuilds the same reading for the previous bar as trend_prev, using midPrev from MidBuf[i + 1]. Comparing two bars is what turns a state into an event.

Shading the history

paint_to bounds the background pass at MathMin(rates_total – GannPeriod – 1, 500), so the shading covers recent history without walking the whole chart. For each bar in that span t_state re-derives the side from close[k] against MidBuf[k], and `PaintBackground` decides whether the rectangles get drawn at all.

How to read the signals

Background colour is the fastest read. Green means closes above the midline, maroon means below.

The midline itself moves with the range, so it can shift under price without price moving at all.

Arrows mark side changes, which in a range happen often and mean little.

Shading stops after five hundred bars, so scrolling far back leaves the older chart unpainted.

Alert channels in this build: popup, push notification, email and sound, one message per closed bar.

Four channels sit beneath `EnableAlerts`: popup, push notification, email and sound, with `SoundFile` naming the clip. Popup ships enabled and the rest ship off. The guard limits output to one message per closed bar.

Every Gann trend Indicator input

Core settings

Setting What it does Default
GannPeriod Lookback for HH/LL. Bars in the high and low window, default `14`. This is the only calculation input, and it sets how quickly the midline moves. 14
PaintBackground Color-code trend background. Turns the coloured rectangles on and off. Set it `false` for the line and arrows alone. on

Display settings

Setting What it does Default
UpBgColor Shading while price sits above the midline, default `clrDarkGreen`, with `DnBgColor` at `clrMaroon` below it. dark green
DnBgColor (see inputs panel) maroon

Alert settings

Setting What it does Default
EnableAlerts (see inputs panel) on
EnablePopup (see inputs panel) on
EnablePushNotify (see inputs panel) off
EnableEmail (see inputs panel) off
EnableSound (see inputs panel) off
SoundFile (see inputs panel) alert.wav
Gann trend indicator inputs: GannPeriod and the PaintBackground toggle
Gann trend indicator inputs: GannPeriod and the PaintBackground toggle

Settings that fit your chart

A fourteen-bar range midline works on any liquid instrument. EURUSD H1 is the reference chart, where the midline updates through the session and the state changes a few times a day. On M5 side changes come constantly. On H4 and daily the midline moves slowly and a state change marks something closer to a genuine trend shift.

When the Gann trend Indicator fails

The midline follows the range rather than price, so a single wide bar shifts it and can flip the state without any real move.

In a range price straddles the midline, and the background alternates colour every few bars.

There is no filter of any kind. Every close on the other side registers, however marginal.

Copy the compiled Gann trend Indicator file into your MQL4/Indicators folder, and the MT5 build into MQL5/Indicators, then restart the terminal and drag it onto a chart. The step-by-step guide with screenshots is at how to install MT4 and MT5 indicators.

Download the Gann trend Indicator for MT4 and MT5

The zip holds the compiled Gann trend Indicator build for MT4 and MT5, plus a short README. Compiled files only, no source. Enter your email below and the download link arrives in your inbox.

Download this indicator free

Enter your email and the file is yours. You also get the full MT4 and MT5 library.

  • 1,380+ indicators
  • MT4 and MT5 files
  • No spam, unsubscribe any time

FAQ

Why does the Gann Midline use the range midpoint, not an average?

Because the two answer different questions. A moving average tracks where closes have been. The midline tracks where the RANGE is centred, taking only the highest high and lowest low of the window. That makes it respond to a single wide bar in a way an average would smooth over, which is closer to how swing-chart traders read structure.

What does GannPeriod at 14 cover?

The fourteen bars whose extremes set the midline. On H1 that is a bit over half a trading day. Shorten it and the line chases price, flipping the state often. Lengthen it toward 30 or 50 and the midline steadies, which makes the background shading a slower and more meaningful read.

Why does PaintBackground stop shading part way back?

paint_to caps the pass at five hundred bars, or fewer when the history is short. Painting every bar on a long chart costs time and fills the object list. Scroll far enough back and you reach unpainted candles, which is a drawing limit rather than missing data.

Do the Gann Up arrows need a confirmed close?

Yes. The test compares trend_now against trend_prev, and both derive from completed closes against their own bar’s midline. A wick across the line changes nothing. That said, there is no additional filter, so a close a fraction past the midline counts the same as a decisive one.

Are results guaranteed?

No. Trading involves risk. Results are not guaranteed; past performance is not indicative of future results. Use the Gann trend Indicator as one input. Always backtest before trading live.

Category: this is part of our Trend collection. Also, browse more Trend for MetaTrader, or explore every MT4 indicator and MT5 indicator on the site.

External references

Dominic Walsh - Forex trader and MT4/MT5 developer

About the author

Written by Dominic Walsh, a Forex trader and MT4/MT5 indicator, Expert Advisor and script developer. Every tool on forexmt4systems.com is tested on live charts before release and ships with ready-to-use compiled MT4 (.ex4) and MT5 (.ex5) files. Learn more about the trader and developer behind this site.

How we build, test and correct every tool: Editorial & Testing Policy. Trading carries risk; see the disclaimer.

Leave a Comment