What is Depth of Market?

Depth of Market is now available on many trading platforms. Depth of Market is available on MT5, cTrader and NinjaTrader. There are many professional traders who now use Depth of Market information in their trading decisions. The Depth of Market information when trading futures contract can be helpful. Futures contracts get traded on a centralized exchanges like the CBOT (Chicago Board of Trade). The volume information meaning how many contracts are long and how many contracts are short at a given point of time is accurately available. Download MT4 Script to close all trades.

Depth of Market

Forex is a Decentralized Over the Counter Market

Forex is a decentralized market unlike the stock and the futures market. Forex is an over the counter market with no central location. Forex gets traded electronically over the counter with no central location. Since forex is not a centralized market no volume information is available. Banks clusters get formed and trade currencies within those clusters. A few big banks form a cluster and some big hedge funds and financial institutions join them with the purpose of exchanging one currency with another. Learn how to code custom MT4 indicators.

Level II Depth of Market DOM

This is how the forex market operates. It is an over the counter market with no centralized location. It is divided into fragments and clusters. A broker may join a cluster and get rates from there. Now Depth of Market as far as it concerns the currency market is not as accurate as compared to the stock market or the futures market. What we see on the Depth of Market on MT5 is that brokers total buy limit order and sell limit orders for a particular currency. If the broker has large number of clients who trade high volume than we can have good depth of market info on that broker platform. On pairs like EURUSD, GBPUSD, USDJPY etc the depth of market can change every second. So it can pretty fast.

Depth of Market Python Script for MT5

Below I have developed a python script that you can use to download the Depth of Market info. This python script also adds the buy limit order volume and sell limit order volume. If we have more buy limit order volume we have more buying pressure and if we have more sell limit order volume we have more selling pressure. Sometimes this happens but other times we will have same buy limit order volume and sell limit order volume.

def depth_market(currency_pair, k=2):
    # establish connection to the MetaTrader 5 terminal
    if not mt5.initialize():    
        print("initialize() failed, error code =",mt5.last_error())
        # shut down connection to the MetaTrader 5 terminal    
        mt5.shutdown()
        quit()
    if mt5.market_book_add(currency_pair):        
        # display the entire market depth 'as is' in a single string             
        # get the market depth data 10 times in a loop   
        for i in range(k):
            # get the market depth content (Depth of Market)        
            items = mt5.market_book_get(currency_pair)
            buy_volume=0.0
            sell_volume=0.0
            # display the entire market depth 'as is' in a single string       
            print('***************************************')
            # now display each order separately for more clarity        
            if items:
                for item in items:
                    # order content                                   
                    print(item._asdict())
                    if item.type==1:
                        buy_volume +=item.volume
                    elif item.type==2:
                        sell_volume +=item.volume 
            print(f'buy volume is {buy_volume}.')
            print(f'sell volume is {sell_volume}.')                    
            # pause for 5 seconds before the next request of the market depth data        
            time.sleep(5)
        # cancel the subscription to the market depth updates (Depth of Market)   
        mt5.market_book_release(currency_pair)
    else:    
        print(f'mt5.market_book_add({currency_pair}) failed') 
        print('error code = ', mt5.last_error())
    # shut down connection to the MetaTrader 5 terminal
    mt5.shutdown()

Now this was the code for market depth. Once we run it we get results like below:

>>> abcd.depth_market("GBPUSD")
***************************************
buy volume is 0.0.
sell volume is 0.0.
***************************************
{'type': 1, 'price': 1.24653, 'volume': 20000000, 'volume_dbl': 20000000.0}
{'type': 1, 'price': 1.2463, 'volume': 10000000, 'volume_dbl': 10000000.0}
{'type': 1, 'price': 1.24615, 'volume': 5000000, 'volume_dbl': 5000000.0}
{'type': 1, 'price': 1.24613, 'volume': 3000000, 'volume_dbl': 3000000.0}
{'type': 1, 'price': 1.24609, 'volume': 1000000, 'volume_dbl': 1000000.0}
{'type': 1, 'price': 1.24607, 'volume': 500000, 'volume_dbl': 500000.0}
{'type': 1, 'price': 1.2460499999999999, 'volume': 165000, 'volume_dbl': 165000.0}
{'type': 2, 'price': 1.24599, 'volume': 5000, 'volume_dbl': 5000.0}
{'type': 2, 'price': 1.24597, 'volume': 500000, 'volume_dbl': 500000.0}
{'type': 2, 'price': 1.2459500000000001, 'volume': 1000000, 'volume_dbl': 1000000.0}
{'type': 2, 'price': 1.2459, 'volume': 3000000, 'volume_dbl': 3000000.0}
{'type': 2, 'price': 1.24588, 'volume': 5000000, 'volume_dbl': 5000000.0}
{'type': 2, 'price': 1.24573, 'volume': 10000000, 'volume_dbl': 10000000.0}
{'type': 2, 'price': 1.2455, 'volume': 20000000, 'volume_dbl': 20000000.0}
buy volume is 39665000.0.
sell volume is 39665000.0.
>>>

As you can see above we have type 1 and type 2 orders. Type 1 is the sell limit order and type 2 is the buy limit orders. One standard lot is 100,000 units of the quote currency. In the above python script we also calculate the total sell limit order volume and total buy limit order volume. In the above case the buy limit order volume and sell limit order is the same so that the market is in equilibrium. Download this MT5 Donchian Channel indicator.

What is Spoofing?

Spoofing is an illegal thing on the stock market and the futures market that are centralized markets. Spoofing means entering a very big sell limit order or a very high buy limit order just to move the market in the direction of that order. Before the price reaches that limit order price level that order is cancelled. It was just meant to fool the market. Spoofing is a problem on the forex market as well as stock market and the futures market. Learn how to calculate average true range and Keltner Channel.

In forex market, nothing can be done against spoofing. It is there and you should aware of it. So there can be big buy limit order or big sell limit order that is just meant to fool the market. So you should know this and use the depth of market info with some caution. Now this was the Depth of Market on MT5. We also have Depth of Market on cTrader which is far more elaborate as compared to MT5. As I have said earlier we can use Depth of Market for very short term moves. Due to spoofing danger we cannot even be sure about short term moves.