Custom logic block implementation.
-
Hello.
I am trying to implement a custom logic block that writes data into a file for each pass of the optimization.
The normal write to file logic block does not use use the frame() function and therefore cannot write to file during optimization.I paid someone to cook a bit of code up for me that will do this.
The code below will write the bid price to file as a test, however the intent is to replicate the 'write to file' logic block and select a list of variables to input.But for now I'm taking it one step at a time and I'm only trying to insert this test script as the logic block. However I can't seem to get it to work.
I placed everything beneath OnTick() into the logic block editor of https://fxdreema.com/studio/MQL5
I placed the OnTesterPass() and OnTesterInit() code into the custom functions section
and everything above OnTick into global variables.This did not compile.
So I placed a few of the global variables into the logic block until it compiled without errors.
However the function does not activate when I place the logic block onto the 'every bar' timer.Can anyone inform me of my error?



#property copyright "Copyright 2020, IVZ."
#property link "https://www.mql5.com/ru/users/febintegral/"
#property version "1.00"
#property tester_everytick_calculatedouble stat_values[7]; // Массив для показателей теста
int cnt = 0;
input double test = 1;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
class SomeData
{
public:
string store;
};SomeData pSomeDAta[1];
bool Executed = false;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{double bidPrice = SymbolInfoDouble(_Symbol,SYMBOL_BID); // Getting the Bid Price
double Mass[20];
for(int i =0; i < 17; i++)
Mass[i] = i;MqlDateTime mdt;
TimeToStruct(TimeCurrent(),mdt);
string output = IntegerToString(mdt.year) + "." + IntegerToString(mdt.mon) + "." + IntegerToString(mdt.day) + "_" + IntegerToString(mdt.hour) + ":" + IntegerToString(mdt.min) + ":" + IntegerToString(mdt.sec)+ ";" + DoubleToString(bidPrice) + ";";for(int i =0; i < 17; i++)
output += "SomeData_" + DoubleToString(Mass[i]) + ";";pSomeDAta[0].store += output + "\r\n";
datetime dt = TimeCurrent();
MqlDateTime mdt1,mdt2;
TimeToStruct(dt,mdt2);TimeCurrent(mdt1);
int PassNumber = 0;
if(mdt.hour == 23 && mdt.min >= 50 && Executed == false)
{string file_name; long search_handle=FileFindFirst("*.csv",file_name,FILE_COMMON); //--- проверим, успешно ли отработала функция FileFindFirst() if(search_handle!=INVALID_HANDLE && -1 != StringFind(file_name,"filetest",0)) { int abc= 0; //--- в цикле проверим являются ли переданные строки именами файлов или директорий do { abc++; } while(FileFindNext(search_handle,file_name)); string sep="_"; // A separator as a character ushort u_sep; // The code of the separator character string result[]; // An array to get strings //--- Get the separator code u_sep=StringGetCharacter(sep,0); //--- Split the string to substrings int k = StringSplit(file_name,u_sep,result); PassNumber = (int)StringToInteger(result[1]); PassNumber++; //--- закрываем хэндл поиска FileFindClose(search_handle); } string headers="Header_1;Header_2;Header_3;Header_4;Header_5;Header_6;Header_7;Header_8;Header_9;Header_10;Header_11;Header_12;Header_13;Header_14;Header_15;Header_16;Header_17;Header_18;Header_19"; int h2=FileOpen("filetest_" + IntegerToString(PassNumber) + "_.csv",FILE_READ|FILE_WRITE|FILE_SHARE_WRITE|FILE_CSV|FILE_COMMON); FileSeek(h2,0,SEEK_END); FileWrite(h2,headers); FileSeek(h2,0,SEEK_END); FileWrite(h2,pSomeDAta[0].store); FileClose(h2); Executed = true; }cnt++;
}
Website doesn't fit all the code into the box for some reason. I attached file.0_1629040410511_FramesAndFiles (1).mq5
-
It seems that the OnTester() and OnTesterPass() sections are not compiling into the code.
A search for OnTester() or OnTesterPass() in the source file does not reveal any results.Could this be a bug?
-
@coinmaster I'm not a programmer but I know MQ% is not as well developed in fxDreema as MQ4. I would recommend to contact the admin and aski him.
-
He's rarely online anymore sadly. But I sent him a message.
-
@coinmaster True. However, I can guarantee he replied all personal messages. He may take its time to do it, though.