How fast is OnCalculate( ) ?

 

Hello,

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);

 

 
Malacarne:

Hello,

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.

You will miss ticks . . .  it's unavoidable.
 
Malacarne:...

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.

 
angevoyageur:

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)
  {
   Print("AT ASK");
  }
else
  {
   if(LastPrice == BidPrice)
     {
      Print("AT BID");
     }
   else
     {
      Print("BETWEEN");
     }
  }

However, this is (somehow) not working as intended...

 
Malacarne:

I provided part of the code... the idea is pretty simple, Alain:

However, this is (somehow) not working as intended...

You can't simply compare doubles like that and expect consistent results.  Price can != Price, read this thread:  Can price != price ?
Can price != price ? - MQL4 forum
  • www.mql5.com
Can price != price ? - MQL4 forum
 
RaptorUK:
You can't simply compare doubles like that and expect consistent results.  Price can != Price, read this thread:  Can price != price ?
Hum... very interesting, RaptorUK! Thanks a lot for sharing this! Do you think that redefining the variables using NormalizeDouble( ) could somehow solve the problem?
 
Redefined all the variables and the problem still persists... 
 

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:

   MqlTick last_tick;
   //---
   if(SymbolInfoTick(symbol,last_tick))
     {
         // tickrecorder.AddTick(symbol,last_tick);
     }
 
ugo58:

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:

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:

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 !

Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure for Current Prices
Documentation on MQL5: Standard Constants, Enumerations and Structures / Data Structures / Structure for Current Prices
  • www.mql5.com
Standard Constants, Enumerations and Structures / Data Structures / Structure for Current Prices - Documentation on MQL5
 
Malacarne:

ugo58, thanks for the suggestion! However, at least for me 

I believe it's not a question of how fast MqlTick( ) is, but rather OnCalculate( ) itself !

Why do you think there is an issue with OnCalculate ? I don't think so.