Deals History inside OnTesterPass - page 2

To add comments, please log in or register
Alain Verleyen
39060
Alain Verleyen  
Anthony Garot:

I avoided using frames. There were some limitations like the passing of only an array of doubles that had me switch tactics.

...

There is no limitation at all when you can use a file. What can't be passed in a file ?

Forum on trading, automated trading systems and testing trading strategies

FrameAdd using data file

Alain Verleyen, 2017.05.21 13:42

I checked against following your post and finally figured out how it works :

//+------------------------------------------------------------------+
//| Optimization start                                               |
//+------------------------------------------------------------------+
void OnTesterInit()
  {
//--- If writing of optimization results is enabled
   Print(__FUNCTION__,"(): Start Optimization \n-----------",TerminalInfoString(TERMINAL_DATA_PATH));
  }
//+------------------------------------------------------------------+
//| Test completion event handler                                    |
//+------------------------------------------------------------------+
double OnTester()
  {
//--- If writing of optimization results is enabled
   int hl=FileOpen("filetest",FILE_CSV|FILE_WRITE);
   if(hl==INVALID_HANDLE)
     {
      printf("Error %i creating tester file",GetLastError());
     }
   else
     {
      int rndval=MathRand();
      FileWriteString(hl,StringFormat("this is a random test %i",rndval));
      FileClose(hl);

      //--- Create a frame
      if(!FrameAdd("Statistics",rndval,0,"filetest"))
         printf("FrameAdd failed with error %i",GetLastError());
      else
        {
         Print("Frame added");
        }
     }
//---
   return(0.0);
  }
//+------------------------------------------------------------------+
//| Next optimization pass                                           |
//+------------------------------------------------------------------+
void OnTesterPass()
  {
   ulong pass;
   string name;
   long id;
   double value;
   ushort data[];

   if(!FrameNext(pass,name,id,value,data))
      printf("Error #%i with FrameNext",GetLastError());
   else
      printf("%s : new frame pass:%llu name:%s id:%lli value:%f",__FUNCTION__,pass,name,id,value);

   string receivedData=ShortArrayToString(data);
   printf("Size: %i %s",ArraySize(data),receivedData);
   Comment(receivedData);
  }
//+------------------------------------------------------------------+
//| End of optimization                                              |
//+------------------------------------------------------------------+
void OnTesterDeinit()
  {
   Print("-----------\n",__FUNCTION__,"(): End Optimization");
  }
Thanks @Stanislav Korotky

Anthony Garot
3637
Anthony Garot  
Alain Verleyen:

There is no limitation at all when you can use a file. What can't be passed in a file ?


Yes, using a file to pass information will work. In fact, your code snippet and what I do are very similar. We both open, write, and close from OnTester().

A different limitation I ran into:

I could not changing input parameters on-the-fly, specifically with ParameterSetRange(). This worked in theory, but I could only set it in OnTesterInit(), and the changed values were not recognized by the running optimization threads. It's possible I was doing something wrong. Global variables didn't work because they weren't shared between the calling instance and the optimization threads. So, passing information through files was the only possibility (further underscoring the correctness of your answer).

And since that was the case, I didn't see any value in using OnTesterInit(),OnTesterPass(),OnTesterDeinit() when I could simply dump data into a CSV from OnTester().

Ricardo Luceac
42
Ricardo Luceac  

Alain Verleyen:

There is no limitation at all when you can use a file. What can't be passed in a file ?

Thanks Alain, but just one more question, maybe a dumb on...

In every pass of the optimization the file will be write, so it gets overwriten by next pass?

or it is managed that the file content bellowing to that pass of optimization will be read by the framenext?

I dont get it...


Thanks

Ricardo Luceac
42
Ricardo Luceac  

Anthony Garot 2018.03.27 13:50   PT

See my comment here:

https://www.mql5.com/en/forum/35683#comment_6397172

I so use the optimizer, yes, and blend my results (CSV file) with the optimizer's results (XML file).

Python is nice for automating all of this because it has libraries for handling CSV, XML, and even INI files.

Thanks for the response...

But I prefer an mql only way.

Your way I need to tell metatrader to create the report, than save the parameters and compare with the xml to know from what pass is the results...

Maybe I do it if I automate the tests.

But I will try an mql only option first.


Thanks

Getting pass number while EA is going through optimization in strategytester?
Getting pass number while EA is going through optimization in strategytester?
  • 2014.08.23
  • www.mql5.com
Hello People I am just curious if EA can commnuicate with strategytester duing its optimizaiton process...
Anthony Garot
3637
Anthony Garot  
But I prefer an mql only way.

Of course. I can fully understand and appreciate that.

Ricardo Luceac
42
Ricardo Luceac  

Thanks everyone, saving to a file works!

Anthony Garot
3637
Anthony Garot  
Alain Verleyen:

There is no limitation at all when you can use a file. What can't be passed in a file ?

I dug into this a little more today.

It appears that when using Local Network Farm agents a file cannot be opened in the OnTester() event.

I know OnTester() is firing because data set in OnTester() is passed back to OnTesterPass() from the agents via frames.

So my approach of dumping data to a file from OnTester() only works for Local Agents, not Local Network Farm Agents, and presumably not for MQL5 Cloud Network Agents.

Anthony Garot
3637
Anthony Garot  

fxsaber:

. . .

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280

This is an interesting approach to passing non-double data through Frames.

Thank you for the suggestion.

fxsaber
14696
fxsaber  
Anthony Garot:

This is an interesting approach to passing non-double data through Frames.

Thank you for the suggestion.

And for custom events

Форум по трейдингу, автоматическим торговым системам и тестированию торговых стратегий

Библиотеки: TypeToBytes

fxsaber, 2018.03.31 09:24

// Кроссплатформенный пример передачи произвольных данных через пользовательское событие

#include <fxsaber\HistoryTicks\Data_String.mqh> // https://www.mql5.com/ru/code/20298

// Печать произвольных данных
template <typename T>
bool MyPrint( const T &Value )
{
  T Array[1];
  
  Array[0] = Value;
  
  ArrayPrint(Array, _Digits, NULL, 0, WHOLE_ARRAY, ARRAYPRINT_HEADER | ARRAYPRINT_ALIGN);
  
  return(true);
}

void OnChartEvent( const int id, const long &lparam, const double&, const string &sparam )
{
  // Распечатали полученные данные
  if ((id == CHARTEVENT_CUSTOM) &&
      (lparam ?  MyPrint(DATA_STRING::FromString<MqlDateTime>(sparam)) // Получили MqlDateTime
              : !MyPrint(DATA_STRING::FromString<MqlTick>(sparam))))   // Получили MqlTick
    ExpertRemove(); // Вышли из примера
}

void OnInit()
{
  MqlTick Tick;  
  MqlDateTime DateTime;
  
  // Заполнили значения
  SymbolInfoTick(_Symbol, Tick);  
  TimeCurrent(DateTime);

  // Передали
  EventChartCustom(0, 0, 0, 0, DATA_STRING::ToString(Tick));     // Передали MqlTick
  EventChartCustom(0, 0, 1, 0, DATA_STRING::ToString(DateTime)); // Передали MqlDateTime
}
12
To add comments, please log in or register