Total Bid and Ask volume in mql5

 

Hello,

It's the 1st time i try to code in mql5 and i'm trying to calculate the total ask volume and bid volume of the previous candle.

Is this value stored somewhere or i have to do a cycle for each previous candle and add each bid/ask value to a variable for every single tick of that candle?

If someone can give me a small and quick example would be great as i didn't find much searching around!


Thanks.

 
Francesco Grassi: It's the 1st time i try to code in mql5 and i'm trying to calculate the total ask volume and bid volume of the previous candle. Is this value stored somewhere or i have to do a cycle for each previous candle and add each bid/ask value to a variable for every single tick of that candle? If someone can give me a small and quick example would be great as i didn't find much searching around!

No, the "ask" or "bid" volume is not stored anywhere because such a concept does not exist.

What does exist is the act of buying at "ask", and selling at "bid".

In non-centralised exchanges or markets, like Forex for example, such transaction volumes are not available. Only the tick quote prices are available.

All you can do is infer that there was a buy or sell transaction by analysing the tick data "ask/bid" quote prices but it is not always 100% clear.

 
Fernando Carreiro #:

No, the "ask" or "bid" volume is not stored anywhere because such a concept does not exist.

What does exist is the act of buying at "ask", and selling at "bid".

In non-centralised exchanges or markets, like Forex for example, such transaction volumes are not available. Only the tick quote prices are available.

All you can do is infer that there was a buy or sell transaction by analysing the tick data "ask/bid" quote prices but it is not always 100% clear.

Thank you for the quick reply.

So i have to calculate it. Should i use MqlTick or MarketBookGet?

In few words i want to receive the total amount of bid volume or ask volume of each previous candle so i can calculate the delta volume of those candles. It's odd how i can't find a single example on how to do it.

Right now i'm reading the article "MQL5 Cookbook: Implementing Your Own Depth of Market" to see if i can understand the process.

EDIT:

I forgot to mention that i want to analyze futures data and not forex data.

 
Francesco Grassi #: Thank you for the quick reply. So i have to calculate it. Should i use MqlTick or MarketBookGet? In few words i want to receive the total amount of bid volume or ask volume of each previous candle so i can calculate the delta volume of those candles. It's odd how i can't find a single example on how to do it. Right now i'm reading the article "MQL5 Cookbook: Implementing Your Own Depth of Market" to see if i can understand the process.

Market depth is only available for certain Exchange symbols and those are only a few of the markets. Most do not have market depth or real volume, only tick volume.

EDIT: I don't have much experience with Futures, sorry!

 
Fernando Carreiro #:

Market depth is only available for certain Exchange symbols and those are only a few of the markets. Most do not have market depth or real volume, only tick volume.

EDIT: I don't have much experience with Futures, sorry!

No worries,

hope someone else can enlight me with this delta indicator i'm trying to code.

 
Francesco Grassi #:

Thank you for the quick reply.

So i have to calculate it. Should i use MqlTick or MarketBookGet?

In few words i want to receive the total amount of bid volume or ask volume of each previous candle so i can calculate the delta volume of those candles. It's odd how i can't find a single example on how to do it.

Right now i'm reading the article "MQL5 Cookbook: Implementing Your Own Depth of Market" to see if i can understand the process.

EDIT:

I forgot to mention that i want to analyze futures data and not forex data.

You need to use MqlTick to analyze the "Time and Sales" which can provide you the real volumes.

Using the MarketBookGet will give you access to the order book. Not the trades.

 

I would like to rephrase and highlight once more what I stated before—there is no such thing as "ask" volume or "bid" volume.

For every market "buy", there will be an equivalent "sell". For every lot sold, there will be an equal volume bought. What drives prices up or down, is the volume NOT bought or NOT sold. When the "demand" and "supply" is unbalanced, price moves.

When some trader offers to buy a higher quantity or volume, than what is available for sale, the price may rise. When some trader offers to sell a higher quantity or volume, than what is required to be bought, the price may drop. I say "may", because contrary to expectations, sometimes the opposite happens. Human behaviour is very strange and fickle.

So, maybe you should rethink your concept and consider what exactly it is that you want to know with your definitions of "ask" and "bid" volumes. Maybe what you want to know is how many ticks occurred at a price higher than the previous price, and how many ticks occurred at a price lower than the previous price.

But even so, which price will you be considering? Maybe "ask" may change but not the "bid", or the "bid" may change but not the "ask", or the changes in "bid" and "ask" may be in opposite directions. All these possibilities are valid and occur in real trading. How will you consider them?

In other words, until you are able to properly define your meaning of "ask volume" and "bid volume", you will not be able achieve your goal. You may even end up having to call them by a different name that properly represents what you want to calculate.

 
Alain Verleyen #:

You need to use MqlTick to analyze the "Time and Sales" which can provide you the real volumes.

Using the MarketBookGet will give you access to the order book. Not the trades.

Thank you very much, i'll give it a try this weekend and see how it goes.

So if i want to check MqlTick on a previous candle, i just need to check the time parameter of MqlTick right?


Fernando Carreiro #:

I would like to rephrase and highlight once more what I stated before—there is no such thing as "ask" volume or "bid" volume.

For every market "buy", there will be an equivalent "sell". For every lot sold, there will be an equal volume bought. What drives prices up or down, is the volume NOT bought or NOT sold. When the "demand" and "supply" is unbalanced, price moves.

When some trader offers to buy a higher quantity or volume, than what is available for sale, the price may rise. When some trader offers to sell a higher quantity or volume, than what is required to be bought, the price may drop. I say "may", because contrary to expectations, sometimes the opposite happens. Human behaviour is very strange and fickle.

So, maybe you should rethink your concept and consider what exactly it is that you want to know with your definitions of "ask" and "bid" volumes. Maybe what you want to know is how many ticks occurred at a price higher than the previous price, and how many ticks occurred at a price lower than the previous price.

But even so, which price will you be considering? Maybe "ask" may change but not the "bid", or the "bid" may change but not the "ask", or the changes in "bid" and "ask" may be in opposite directions. All these possibilities are valid and occur in real trading. How will you consider them?

In other words, until you are able to properly define your meaning of "ask volume" and "bid volume", you will not be able achieve your goal. You may even end up having to call them by a different name that properly represents what you want to calculate.


Yes my bad, probably i should've be more clear with the request. I know what i'm looking for but i wasn't able to explain it properly.

I'm just trying to calculate the Delta volume which by definition is calculated by taking the difference of the volume that traded at the offer price and the volume that traded at the bid price and thus: Delta = (Ask – Bid Volume)


So the plan would be check with MqlTick the volume traded at bid and volume traded at ask of a given period of time (5m for example if i want to use it on 5min candles), add that volume to 2 different variables and then do ask variable - bid variable.


Thanks both of you for the moment, i'll let you know the results.

 
Francesco Grassi #: Thank you very much, i'll give it a try this weekend and see how it goes. So if i want to check MqlTick on a previous candle, i just need to check the time parameter of MqlTick right?

Yes my bad, probably i should've be more clear with the request. I know what i'm looking for but i wasn't able to explain it properly. I'm just trying to calculate the Delta volume which by definition is calculated by taking the difference of the volume that traded at the offer price and the volume that traded at the bid price and thus: Delta = (Ask – Bid Volume).  So the plan would be check with MqlTick the volume traded at bid and volume traded at ask of a given period of time (5m for example if i want to use it on 5min candles), add that volume to 2 different variables and then do ask variable - bid variable. Thanks both of you for the moment, i'll let you know the results.

I will repeat ... there is no such thing as "ask volume" or "bid volume", there is no such thing as volume "traded at offer" or volume "traded at bid" (at least not in the sense of a separate unbalanced transaction).

For every "buy" at Ask, there will be an equivalent "sell" at Bid, with the broker taking the Spread. Volume may be distributed amount several deals but the net result is always balanced, so by your definition, "Delta" will always be zero.

Consider what you really want to achieve by your calculation! You are making the wrong assumptions. Please pay careful attention—what you have described is incorrect.
 
Fernando Carreiro #:

I will repeat ... there is no such thing as "ask volume" or "bid volume", there is no such thing as volume "traded at offer" or volume "traded at bid" (at least not in the sense of a separate unbalanced transaction).

For every "buy" at Ask, there will be an equivalent "sell" at Bid, with the broker taking the Spread. Volume may be distributed amount several deals but the net result is always balanced, so by your definition, "Delta" will always be zero.

Consider what you really want to achieve by your calculation! You are making the wrong assumptions. Please pay careful attention—what you have described is incorrect.

Then how the delta volume indicators are calculated in the other platform?

The formula is the one i posted, probably i can't explain properly my concept but there must be a way to write a "delta volume" indicator.

Maybe i didn't understand what you exactly mean but i know for sure that Buy and Sell Volume can be different. It's like when you see a footprint chart and each candle has 2 coloumns: one for the bids and one for the asks and there are different values in the coloumns.


Probably the way you describes is how it works in forex and i'm not even sure it's like that.
 
Francesco Grassi #:

Then how the delta volume indicators are calculated in the other platform?

The formula is the one i posted, probably i can't explain properly my concept but there must be a way to write a "delta volume" indicator.

Maybe i didn't understand what you exactly mean but i know for sure that Buy and Sell Volume can be different. It's like when you see a footprint chart and each candle has 2 coloumns: one for the bids and one for the asks and there are different values in the coloumns.


Probably the way you describes is how it works in forex and i'm not even sure it's like that.

Their are already such indicators existing, why do you want to create your own ?

Just do a search on the Market.