TimeCurrent() does not work during optimization - page 2

 
Fernando Carreiro #:

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.

Do you mean I need to output to a File using FrameAdd()?

 
Fernando Carreiro #:

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.

actaually onTick() works well with OnTesterPass() because I am able to extract AccountInfoDouble(ACCOUNT_BALANCE) and pass it into array using FrameAdd

 
Launger #: actaually onTick() works well with OnTesterPass() because I am able to extract AccountInfoDouble(ACCOUNT_BALANCE) and pass it into array using FrameAdd

But is it returning the final balance or initial balance?

 
Launger #: Do you mean I need to output to a File using FrameAdd()?
Ignore my suggestion. I forgot the Print() is not your objective but the actual data about the time.
 
Fernando Carreiro #:
Ignore my suggestion. I forgot the Print() is not your objective but the actual data about the time.

Just last question, does TimeCurrent() works as usual in onTick() during optimisation? Thanks for help

 
Launger #: Just last question, does TimeCurrent() works as usual in onTick() during optimisation? Thanks for help

Yes it does! However, you did not answer my other question which will be relevant ...

Launger #:

actaually onTick() works well with OnTesterPass() because I am able to extract AccountInfoDouble(ACCOUNT_BALANCE) and pass it into array using FrameAdd

Fernando Carreiro #:

But is it returning the final balance or initial balance?

 
Fernando Carreiro #:

But is it returning the final balance or initial balance?

It depends whether you call it onInit or onTick. If you call it onTick then it return last balance
 
Launger #: It depends whether you call it onInit or onTick. If you call it onTick then it return last balance

No, I meant what value does it return in OnTesterPass()?

That is the whole point, to now if OnTesterPass() is being called before OnTick() is ever called or at the end of the test.

 
Fernando Carreiro #:

No, I meant what value does it return in OnTesterPass()?

That is the whole point, to now if OnTesterPass() is being called before OnTick() is ever called or at the end of the test.

OnTesterPass() is called AFTER any EA standard events, at the end of a pass.

The problem was there is no direct communication between the tested EA and OnTesterPass(), you need to transmit the value(s).

Imagine a cloud optimization, each pass of the tested EA is run remotely. It uses the standard EA events (OnInit, OnTick...), including OnTester().

At the same time, you have a special instance of the EA, running locally on your MT5 platform, which works ONLY with OnTesterInit(), OnTesterDeInit() and OnTesterPass() ( (when these events() are used otherwise this special instance is not launched).

Remotely, at the end of a pass, within OnTester() you can calculate and/or send data using FrameAdd(). These data will be received by the local instance with OnTesterPass(), there you can extract the data and process them.

datetime dtTime = WRONG_VALUE;

//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
void OnTick()
  {
   dtTime = TimeCurrent();
  }
//+------------------------------------------------------------------+
double OnTester()
  {
   string name="";
   long   id=0;
   double data[1];
   data[0]=(double)dtTime;

   FrameAdd(name,id,input_value,data);

   return 0;
  }
//+------------------------------------------------------------------+
void OnTesterInit()
  {
   Print("Begin...");
  }
//+------------------------------------------------------------------+
void OnTesterPass()
  {
   ulong  pass=0;
   string name="";
   long   id=0;
   double value=0.0;
   double data[];
   
   FrameNext(pass,name,id,value,data);
   Print(__FUNCTION__,": ", (datetime)data[0]);
  }
//+------------------------------------------------------------------+
void OnTesterDeinit()
  {
   Print("... end.");
  }

Begin...
OnTesterPasspass: 1 2023.02.03 23:54:59
OnTesterPasspass: 0 2023.02.03 23:54:59
OnTesterPasspass: 2 2023.02.03 23:54:59
OnTesterPasspass: 3 2023.02.03 23:54:59
OnTesterPasspass: 4 2023.02.03 23:54:59
OnTesterPasspass: 5 2023.02.03 23:54:59
... end.

That being said, I don't see any interest to transmit TimeCurrent(), it will be the same on all passes, but that's a detail.

Reason: