FrameAdd using data file - page 2

 
Without files

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

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

fxsaber, 2017.05.22 15:04

Получаем конфиденциальные данные владельцев облачных агентов
#include <TypeToBytes.mqh>

input int Range = 0;

template <typename T>
struct ARRAY
{
  T Array[];
  
  void operator +=( const T Value )
  {
    const int i = ArrayResize(this.Array, ArraySize(this.Array) + 1) - 1;
    
    this.Array[i] = Value;
  }
};

#define TOSTRING(A) #A + " = " + (string)(A)
#define ADD(A,B) Str += TOSTRING(TerminalInfo##A(B));

void GetPrivateData( ARRAY<string> &Str )
{
  Str += TOSTRING(MQLInfoString(MQL_PROGRAM_PATH));
  
  ADD(Integer, TERMINAL_BUILD)
  ADD(Integer, TERMINAL_COMMUNITY_ACCOUNT)
  ADD(Integer, TERMINAL_COMMUNITY_CONNECTION)
  ADD(Integer, TERMINAL_CONNECTED)
  ADD(Integer, TERMINAL_DLLS_ALLOWED)
  ADD(Integer, TERMINAL_TRADE_ALLOWED)
  ADD(Integer, TERMINAL_NOTIFICATIONS_ENABLED)
  ADD(Integer, TERMINAL_MAXBARS)
  ADD(Integer, TERMINAL_MQID)
  ADD(Integer, TERMINAL_CODEPAGE)
  ADD(Integer, TERMINAL_CPU_CORES)
  ADD(Integer, TERMINAL_DISK_SPACE)
  ADD(Integer, TERMINAL_MEMORY_PHYSICAL)
  ADD(Integer, TERMINAL_MEMORY_TOTAL)
  ADD(Integer, TERMINAL_MEMORY_AVAILABLE)
  ADD(Integer, TERMINAL_MEMORY_USED)
  ADD(Integer, TERMINAL_X64)
  ADD(Integer, TERMINAL_OPENCL_SUPPORT)
  ADD(Integer, TERMINAL_SCREEN_DPI)
  ADD(Integer, TERMINAL_PING_LAST)

  ADD(Double, TERMINAL_COMMUNITY_BALANCE)

  ADD(String, TERMINAL_LANGUAGE)
  ADD(String, TERMINAL_COMPANY)
  ADD(String, TERMINAL_NAME)
  ADD(String, TERMINAL_PATH)
  ADD(String, TERMINAL_DATA_PATH)
  ADD(String, TERMINAL_COMMONDATA_PATH)
}

void OnTesterPass()
{
  ulong Pass;
  string Name;
  long ID;
  double Value;
  uchar Data[];

  while (FrameNext(Pass, Name, ID, Value, Data))
  {
    string Str[];
    
    _ArrayCopy(Str, Data);
    
    ArrayPrint(Str);
  }
}

double OnTester()
{
  ARRAY<string> Str;  

  GetPrivateData(Str);
  
  FrameAdd("Temp", 0, 0, _R(Str.Array).Bytes);
  
  return(0);
}

Доступны имя пользователя Windows, битность, число ядер, размер памяти и т.д.

 
Alain Verleyen:

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

Thanks @Stanislav Korotky

Hi Alain Verleyen,

I think you got it!! (as always!). I thought I had to put the filename as "filetest.csv", while only using "filetest" is sufficient... very good, Master!

FrameAdd("Statistics",rndval,0,"filetest")

And as Stanislav Korotky already wrote, using ShortArrayToString is a necessary step to correctly retrieve the string information.

Congrats, Master!

Regards,
Malacarne

 
Rodrigo Malacarne:

Hi Alain Verleyen,

I think you got it!! (as always!). I thought I had to put the filename as "filetest.csv", while only using "filetest" is sufficient... very good, Master!

And as Stanislav Korotky already wrote, using ShortArrayToString is a necessary step to correctly retrieve the string information.

Congrats, Master!

Regards,
Malacarne

You are always welcome
 
fxsaber:
Without files

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

Вопросы от начинающих MQL5 MT5 MetaTrader 5

fxsaber, 2017.08.23 14:10

Для записи данных Агентов в один файл нужно использовать Фрейм-режим.

// Пример записи данных Агентов (включая Облачные) в один файл
input int Range = 0;

void OnTick()
{
// ....
}

// Файл открываем только в режимах одиночночного прогона или Фрейма.
const int handle = ((MQLInfoInteger(MQL_TESTER) && !MQLInfoInteger(MQL_OPTIMIZATION)) || MQLInfoInteger(MQL_FRAME_MODE)) ?
                   FileOpen(__FILE__, FILE_WRITE | FILE_TXT) : INVALID_HANDLE;

// Подготовка данных
void GetData( string &Str, MqlTick &Ticks[], double &Balance )
{
  Str = "Hello World!";
  
  CopyTicks(_Symbol, Ticks, COPY_TICKS_ALL, 0, 2); // Последние два тика (пример)
  
  Balance = AccountInfoDouble(ACCOUNT_BALANCE);
}

// Запись данных
void SaveData( const string &Str, const MqlTick &Ticks[], const double Balance )
{
  FileWrite(handle, Str);
  
  for (int i = 0; i < ArraySize(Ticks); i++)
    FileWrite(handle, Ticks[i].bid);
    
  FileWrite(handle, Balance);
}

void OnTesterDeinit()
{
  if (handle != INVALID_HANDLE)  
    FileClose(handle);
    
  ChartClose();
}

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

double OnTester()
{
  string Str;
  MqlTick Ticks[];
  double Balance;
  
  GetData(Str, Ticks, Balance); // Подготовка данных для записи

  if (MQLInfoInteger(MQL_OPTIMIZATION)) // Оптимизация
  {
    CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205
    
    Container[0] = Str;
    Container[1] = Ticks;
    Container[2] = Balance;
  
    FrameAdd(NULL, 0, 0, Container.Data); // Отправили данные из Агента на Терминал
  }
  else // Одиночный прогон
  {    
    if (handle != INVALID_HANDLE)
      SaveData(Str, Ticks, Balance); // Данные будут записаны в MQL5\Files-папку Агента (не Терминала)
    
    FileClose(handle);
  }
  
  return(0);
}

void OnTesterPass()
{    
  if (handle != INVALID_HANDLE)
  {
    ulong Pass;
    string Name;
    long ID;
    double Value;
  
    CONTAINER<uchar> Container; // https://www.mql5.com/ru/forum/95447/page4#comment_5464205
  
    while (FrameNext(Pass, Name, ID, Value, Container.Data))
    {
      string Str;
      MqlTick Ticks[];
      double Balance;
      
      // Получили данные от Агента
      Container[0].Get(Str);
      Container[1].Get(Ticks);
      Container[2].Get(Balance);
      
//      FileWrite(handle, Pass);     // Если хочется записать номер прохода
      SaveData(Str, Ticks, Balance); // Данные будут записаны в MQL5\Files-папку Терминала (не Агента)
    }
  }
}
 
Alain Verleyen:

No, as I said it works, not for you ?

2017.05.21 20:00:48.107    FrameTest (EURUSD,M6)    OnTesterInit(): Start Optimization
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:0 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.292    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:16 name:Statistics id:28820 value:0.000000
2017.05.21 20:00:57.309    FrameTest (EURUSD,M6)    Size: 28 this is a random test 28820
...

2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    OnTesterPass : new frame pass:79 name:Statistics id:8492 value:0.000000
2017.05.21 20:01:10.587    FrameTest (EURUSD,M6)    Size: 27 this is a random test 8492
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    -----------
2017.05.21 20:01:10.720    FrameTest (EURUSD,M6)    OnTesterDeinit(): End Optimization

Build 1596.

Hi there, hope you can help to preserve my hairline. I've copied your code exactly replacing my attempts, and in my log `OnTesterPass` never gets called, inside the 'Agent-127.0.0.1-3000\MQL5\Files' the file `filetest` is being created. Logs for the agent don't have any entires from the print statements in the `OnTester` function. I am out of ideas of what I am doing wrong, and ideas? Build #1643 @Alain Verleyen 


```

2017.09.17 23:18:44.697 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) OnTesterInit(): Start Optimization 

2017.09.17 23:18:44.697 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) -----------C:\Users\danielsokolowski\AppData\Roaming\MetaQuotes\Terminal\36B48814C6C658AA3EC0B66B0B23CF41

2017.09.17 23:18:48.945 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) -----------

2017.09.17 23:18:48.945 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) OnTesterDeinit(): End Optimization

```

 
danielsokolowsk:

Hi there, hope you can help to preserve my hairline. I've copied your code exactly replacing my attempts, and in my log `OnTesterPass` never gets called, inside the 'Agent-127.0.0.1-3000\MQL5\Files' the file `filetest` is being created. Logs for the agent don't have any entires from the print statements in the `OnTester` function. I am out of ideas of what I am doing wrong, and ideas? Build #1643 @Alain Verleyen 


```

2017.09.17 23:18:44.697 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) OnTesterInit(): Start Optimization 

2017.09.17 23:18:44.697 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) -----------C:\Users\danielsokolowski\AppData\Roaming\MetaQuotes\Terminal\36B48814C6C658AA3EC0B66B0B23CF41

2017.09.17 23:18:48.945 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) -----------

2017.09.17 23:18:48.945 DS_1MilNetWorthBy40-v53 (GBPNZD,H1) OnTesterDeinit(): End Optimization

```

Please provide some code if you need coding help.
 
danielsokolowsk:

my log `OnTesterPass` never gets called, inside the 'Agent-127.0.0.1-3000\MQL5\Files' the file `filetest` is being created. Logs for the agent don't have any entires from the print statements in the `OnTester` function. I am out of ideas of what I am doing wrong, and ideas?

Delete the optimization cache. For example, recompile the EA.

 
Alain Verleyen:
Please provide some code if you need coding help.

I have finally figured it out. `OnTesterPass` will NOT be called for single tester runs (Optimization: Disabled) and for 'Optimization: All symbols in the MarketWatch', that is when `MQLInfoInteger(MQL_TESTER)=1 && MQLInfoInteger(MQL_OPTIMIZATION)=0`. This actually posses a huge problem - unless I am missing something obvious - but one is simply unable to extract any statistics data form remote agents in the following two scenarios:

- single run but with a remote agent selected to run it

- remote agents utilized in 'Optimization: All symbols in the MarketWatch'

Be great,

 
danielsokolowsk:

I have finally figured it out. `OnTesterPass` will NOT be called for single tester runs (Optimization: Disabled) and for 'Optimization: All symbols in the MarketWatch', that is when `MQLInfoInteger(MQL_TESTER)=1 && MQLInfoInteger(MQL_OPTIMIZATION)=0`. This actually posses a huge problem - unless I am missing something obvious - but one is simply unable to extract any statistics data form remote agents in the following two scenarios:

- single run but with a remote agent selected to run it

You can workaround it by using an optimization "Slow complete algorithm" with only 2 passes.

- remote agents utilized in 'Optimization: All symbols in the MarketWatch'

You could write to ServiceDesk, maybe they can enabled OnTesterXXX() for this kind of "optimization".

EDIT: from fxsaber post it seems, OnTesterPass() is working with this kind of optimization ? I don't have time to check myself.

 
danielsokolowsk:

I have finally figured it out. `OnTesterPass` will NOT be called for single tester runs (Optimization: Disabled) and for 'Optimization: All symbols in the MarketWatch', that is when `MQLInfoInteger(MQL_TESTER)=1 && MQLInfoInteger(MQL_OPTIMIZATION)=0`. This actually posses a huge problem - unless I am missing something obvious - but one is simply unable to extract any statistics data form remote agents in the following two scenarios:

- single run but with a remote agent selected to run it

- remote agents utilized in 'Optimization: All symbols in the MarketWatch'

It is not true!

Add this strings in your EA and start Optimization

#include <TypeToBytes.mqh> // https://www.mql5.com/ru/code/16280
#define REPORT_TESTER // В тестере будут автоматически записываться отчеты
#include <Report.mqh> // https://www.mql5.com/ru/code/18801


Result:


EURUSD (Data from OnTesterPass)



USDJPY (Data from OnTesterPass)