Termos de Referência
Zero-Lag MA Trend Levels — TradingView/Pine Script to MT5
1. Project Objective
Convert the supplied TradingView Pine Script v5 indicator:
"Zero-Lag MA Trend Levels [ChartPrime]"
into a fully functional MetaTrader 5 (MT5) custom indicator written in MQL5.
The objective is to reproduce the TradingView indicator's calculations, signals, visual appearance, trend levels, and behavior as closely as technically possible.
The final product must operate directly on an MT5 chart without requiring external indicators, DLLs, or additional files.
The original Pine Script uses:
-
EMA
-
Zero-Lag Moving Average (ZLMA)
-
ATR
-
Bullish/bearish crossovers
-
Trend-level zones
-
Secondary bullish/bearish signals
Default inputs:
-
Length = 15
-
ATR Period = 200
-
Trend Levels = ON
-
Bullish color = #30D453
-
Bearish color = #4043F1
The MT5 version must reproduce the following calculations.
EMA
Calculate:
EMA = EMA(Close, Length)
Default:
Length = 15
Zero-Lag Correction
Calculate:
Correction = Close + (Close - EMA)
ZLMA
Calculate:
ZLMA = EMA(Correction, Length)
The ZLMA calculation must match TradingView's ta.ema() behavior as closely as possible.
The original indicator determines the ZLMA trend using the value three bars previously.
Bullish ZLMA:
ZLMA > ZLMA[3]
Bearish ZLMA:
ZLMA < ZLMA[3]
If neither condition is true, the neutral state may be used.
Colors
Bullish:
#30D453
Bearish:
#4043F1
The EMA changes color according to its relationship with ZLMA.
Bullish
When:
EMA < ZLMA
EMA should use the bullish color.
Bearish
When:
EMA >= ZLMA
EMA should use the bearish color.
Bullish Signal
A bullish signal occurs when ZLMA crosses above EMA:
ZLMA crosses above EMA
Equivalent to:
ZLMA > EMA
on the current closed candle while:
ZLMA(previous) <= EMA(previous)
Bearish Signal
A bearish signal occurs when ZLMA crosses below EMA:
ZLMA crosses below EMA
Equivalent to:
ZLMA < EMA
on the current closed candle while:
ZLMA(previous) >= EMA(previous)
At every bullish crossover:
-
Plot a small diamond at the ZLMA price.
-
Use the bullish color.
At every bearish crossover:
-
Plot a small diamond at the ZLMA price.
-
Use the bearish color.
The diamonds must remain visible historically.
They must not disappear when the indicator is reloaded.
The chart must display:
-
ZLMA
-
EMA
Both should be plotted directly on the main price chart.
The ZLMA color should change according to its direction.
The EMA color should change according to whether it is above or below ZLMA.
The area between ZLMA and EMA should be visually filled.
Bullish
When:
ZLMA > EMA
Use the bullish color with transparency.
Bearish
When:
ZLMA < EMA
Use the bearish color with transparency.
The fill should update automatically as the relationship between the two lines changes.
Calculate:
ATR = ATR(200)
Default ATR period:
200
The ATR is used to determine the height of the trend-level zone.
The ATR period should be exposed as an MT5 input.
When a bullish ZLMA/EMA crossover occurs:
Top
ZLMA
Bottom
ZLMA - ATR
Create a bullish rectangular zone between these two prices.
The zone should use the bullish color with transparency.
The price associated with the signal should also be displayed where practical.
When a bearish ZLMA/EMA crossover occurs:
Top
ZLMA + ATR
Bottom
ZLMA
Create a bearish rectangular zone between these prices.
The zone should use the bearish color with transparency.
The trend-level zone should extend to the right after its creation.
The default extension is approximately 4 bars, matching the TradingView implementation.
The developer should ensure that the zone remains visually consistent with the TradingView version.
The original indicator creates a bullish ▲ signal when price crosses above the top of the active bullish trend-level zone.
Conditions should reproduce the Pine logic:
-
Price crosses above the trend-level top.
-
There was no new crossover signal on the current or previous bar.
-
EMA is below ZLMA.
The ▲ should be plotted around the relevant candle.
The signal must remain visible historically.
The original indicator creates a bearish ▼ signal when price crosses below the bottom of the active bearish trend-level zone.
Conditions:
-
Price crosses below the trend-level bottom.
-
There was no new crossover signal on the current or previous bar.
-
EMA is above ZLMA.
The ▼ should be plotted around the relevant candle.
The signal must remain visible historically.
This is important.
The MT5 indicator should not repaint historical signals.
Signals should preferably be confirmed using the closed candle.
Once a crossover or secondary signal has been confirmed on a closed candle:
-
It must remain on the chart.
-
It must not move to another historical candle.
-
It must not disappear after refreshing MT5.
-
It must not change simply because new candles appear.
The developer should clearly identify if any part of the original TradingView logic inherently behaves differently in real time.
When the indicator is attached to an existing MT5 chart, it must calculate historical data.
For example, if the chart contains 5,000 candles, the indicator should calculate and display historical:
-
ZLMA
-
EMA
-
crossover diamonds
-
trend-level zones
-
▲ signals
-
▼ signals
It must not only display signals generated after the indicator is attached.
The MT5 indicator should have the following inputs:
Main Settings
Length = 15
ATR Period = 200
Display
Show Trend Levels = true
Show Secondary Signals = true
Colors
Bullish Color = #30D453
Bearish Color = #4043F1
Alerts
Enable Alerts = false
Enable Push Notifications = false
Alert On Closed Candle = true
Optional alerts should be provided for:
Bullish crossover
"Symbol / Timeframe — Bullish ZLMA crossover"
Bearish crossover
"Symbol / Timeframe — Bearish ZLMA crossover"
Optionally provide alerts for:
-
▲ secondary bullish signal
-
▼ secondary bearish signal
Alerts should be one-time per signal.
The indicator must not repeatedly alert on every tick while the same signal remains active.
The indicator should be lightweight.
Avoid:
-
unnecessary calculations on every tick
-
excessive chart objects
-
infinite object creation
-
unnecessary recalculation of the entire history on every tick
Historical calculations may be performed when the indicator first loads, while subsequent calculations should preferably process only newly available data.
The indicator should be suitable for:
-
XAUUSD
-
Forex pairs
-
indices
-
CFDs
-
multiple MT5 timeframes
All chart objects created by the indicator must have a unique naming prefix.
For example:
ZLMA_TL_
When the indicator is removed from the chart, its objects should be removed automatically.
The indicator must not delete or modify objects belonging to other indicators or the trader.
The indicator should work on all standard MT5 timeframes, including:
-
M1
-
M5
-
M15
-
M30
-
H1
-
H4
-
D1
-
W1
-
MN1
No hard-coded timeframe should be used unless specifically required by the original Pine Script.
The indicator should work with different broker symbol formats, including symbols such as:
-
XAUUSD
-
XAUUSDm
-
XAUUSD.a
-
EURUSD
-
GBPUSD
-
US30
-
NAS100
-
and Synthetic Indices from Deriv broker
The code must use the current chart's symbol and price precision automatically.
The final source code must compile in the current MetaEditor/MT5 environment with:
-
0 errors
-
0 warnings where reasonably possible
The developer must provide the complete .mq5 source code.
No DLL dependency should be required.
No external indicator should be required.
Before delivery, the developer should test the indicator on:
XAUUSD M1
and at least one:
EURUSD M15/H1
Testing should verify:
-
ZLMA matches the TradingView calculation.
-
EMA matches TradingView.
-
Crossovers occur on the same candles.
-
Diamonds appear on the same candles.
-
Trend-level zones appear on the same signals.
-
Secondary ▲/▼ signals correspond to the Pine logic.
-
Historical signals remain visible.
-
Signals do not unnecessarily repaint.
-
Alerts trigger only once.
-
Removing/reloading the indicator does not destroy historical signal integrity.
The developer should compare the MT5 version against the supplied TradingView indicator using the same:
-
Symbol
-
Timeframe
-
Length
-
ATR period
-
Historical date range
The developer should aim for candle-by-candle agreement between TradingView and MT5.
Small differences caused by broker price feeds may be expected.
The developer should provide:
Required
-
Complete .mq5 source code.
-
Compiled .ex5 indicator.
-
List of configurable inputs.
-
Brief installation instructions.
-
Confirmation that the indicator compiles without errors.
Optional
-
Screenshots comparing TradingView and MT5.
-
Explanation of any unavoidable differences.
-
Alert configuration instructions.
The project will be considered complete when:
-
The indicator compiles successfully.
-
ZLMA and EMA calculations reproduce the Pine logic.
-
Bullish and bearish crossovers are correctly identified.
-
Crossover diamonds are visible.
-
Trend-level zones are correctly generated.
-
Secondary ▲/▼ signals are correctly generated.
-
Historical signals are visible.
-
The indicator does not unnecessarily repaint.
-
Alerts work correctly and do not repeat continuously.
-
The indicator works on XAUUSD and standard Forex symbols.
-
The indicator does not significantly slow down MT5.
-
All objects are properly managed when the indicator is removed.
Source Code
The developer will be provided with the original TradingView Pine Script v5 source code for:
Zero-Lag MA Trend Levels [ChartPrime]
The Pine Script should be treated as the reference implementation. The MT5 implementation should reproduce its behavior rather than merely translating Pine syntax line-by-line.