TimeCurrent() does not work during optimization

 
Hi. I am trying to extract timeCurrent inside onInit() and onTick() to get optimization starting time and current time, but it returns 1970 when I try to Print these variables during onTesterPass or onTesterInit. Does anyone know what is the problem? Thanks
 
Launger: Hi. I am trying to extract timeCurrent inside onInit() and onTick() to get optimization starting time and current time, but it returns 1970 when I try to Print these variables during onTesterPass or onTesterInit. Does anyone know what is the problem? Thanks

You should not use TimeCurrent() in OnInit(), only in OnTick(). However, TimeCurrent() is the simulated trade server time, not the current local time.

 
Fernando Carreiro #:

You should not use TimeCurrent() in OnInit(), only in OnTick(). However, TimeCurrent() is the simulated trade server time, not the current local time.

Hey yes I need get simulated history time, meaning if I want to start optimization from 01/01/21, it is going to return timeCurrent() equal to 01/01/21, but it still return TimeCurrent() equal to 1970 when I print it OnTesterPass
 
Launger #: Hey yes I need get simulated history time, meaning if I want to start optimization from 01/01/21, it is going to return timeCurrent() equal to 01/01/21, but it still return TimeCurrent() equal to 1970 when I print it OnTesterPass

Show your code sample. Otherwise we can't identify what you are doing incorrectly.

You don't have to provide all yout code. Male a small test code to demonstrate the problem you are having.

 
Fernando Carreiro #:

Show your code sample. Otherwise we can't identify what you are doing incorrectly.

You don't have to provide all yout code. Male a small test code to demonstrate the problem you are having.

datetime Time;

OnTick()
{
Time=timeCurrent();
}

OnTesterPass()
{
Print(Time);
}

But it prints 1970 on every pass, meaning it’s empty variable. I tried TimeToString() still returns the same value
 
Launger #: But it prints 1970 on every pass, meaning it’s empty variable. I tried TimeToString() still returns the same value
  1. Please use "</>" or Alt-S when adding code to your posts.
  2. Please provide proper code, that compiles, and in this case, that can be optimised (needs inputs).
  3. Initialise your global variable to a predictive value (e.g. WRONG_VALUE).
 

Please test optimisations on the following code and show us the log output.

input int i_nTest = 0;

datetime dtTime = WRONG_VALUE;

void OnTick() {
   dtTime = TimeCurrent();
};

void OnTesterPass() {
   Print( "OnTesterPass: ", dtTime );
};

double OnTester() {
   Print( "OnTester: ", dtTime );
   return 0;
};
 
Also, I've never used the OnTesterPass event handler, so I am not sure when it is called, if before or after the actual pass. Your results from the previous code should help identify that.
 
Fernando Carreiro #:
Also, I've never used the OnTesterPass event handler, so I am not sure when it is called, if before or after the actual pass. Your results from the previous code should help identify that.

I have modified your code, so it returns value onTesterPass. Please see the screenshots. It return wrong value for the dtTime

Files:
1.png  42 kb
2.png  40 kb
 
Fernando Carreiro #:
Also, I've never used the OnTesterPass event handler, so I am not sure when it is called, if before or after the actual pass. Your results from the previous code should help identify that.

I also tried to convert dtTime into double so I can pass the array into FrameAdd, but it still return wrong datetime.

Files:
1.png  42 kb
 
Launger #: Actually I have pasted your code inside my EA and that's what I got. Please see the screenshot

Then OnTesterPass() is being called BEFORE any OnTick events, just as I suspected, so you will not be able to collect data about the Test Date Range this way.

You may need to use the OnTester() instead, but you will need to output to a File as it seems that you cannot Print() from OnTester() either.

Reason: