Libraries: Сode that records balance and equity charts and calculates additional optimization criteria

 

Сode that records balance and equity charts and calculates additional optimization criteria:

If you have access to the Expert Advisor code, you can save balance and equity charts and calculate additional optimization criteria by adding additional code from this library.

Сode that records balance and equity charts and calculates additional optimization criteria

Author: Aleksei Kuznetsov

 
It's a very useful library. When used in conjunction with the author's product, more advanced trading analysis indicators can be obtained.
 
save_Add( AvgPips, 2, "自定义1", true); When I change the name of a custom metric to Chinese, an error occurs. Changing the name of a built-in metric to Chinese also results in an error. It seems that only English is supported?
   save_Add( AvgPips, 2, "Custom 1", true);//value, digits, name, sort_min_to_max

I've found a way to add unicode to custom criteria names. Use character codes. For example:
Новая страница
It looks like this in Russian:

 
Aleksei Kuznetsov # :

I've found a way to add unicode to custom criteria names. Use character codes . For example:
Новая страница
It looks like this in Russian:

While this is feasible, I don't understand the difficulties in supporting UTF8. Could the codepage be set?

int    StringToCharArray ( 
   string   text_string,         
   uchar &  array[],             
   int      start= 0 ,             
   int      count=- 1              
   uint     codepage= CP_ACP     
   );

string  CharArrayToString(
   uchar  array[],              
   int    start=0,              
   int    count=-1              
   uint    codepage=CP_ACP      
   );
 
hini #:
StringToCharArray

codepage=CP_ACP is the default value.
1 byte is stored in the Char array. I have proposed a working unicode solution. Each of the characters in я can be encoded in 1 byte.

You can use this online converter: https://r12a.github.io/app-conversion/

For your sample: 自定义1  =  自定义1

If you find another working solution, please share it.

Unicode code converter
  • r12a.github.io
Helps you convert between Unicode character numbers, characters, UTF-8 and UTF-16 code units in hex, percent escapes,and Numeric Character References (hex and decimal).
 
Aleksei Kuznetsov # :
codepage=CP_ACP is the default value.
1 byte is stored in the array. I have proposed a working unicode solution. Each of the characters in & # 1103 can be encoded in 1 byte .
If you find another working solution, please share it.
void add( uchar &a[], string    v){add(a, StringLen (v)); StringToCharArray (v, a, ArraySize (a), -1, CP_UTF8 );}
Then can't we just read it in the panel by setting the last parameter of `CharArrayToString` to `CP_UTF8`?
 
hini #:
Then can't we just read it in the panel by setting the last parameter of `CharArrayToString` to `CP_UTF8`?
it didn't work in my test.
 
#property script_show_inputs

 enum ENUM_OPERATION {
  OP_SAVE = 0 ,   // Save 
  OP_LOAD = 1      // Load 
};

 input ENUM_OPERATION InpOperation = OP_SAVE;

 //+------------------------------------------------------------------+
 bool SaveStringToFile( string fileName, string text) {
   int handle = FileOpen (fileName, FILE_WRITE | FILE_BIN );
   if (handle == INVALID_HANDLE ) return false ;

   uchar data[];
   int size = StringToCharArray (text, data, 0 , - 1 , CP_UTF8 );
   Print ( "text length: " , StringLen (text));
   Print ( "data size: " , ArraySize (data)); 

   if (size > 0 ) {
     FileWriteArray (handle, data, 0 , size);
     FileClose (handle);
     Print ( "Save OK" );
     return true ;
  }

   FileClose (handle);
   return false ;
}

 //+------------------------------------------------------------------+
 bool LoadStringFromFile( string fileName, string &text) {
   int handle = FileOpen (fileName, FILE_READ | FILE_BIN );
   if (handle == INVALID_HANDLE ) return false ;

   uint fileSize = ( uint ) FileSize (handle);
   if (fileSize == 0 ) {
     FileClose (handle);
     return false ;
  }

   uchar data[];
   ArrayResize (data, fileSize);
   FileReadArray (handle, data, 0 , fileSize);
   FileClose (handle);

  text = CharArrayToString (data, 0 , WHOLE_ARRAY , CP_UTF8 );
   Print ( "read: " ,text);
   return true ;
}

 //+------------------------------------------------------------------+
 void OnStart () {
   string fileName = "test.bin" ;
   string testText = "Test Chinese text: 这是测试中文字符串" ;
  
   if (InpOperation == OP_SAVE) {
    SaveStringToFile(fileName, testText);
  } else {
     string loadedText = "" ;
    LoadStringFromFile(fileName, loadedText);
  }
}
 //+------------------------------------------------------------------+
My tests did not find any issues. You might need to pay attention to the length of the saved string; it should be "ArraySize" after being converted to an array, not "StringLen".
 
void add( uchar &a[], string     v){add(a, StringLen (v) ); StringToCharArray (v, a, ArraySize (a), - 1 , CP_UTF8 );}

This should not be StringLen.

void add(uchar &a[], string v) {
  uchar temp[];
  int byteCount = StringToCharArray(v, temp, 0, -1, CP_UTF8);

  add(a, byteCount);

  if(byteCount > 0) {
    int currentSize = ArraySize(a);
    ArrayResize(a, currentSize + byteCount);
    ArrayCopy(a, temp, currentSize, 0, byteCount);
  }
}
 
hini #:

This should not be StringLen.

This is a great solution.

I have added UTF support for UTF characters in Custom Criteria names to this library and to the report.


Note: UTF files are twice as large as ASCII files. For large reports > 50,000 passes, it is preferable to use only Latin characters or/and solution from this post https://www.mql5.com/en/forum/504277#comment_59090091.