I'm trying to develop a tick indicator which will be used to determine if ticks are ocurring at bid, at ask or between quotes, as well as their volumes.
However, I'm having several problems when running the indicator, mainly because the indicator is returning wrong values for the volume and is wrongly identifying bid, ask and last quotes.
These problems usually occur when the market enters a "fast pace", with several orders ocurring at the same second, as shown in the picture attached. It seems to me that tick calculations cannot be made inside OnCalculate( ), because it's not fast enough to perform such computations.
Specifically in the picture attached, I'm showing the logs of two instances of MetaTrader 5 running in the same machine (i7-3930K, 4.1 MHz, 12 cores), receiving data from the same broker and running in the same symbol.
So, what could be the root of the problem? The internet connection (usually 26 ms latency, 15 Mbps), the data source itself or the OnCalculate( ) speed?
I would appreciate any explanation.
P.S.: by the way, I'm using this piece of code to capture bid/ask/last/volume information:
tick_ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK);
tick_bid = SymbolInfoDouble(_Symbol,SYMBOL_BID);
tick_last = SymbolInfoDouble(_Symbol,SYMBOL_LAST);
tick_volume = (int)SymbolInfoInteger(_Symbol,SYMBOL_VOLUME);
You don't show the code used to produce the result of your screenshot so it's difficult to give a complete answer, as I really don't understand your screenshot.
See this post, it may be interest you.
I provided part of the code... the idea is pretty simple, Alain:
if(LastPrice == AskPrice)
if(LastPrice == BidPrice)
However, this is (somehow) not working as intended...
For me "last" is always equal to the bid price. And I have still have to find out why I get more different ticks than the broker shows later a the M1 level ;)
I record ticks for 21 currencies which gives about 1 GByte for a week.
I think this could be faster:
last isn't use with forex. It's used with Depth of Market for stock exchange (maybe some broker activate DOM for forex but not sure it makes sense).
Maybe because OnCalculate() isn't the same as OnTick().
ugo58, thanks for the suggestion! However, at least for me
last_tick.last == NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_LAST),_Digits)
I believe it's not a question of how fast MqlTick( ) is, but rather OnCalculate( ) itself !