I try to code an EA and I wonder what is the best code regarding fast retrieval/obtain of prices.
Please respond with argues.
All opinions are very much appreciated !
When you use the MqlTick struct you call five pieces of information at the same time (time, bid, ask, last and volume)... so instead of using this whole piece of code
datetime _time = SymbolInfoInteger(_Symbol,SYMBOL_TIME); double _bid = SymbolInfoDouble(_Symbol,SYMBOL_BID); double _ask = SymbolInfoDouble(_Symbol,SYMBOL_ASK); double _last = SymbolInfoDouble(_Symbol,SYMBOL_LAST); ulong _volume = SymbolInfoInteger(_Symbol,SYMBOL_VOLUME);
you might simply use
MqlTick last_tick;
It's shorter to code and in some tests we've done in the Portuguese forum it's also faster to retrieve information.
When you use the MqlTick struct you call five pieces of information at the same time (time, bid, ask, last and volume)... so instead of using this whole piece of code
you might simply use
It's shorter to code and in some tests we've done in the Portuguese forum it's also faster to retrieve information.
OK, but if let say I need only ask, or only bid price. IMHO to code like this:
if (SymbolInfoDouble(_Symbol,SYMBOL_ASK) < price) some code
is faster than
MqlTick last_tick; if(last_tick.ask < price) some code
In the first case I ask for less information, so I retrieve the answer faster. Am I wright?
OK, but if let say I need only ask, or only bid price. IMHO to code like this:
is faster than
In the first case I ask for less information, so I retrieve the answer faster. Am I wright?
Why not test it yourself ?
I create a little test program, and I used the profiler to see what option is quicker.
input int TestingTime=300; //-- Profiling time for each option bool TestSymbolInfoTick=true; //-- Test SymbolInfoTick if true, SymbolInfoouble if false MqlTick tick; //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- EventSetTimer(TestingTime); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- double ask; if(TestSymbolInfoTick) { if(SymbolInfoTick(_Symbol,tick)) { ask=tick.ask; } } else { ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK); } } //+------------------------------------------------------------------+ //| Expert ontimer function | //+------------------------------------------------------------------+ void OnTimer() { TestSymbolInfoTick=!TestSymbolInfoTick; if(TestSymbolInfoTick) ExpertRemove(); } //+------------------------------------------------------------------+
and I run this code (started with profiling) on a EURUSD, M5 chart. Here is the result :
SymbolInfoDouble was called 868 times and takes 8498 µs to execute. It's an average of 9.79 µs
SymbolInfoTick was called 936 and takes 2450 µs +128 µs for assigning ask (not shown in the picture). It's an average of 2.75 µs.
Is it enough argues ?
Why not test it yourself ?
I create a little test program, and I used the profiler to see what option is quicker.
and I run this code (started with profiling) on a EURUSD, M5 chart. Here is the result :
SymbolInfoDouble was called 868 times and takes 8498 µs to execute. It's an average of 9.79 µs
SymbolInfoTick was called 936 and takes 2450 µs +128 µs for assigning ask (not shown in the picture). It's an average of 2.75 µs.
Is it enough argues ?
Why not test it yourself ?
I create a little test program, and I used the profiler to see what option is quicker.
and I run this code (started with profiling) on a EURUSD, M5 chart. Here is the result :
SymbolInfoDouble was called 868 times and takes 8498 µs to execute. It's an average of 9.79 µs
SymbolInfoTick was called 936 and takes 2450 µs +128 µs for assigning ask (not shown in the picture). It's an average of 2.75 µs.
Is it enough argues ?
Alain this is awesome!
May I ask a question pls?
Would this mean that practically you would always use SymbolInfoTick instead of SymbolInfoDouble to gain speed?
Thanks in advance.
Alain this is awesome!
May I ask a question pls?
Would this mean that practically you would always use SymbolInfoTick instead of SymbolInfoDouble to gain speed?
Thanks in advance.
Yes.
Thanks a lot.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I try to code an EA and I wonder what is the best code regarding fast retrieval/obtain of prices.
Please respond with argues.
All opinions are very much appreciated !