Download MetaTrader 5

How to put the start & end date of a backtest into a variable?

To add comments, please log in or register
mark101
85
mark101  
...so that I can use that to name a csv-file which the EA produces. Is there already a built-in variable for that?
Ali Akcaagac
168
Ali Akcaagac  
datetime timeval = TimeLocal();
string filename = "file-" + timeval + ".csv";
...

... This will return a string similar to "file-142414233.csv", where this crippled number shows the seconds since 1st of january 1970 until now. You can modify the datetime value to show more representative things like e.g. "file-20151130123359.csv" if you wish.

Carl Schreiber
7362
Carl Schreiber  
datetime start=0,end=0;
...
int start() {
   if (start==0) start = TimeCurrent();
   end = TimeCurrent();
}
...
double OnTester() {
   string FrTo = TimeToString(start)+"-"+TimeToString(end); // no seconds: 2015.08.12 08:12
   int fnd = StringReplace(FrTo,":",""); //get rid of :
}
mark101
85
mark101  
...
mark101
85
mark101  
gooly:

Thanks, gooly. I guess there is no way to have the end date right from the start because the csv-file is written on the fly (output at each bar) and not at the end of the test?
Carl Schreiber
7362
Carl Schreiber  
Alexnice:
Thanks, gooly. I guess there is no way to have the end date right from the start because the csv-file is written on the fly (output at each bar) and not at the end of the test?

1) You can enter the dates as parameters of the EA,

2) Write a tmp-file and rename it at the end

mark101
85
mark101  
Nr.2 works for me, thanks a lot.
To add comments, please log in or register