Backtesting Issue ( Strategy Tester hangs up )

 

Hello,


I`m backtesting my own EA on a (very) short time frame, 2 days at a Period of M1 (I`ve got the offline history data) . But the strategy tester always seem to hang around 40 % ( it actually races through up to 40 % ) . The CPU is still maxed out and the ram used stays around 170 Megs . I`ve let it run for 8 hours and I`m pretty sure that a backtest for 2 days shouldn`t take that long ( it`s a Dual Intel Core machine ) . Does anybody know that the cause of that would be ? when I run the EA live it seems to behave normaly but I just can't backtest it without hanging .. Maybe I`ve done something wrong in the EA code, but I`ve got no idea what it could be ...


Cheers,

 
julz:

Hello,


I`m backtesting my own EA on a (very) short time frame, 2 days at a Period of M1 (I`ve got the offline history data) . But the strategy tester always seem to hang around 40 % ( it actually races through up to 40 % ) . The CPU is still maxed out and the ram used stays around 170 Megs . I`ve let it run for 8 hours and I`m pretty sure that a backtest for 2 days shouldn`t take that long ( it`s a Dual Intel Core machine ) . Does anybody know that the cause of that would be ? when I run the EA live it seems to behave normaly but I just can't backtest it without hanging .. Maybe I`ve done something wrong in the EA code, but I`ve got no idea what it could be ...


Cheers,


Something intenstive executing (triggered by the start() function) with every tick?

Post your code and we'll have a look.


CB

 
cloudbreaker:

Something intenstive executing (triggered by the start() function) with every tick?

Post your code and we'll have a look.


CB

ah yeah, that would be it, I basically have nearly everything executing in the start(), I probably should outsource some of it in separate functions, here is the code :


int start()
{
//----

int
Total, // Amount of orders in a window
Tip=-1, // Type of selected order (B=0,S=1)
Ticket; // Order number

double
Lot, // Amount of lots in a selected order
Lts, // Amount of lots in an opened order
Min_Lot, // Minimal amount of lots
Step, // Step of lot size change
Free, // Current free margin
One_Lot, // Price of one lot
Price, // Price of a selected order
SL, // SL of a selected order
TP; // TP за a selected order
bool
Ans =false, // Server response after closing
Cls_B=false, // Criterion for closing Buy
Cls_S=false, // Criterion for closing Sell
Opn_B=false, // Criterion for opening Buy
Opn_S=false; // Criterion for opening Sell



double MA_1_t; // Current MA_1 value
double MA_2_t; // Current MA_2 value
double MA_1_t1;
double MA_2_t1;
double MA_1_t2;
double MA_2_t2;
double ADX;


MA_1_t=iMA(NULL,0,Period_MA_1,0,MODE_SMA,PRICE_CLOSE,0);
MA_2_t=iMA(NULL,0,Period_MA_2,0,MODE_SMA,PRICE_CLOSE,0);

MA_1_t1=iMA(NULL,0,Period_MA_1,1,MODE_SMA,PRICE_CLOSE,0);
MA_2_t1=iMA(NULL,0,Period_MA_2,1,MODE_SMA,PRICE_CLOSE,0);

MA_1_t2=iMA(NULL,0,Period_MA_1,2,MODE_SMA,PRICE_CLOSE,0);
MA_2_t2=iMA(NULL,0,Period_MA_2,2,MODE_SMA,PRICE_CLOSE,0);




ADX=iADX(NULL,0,14,PRICE_CLOSE,MODE_MAIN,0);



// Set SMA 1 Display
ObjectCreate("SMA_1", OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet("SMA_1", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("SMA_1", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("SMA_1", OBJPROP_YDISTANCE, 15);// Y coordinate
ObjectSetText("SMA_1",DoubleToStr(MA_1_t,5),20,"Arial",Cyan);

// Set SMA2 Display
ObjectCreate("SMA_2", OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet("SMA_2", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("SMA_2", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("SMA_2", OBJPROP_YDISTANCE, 40);// Y coordinate
ObjectSetText("SMA_2",DoubleToStr(MA_2_t,5),20,"Arial",Cyan);

// Set SMA Result Display
ObjectCreate("Result", OBJ_LABEL, 0, 0, 0);// Creating obj.
ObjectSet("Result", OBJPROP_CORNER, 0); // Reference corner
ObjectSet("Result", OBJPROP_XDISTANCE, 10);// X coordinate
ObjectSet("Result", OBJPROP_YDISTANCE, 70);// Y coordinate
ObjectSetText("Result","Waiting",20,"Arial",Cyan);
//Print("Previous High :"+High[1]);
//Print("Previous Low :"+Low[1]);


// Conditionss
if ((MA_1_t >= MA_2_t) && (MA_1_t1 > MA_2_t1) && (MA_1_t2 > MA_2_t2) && (MathAbs(MA_1_t-MA_2_t) >= Rastvor) ) // If difference between
{ // ..MA 1 and 2 is large
ObjectSetText("Result","SMA 1 > SMA 2",10);

if (Low[0] < MA_1_t && Open[0] > MA_1_t)
{
ObjectCreate("achete"+Bars,OBJ_ARROW, 0, TimeCurrent(), Bid); //draw a dn arrow
ObjectSet("achete"+Bars, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("achete"+Bars, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
ObjectSet("achete"+Bars, OBJPROP_COLOR,Blue);
WindowRedraw();

Opn_B=true; // Criterion for opening Buy
Cls_S=true; // Criterion for closing Sell
Print("On devrait acheter");
}



}

if ((MA_2_t > MA_1_t) && (MA_2_t1 > MA_1_t1) && (MA_2_t2 > MA_1_t2) && (MathAbs(MA_1_t-MA_2_t) >= Rastvor) ) // If difference between
{ // ..MA 1 and 2 is large
ObjectSetText("Result","SMA 2 > SMA 1",10);

if (High[0] > MA_1_t && Open[0] < MA_1_t )
{
ObjectCreate("vends"+Bars,OBJ_ARROW, 0, TimeCurrent(), Bid); //draw a dn arrow
ObjectSet("vends"+Bars, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet("vends"+Bars, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
ObjectSet("vends"+Bars, OBJPROP_COLOR,Red);
WindowRedraw();


Opn_S=true; // Criterion for opening Sell
Cls_B=true; // Criterion for closing Buy
Print("On devrait Vendre");
}
}

 

Just separating stuff into different functions won't help if that separate function is still always triggered during execution of the start() function.

What I've had to do in the past has been to provide a user configurable LIVE or TEST mode, the latter turning off intensive functionality which is not necessary during a test run.

Will peruse your code later when I've more time. Where is the rest of your code?


CB

 
cloudbreaker:

Just separating stuff into different functions won't help if that separate function is still always triggered during execution of the start() function.

What I've had to do in the past has been to provide a user configurable LIVE or TEST mode, the latter turning off intensive functionality which is not necessary during a test run.

Will peruse your code later when I've more time. Where is the rest of your code?


CB

Yeah, outsourcing the functions somewhere else wouldn`t help if they`re ran all the time, maybe as you say, I should disable the graphics functions with a switch, I`ve attached the rest of the code .

Files:
 

I`ve disabled all the OBJECTSET/OBJECTCREATE as well as the WindowRedraw(), but that doesn`t seem to help, I assume that they would not be computed by the Strategy tester anyway .

 
julz:

Yeah, outsourcing the functions somewhere else wouldn`t help if they`re ran all the time, maybe as you say, I should disable the graphics functions with a switch, I`ve attached the rest of the code .


Julz, I just had a very quick look at your code before going out (so haven't had a chance to try to understand your logic). Seems to me what is slowing things down are the loops in your start() function. If you execute a loop that has a significant number of iterations with every tick, it will definitely slow the tester down considerably, when you are testing against a data set which includes a lot of ticks. So have a look and see if you can be more selective about when you initiate a look through open orders, or through order history etc. Another question - do you really need to declare all those variables at the top of the start() function? Would aid performance to declare them outside start() if you can.


CB

 

CB


Thanks for looking into it,I'll move those variable declarations somewhere else and try to see what is executed/tick to lighten things up :)


Cheers !

Reason: