2

In MQL4 ( MT4, MT5 ), how do I get the total volume of open Short and Long positions on the Exchange, for a current pair at the current time?

Stanislav Kralin
  • 11,070
  • 4
  • 35
  • 58
Amber More
  • 131
  • 1
  • 15

2 Answers2

1

A thing, you ask to get, is called a Level-3 Depth-of-Market, [L3-DoM].

Fact 1: there is not a common way to aggregate the Global DoM, may expect just a per Exchange ( a local, market-making, island ) Local DoM, so forget about seeing anything near the orders of magnitude of the average Global FX turnover, published to be about USD 5,400,000,000,000.00

Fact 2: even the local market-making body ( FX Trading Venue, LP provider, FX Broker et al ) do not expect to receive the Local DoM automatically, as not all bodies aggregate & provide the Local DoM on some public service-provisioning basis.

Fact 3: given some streaming interfaces can provide a Trader a flow of changes on the DoM, one ought expect using a high-frequency processing tools, to handle more than small/large tens ( hundreds/thousands even tens of thousands in peak hours alike NFP events, etc. ) changes per millisecond to happen. Given a professional trading venue is well oiled with sufficient peering with Prime Banks, Institutional LPs ( and perhaps a few DarkPool LPs ), the majors execute in common a Local DoM in the ranges above USD 50,000,000.00 on each of Long and Short sides.

Fact 4: some older updates of MetaTrader Terminal 4 started an add-on panel, called similarly a DoM, but there were no programmatic ways to communicate with such add-on panel/data. More details on this part of history are here.

Fact 5: The proposal, presented in his fairest belief by Daniel, does not provide DoM per-se, but show just your ( a Trader's ) own inventory of positions, placed on the table, not the real DoM landscape.


If interested in more details, do not hesitate to read more posts on DoM and some other animated latency graphs on Top-of-the-Book Price Lifetime to be able to compare FX Brokers timings against LMAX, Currenex or other LP-providers. For detailed LDG/GDF statistics on speed of changes in the L3-DoM near/during NFP announcement, enjoy the data collected in a Table aggregates from FIX-Protocol Stream Processing, presented in this post.

Community
  • 1
  • 1
user3666197
  • 1
  • 6
  • 50
  • 92
  • You shared good information, but then how iOBV and iMFI get data from, We can see clearly volume in MT4 basic Volumes>>Volumes indicator. Correct me if I am wrong. – Amber More Mar 12 '17 at 23:43
  • this is number of ticks. each time bid or ask changes - a new tick is generated and sent to your client mt4. amount of such ticks is called volume in mt4. in mt5 - you may have tick_volume(same as mt4) and real volumes (for certain pairs and exchanges but not for forex). iVolume and other volume based indicators are built on this tick data which is different for every broker – Daniel Kniaz Mar 13 '17 at 06:59
  • The word "Tick" has a few different meanings in different domains of use, a common trap in contemporary epochs. Yes, the MT4-tick ( counted, per Bar, in a summation register ( ADD-er ) called a "Volume" ) is an indication, that "just" the Top-of-the-Book price has changed. That could be understood as just a raw observation, what goes on in the L3-DoM, as the structure and the internal dynamics of the DoM-envelope remains invisible. A Tick signals that someone has cleared to zero the Top-of-the-Book capacity traded at Market and thus a next non-zero $$$ level ( under or above it ) becomes ToB. – user3666197 Mar 13 '17 at 13:14
-1

in mt5 - depends on your terminal, if you select non-hedging then total open position for each Symbol.

in mt4 - use the following code, if you are interested in trades open by some particular EA - then check both Symbol and magic number:

int buys = 0, sells = 0;         //number of tickets
double volBuys = 0, volSells = 0; //total volumes
for (int i=OrdersTotal()-1;i>=0;i--){
   if(OrderSelect(i,SEL_BY_POS)){
      if(OrderSymbol()==Symbol()){
         if(OrderType()==OP_BUY){
            buys++;
            volBuys += OrderLots();
         }else if(OrderType()==OP_SELL){
            sells++;
            volSells += OrderLots();
         }
      }
   }
 }
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20