MT5 and speed in action - page 87

 
fxsaber:

Faster.

It does the same thing - it returns the function value. But it also makes checks beforehand.
Inside the function itself there are also checks for passed value of symbol name, and from it - either "if a simple string parameter instead of Symbol(), _Symbol or NULL, then checks for the full program and more property request", or uses values of the current symbol from cache without additional checks.
Why do you do them once again and still claim that it speeds up data retrieval? I do not understand the logic of such reasoning.

By the way, I always do so in my functions, but I don't think it somehow speeds up data retrieval, but rather slows it down because of checks of passed symbol name value in my function.

 
Artyom Trishkin:

Why do you do them again, and yet you claim it speeds up the data?

You yourself quoted the explanation.

 
Slava:

Symbol(), _Symbol entries are equivalent to NULL (where NULL is allowed instead of symbol name)

Is it the same in MT4? And in MT5 Tester what about it?

 
Artyom Trishkin:

By the way, I always do this in my functions

Show me please.

 
fxsaber:

You yourself quoted the explanation.

Exactly - it's all done inside the regular function. Why duplicate it on the outside as well?

 
Artyom Trishkin:

Exactly - it's all done inside the regular function. Why duplicate it on the outside as well?

Then you have not understood the explanation. The speed of the two calls is different.

void OnTick()
{
  static const string Symb = _Symbol;
  MqlTick Tick;
  
  SymbolInfoTick(_Symbol, Tick);
  SymbolInfoTick(Symb, Tick);  
}
 
fxsaber:

Please show me.

All the functions and methods where this is done with me?

There are too many of them.

 
Artyom Trishkin:

All the functions and methods where I do so?

One is enough.

 
fxsaber:

Then you have not understood the explanation. The speed of the two calls is different.

I seem to have understood it all. Of course it's different. So how did you speed it up? You pass a value that is not the current symbol to the function in one case - if it is not_Symbol.

Here, in the case when you pass the above value to the function, the function does not perform checks and takes the value of the current symbol from the cache.

In other cases, it queries the data of the specified symbol with the check "full program" + its presence in the market overview. Your "fast" function does not get rid of these checks when requesting data from a non-native symbol. So where is the acceleration?

bool SymbolInfoTickFast( const string &Symb, MqlTick &Tick )
{
  return((Symb == _Symbol) ? SymbolInfoTick(_Symbol, Tick)
                           : SymbolInfoTick(Symb, Tick));
}

Only two options in your function when called if(SymbolInfoTickFast(Symbol(), tick_array)) {}

  1. getting data of the current symbol - call SymbolInfoTick with parameter _Symbol (quick)
  2. fetch another symbol data - call SymbolInfoTick with string parameter (slow)

Another thing, if you (in your habit of defining everything that moves) create a string variable for the current symbol, then yes - you have to do checks here and replace your macro substitution with a predefined variable, or call Symbol()

 
Artyom Trishkin:

How did you speed it up?

It's hard for me to explain the obvious.
const MqlTick GetMarketWatchTick( const string &Symb )
{
  MqlTick Tick = {0};

  SymbolInfoTick(Symb, Tick);

  return(Tick);
}

void OnTick()
{
  MqlTick Ticks[1];
  
  Ticks[0] = GetMarketWatchTick(_Symbol);
  ArrayPrint(Ticks);
}
In this code, it is possible to speed up GetMarketWatchTick.