Thoughts on speeding up "Every Tick" testing

 

Back testing in "every tick" mode is extremely slow if the EA calls a bunch of different iCustom() functions. I have been trying to figure out a way to reduce the number of calculations without sacrificing precision. So far I have only been able to come up with one method:

This works for EAs that enter the market upon reaching a resistance level. Consider for example that our EA enters short when price climbs up to the 1.0000 point; we are then only interested in evaluating ticks that represent the current bar's HIGH (and vice versa for LOW). This code seems to speed things up quite a bit:

if (High[0] != Low[0]) if(Close[0] != High[0] && Close[0] !=Low[0])  return(0); 


Does anyone have any additional ideas?
 

Some custom indicators are badly coded and very inefficient by recalculating historical data that it just doesn't need to... Either review the code of the indicator and improve it's efficiency, or sometimes the actual guts of the indicator method is actually very simple and can just be coded directly into your EA.

hth

V

 
mfurlend:

Back testing in "every tick" mode is extremely slow if the EA calls a bunch of different iCustom() functions. I have been trying to figure out a way to reduce the number of calculations without sacrificing precision.

Same idea here. The indicators only change at either a new bar or at an extreme price.
//+------------------------------------------------------------------+
//| Skip useless ticks                                               |
//+------------------------------------------------------------------+
double      CA.below,   CA.above=0;         // \  Export
datetime    CA.when=0;                      // _> start
void CallAgain(double where, datetime nextTime=0){
    if (where>=Bid && CA.above > where) CA.above = where;
    if (where<=Bid && CA.below < where) CA.below = where;
    if (nextTime != 0 && CA.when >= nextTime)   CA.when = nextTime;
    return;
}
start(){
    datetime    now = TimeCurrent();
    if (now < CA.when && Bid > CA.below && Bid < CA.above)  return(0);
    #define INF 999999  // Don't call me again until the next special case.
    CA.when = now+INF;  CA.below = 0;   CA.above = INF;
    ...
    if (bid>open[0]){ // trading up
        ...
        if(notYet){ CallAgain(High[0]+Point,Time[0]+60*Period()); // Try again at new extreme
                   CallAgain(Open[0]-Point);                      // Try again at direction reversal
 
WHRoeder:
Same idea here. The indicators only change at either a new bar or at an extreme price.

to speed up back testing:

1- removed or comment out all screen output, objets, comment() etc ( you don´t need to see nothing on screen during optmization )

2- reduce the number of if on your logic as much as you can

use x++ instead of x = x +1

3- if possible look on the bar 1 not 0 on indicators, this could break your expert logic

4 -try not to make Dll calls

5- use StringConcatenate() instead of string + string

 

Great suggestions. I've been wondering, is it faster to assign variables such as Bid and Close[0] to a new variable and to use those instead? How about built-in functions like OrderOpenPrice()?

Another tip: Use nested IF statements instead of using "&&" if one of the checks is a function.

ex:

//Slow:
if (Bid > Ask && OrderOpenPrice() > Bid) DoSomething();

//Faster:
if (Bid > Ask) if (OrderOpenPrice() > Bid) DoSomething();

At least, thats what I've been told.

 
Also, I've been wondering if static variables use less memory than variables declared at the global level (as in, those declared before the start function, not the GlobalVariable...() type). Any thoughts?
 
mfurlend:
Also, I've been wondering if static variables use less memory than variables declared at the global level (as in, those declared before the start function, not the GlobalVariable...() type). Any thoughts?

I don't see why they should. The storage for the variable would be the same size.
 
WHRoeder:
Same idea here. The indicators only change at either a new bar or at an extreme price.

I am a bit confused about a few lines in this code:

    CA.when = now+INF;  CA.below = 0;   CA.above = INF;
    ...
    if (bid>open[0]){ // trading up
        ...
        if(notYet){ CallAgain(High[0]+Point,Time[0]+60*Period()); // Try again at new extreme
                   CallAgain(Open[0]-Point);                      // Try again at direction reversal

1. What is supposed to go in the spots where you wrote "..."?

2. What is "notYet" ?

 
Everything after the top ellipses are just to show how I use it. Think!