Introduction
The MetaTrader 5 Depth of Market (DOM) is one of the platform's most powerful yet underutilized features for algorithmic traders. Unlike MT4, which offers no real order book data, MT5 provides live market depth showing pending buy and sell orders at various price levels. For algo traders, this data reveals supply and demand dynamics that can inform entry, exit, and risk management decisions.
This guide will teach you how to enable, interpret, and programmatically access the MT5 DOM using MQL5. By the end, you'll be able to build custom Expert Advisors and indicators that react to order book imbalances, support/resistance from depth clusters, and trade size anomalies. You don't need a PhD in market microstructure—just MT5, a funded account with DOM access, and basic MQL5 knowledge.
Prerequisites
- MT5 Platform – Build 3916 or newer (check via Help > About). Older builds lack some DOM improvements.
- Live or demo account – DOM requires a broker that provides market depth. Most ECN/STP brokers offer it; verify under View > Market Watch, right-click a symbol, and see if "Depth" is enabled.
- MQL5 MetaEditor – Pre-installed with MT5 at Tools > MetaQuotes Language Editor.
- Basic MQL5 knowledge – Familiarity with OnTick() or OnCalculate(), variables, and simple conditionals.
- Symbol with sufficient liquidity – Forex majors, indices, or liquid futures work best. Avoid thinly traded symbols.
Step-by-Step Instructions
1. Enable and View the Depth of Market
- Open MT5 and go to View > Market Watch (Ctrl+M).
- Right-click inside Market Watch and select Depth (or Show All if hidden).
- Right-click the desired symbol (e.g., EURUSD) and choose Depth of Market (or press F2). The DOM panel appears on the left side of the chart.
- In the DOM panel, you'll see:
- Bid side (left) – Buy orders sorted descending by price.
- Ask side (right) – Sell orders sorted ascending by price.
- Volume column – Total lots/contracts at each level.
- Cumulative volume – Shown as a horizontal bar for quick visual comparison.
- Click Settings (gear icon) to customize:
- Depth levels – Default 10; increase to 20–50 for more granularity (broker-dependent).
- Volume format – Choose between lots, contracts, or ticks.
- Show cumulative – Toggle cumulative volume bars.
2. Interpret DOM Data for Trading Decisions
DOM reveals order book pressure. Key patterns:
- Imbalance – If cumulative bid volume at top 5 levels is much larger than ask volume, buyers are aggressive. Expect upward price movement.
- Support/Resistance – Large clusters of limit orders at a specific price often act as support (bids) or resistance (asks).
- Spoofing detection – Sudden large orders that disappear quickly may indicate manipulation. Your algorithm can ignore such levels.
Example: For EURUSD, if bids show 50 lots at 1.1050 and asks only 10 lots at 1.1051, the DOM suggests buying pressure. An algo could place a buy stop above 1.1051.
3. Access DOM Programmatically with MQL5
MQL5 provides the MarketBookGet() and MarketBookAdd() functions to retrieve DOM data. Here's a minimal Expert Advisor that prints the current book imbalance:
//+------------------------------------------------------------------+
//| DOM_Imbalance_EA.mq5 |
//+------------------------------------------------------------------+
#property copyright "Your Name"
#property version "1.00"
#property strict
void OnTick()
{
MqlBookInfo book[];
if(!MarketBookGet(_Symbol,book))
{
Print("Error getting DOM: ",GetLastError());
return;
}
double bidVol=0, askVol=0;
for(int i=0;i<ArraySize(book);i++)
{
if(book[i].type==BOOK_TYPE_BUY) bidVol+=book[i].volume;
if(book[i].type==BOOK_TYPE_SELL) askVol+=book[i].volume;
}
double imbalance = (bidVol-askVol)/(bidVol+askVol);
Comment("DOM Imbalance: ",DoubleToString(imbalance,2));
if(imbalance>0.3) Print("Strong buy pressure");
if(imbalance<-0.3) Print("Strong sell pressure");
}
//+------------------------------------------------------------------+
4. Subscribe to DOM Updates
DOM data requires subscription via MarketBookAdd() in OnInit():
int OnInit()
{
if(!MarketBookAdd(_Symbol))
{
Print("Failed to subscribe to DOM: ",GetLastError());
return(INIT_FAILED);
}
return(INIT_SUCCEEDED);
}
Unsubscribe in OnDeinit() with MarketBookRelease() to free resources.
5. Build a Simple Order Book Indicator
This indicator plots cumulative bid/ask volume as a histogram on the chart:
//+------------------------------------------------------------------+
//| DOM_Indicator.mq5 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots 2
#property indicator_type1 DRAW_HISTOGRAM
#property indicator_type2 DRAW_HISTOGRAM
#property indicator_color1 clrBlue
#property indicator_color2 clrRed
double BidBuffer[], AskBuffer[];
int OnInit()
{
SetIndexBuffer(0,BidBuffer,INDICATOR_DATA);
SetIndexBuffer(1,AskBuffer,INDICATOR_DATA);
IndicatorSetString(INDICATOR_SHORTNAME,"DOM Imbalance");
if(!MarketBookAdd(_Symbol)) return(INIT_FAILED);
return(INIT_SUCCEEDED);
}
int OnCalculate(const int rates_total,const int prev_calculated,
const datetime &time[],const double &open[],
const double &high[],const double &low[],
const double &close[],const long &tick_volume[],
const long &volume[],const int &spread[])
{
MqlBookInfo book[];
if(!MarketBookGet(_Symbol,book)) return(rates_total);
double bid=0, ask=0;
for(int i=0;i<ArraySize(book);i++)
{
if(book[i].type==BOOK_TYPE_BUY) bid+=book[i].volume;
if(book[i].type==BOOK_TYPE_SELL) ask+=book[i].volume;
}
BidBuffer[0]=bid;
AskBuffer[0]=ask;
return(rates_total);
}
void OnDeinit(const int reason)
{
MarketBookRelease(_Symbol);
}
Tips and Best Practices from Experience
- Use tick-by-tick DOM – Set your EA to run on OnBookEvent() instead of OnTick() for immediate DOM updates. OnBookEvent fires only when the order book changes, reducing CPU load.
- Filter noise – DOM updates can be frequent (100+ per second). Use a minimum volume threshold (e.g., ignore levels under 1 lot) to avoid false signals.
- Backtest with DOM – MT5 Strategy Tester does not simulate order book data. Use custom tick data with MqlTick structures if you need historical DOM behavior, or test on a demo account with live DOM.
- Manage memory – DOM arrays can grow large. Always call ArrayFree() after processing to avoid memory leaks in long-running EAs.
- Check broker limits – Some brokers cap DOM depth to 10 levels. Test with your broker before building complex algorithms.
Common Mistakes and Troubleshooting
Mistake 1: DOM Panel Shows No Data
Cause: Broker does not provide market depth, or symbol is not enabled for DOM.
Fix: Right-click symbol in Market Watch > Properties > ensure "Depth of Market" is checked. Contact broker if still empty.
Mistake 2: MarketBookGet() Returns Error 4106 (No Market Depth)
Cause: Subscription not added in OnInit().
Fix: Call MarketBookAdd() before any MarketBookGet() call. Check return value.
Mistake 3: EA Runs Slowly with DOM
Cause: Processing DOM on every tick instead of using OnBookEvent().
Fix: Replace OnTick() with void OnBookEvent(const string& symbol) and filter for your symbol.
Mistake 4: DOM Data Appears Stale
Cause: MarketBookRelease() called prematurely or broker throttling.
Fix: Ensure subscription persists for the EA lifetime. Add a delay in OnTick() if broker limits updates.
Summary / Recap and Next Steps
You now know how to enable the MetaTrader 5 Depth of Market, interpret order book data, and access it programmatically via MQL5 functions. The code examples provide a foundation for building DOM-driven EAs and indicators that react to real-time supply and demand.
Next steps:
- Experiment with the DOM indicator on a demo account for one week.
- Modify the EA to place pending orders based on imbalance thresholds.
- Explore MqlBookInfo structure fields (price, volume, type, and additional info like stop orders).
- Combine DOM with volume profile indicators for deeper market analysis.
For advanced reading, study the MarketBookGet() and OnBookEvent() documentation in MetaEditor's help (F1). The MT5 DOM is a gateway to professional-grade algorithmic trading—use it wisely.
Frequently Asked Questions
Can I use DOM in MT4?
No. MT4 does not support market depth. You must use MT5 for DOM data. Some third-party bridges exist but are unreliable.
Does DOM work in the Strategy Tester?
No. The Strategy Tester does not simulate order book data. Test DOM-based EAs on a demo account with live market conditions.
What is the best timeframe for DOM analysis?
DOM is tick-based and independent of chart timeframes. Use it for intraday scalping (1-minute to 15-minute charts) where order book dynamics matter most.
How do I handle DOM data from multiple symbols?
Call MarketBookAdd() for each symbol in OnInit(). In OnBookEvent(), check the symbol parameter and process accordingly. Use separate arrays per symbol to avoid confusion.






