Please help - Problem in String Creation

 

Hi,

now I need your expertise.

I have trouble creating a string and outputting it on a file:


#property strict
#include <Files/FileTxt.mqh>

void OnStart() {
  CFileTxt      m_file;
  m_file.SetCommon (true);
  m_file.Open ("PosData.txt", FILE_WRITE|FILE_TXT);
  
  string pos = "";
  pos += "2 buy 0.10000 14050.00000 14050.00000 0.0 14100.00000 ";
  pos += "5 buy 0.10000 14050.00000 14050.00000 0.0 14150.00000 ";
  pos += "8 buy 0.10000 14050.00000 14050.00000 0.0 14200.00000 ";
  pos += "14 buy 0.10000 14000.00000 13999.10000 0.0 14050.00000 ";
  pos += "17 buy 0.10000 14000.00000 13999.10000 0.0 14100.00000 ";
  pos += "20 buy 0.10000 14000.00000 13999.10000 0.0 14150.00000 ";
  pos += "23 buy 0.10000 14000.00000 13999.10000 0.0 14200.00000 ";
  pos += "1051 buy 0.10000 13750.00000 13749.40000 0.0 13950.00000 ";
  pos += "32 buy 0.10000 13950.00000 13948.61000 0.0 14050.00000 ";
  pos += "35 buy 0.10000 13950.00000 13948.61000 0.0 14100.00000 ";
  pos += "38 buy 0.10000 13950.00000 13948.61000 0.0 14150.00000 ";
  pos += "41 buy 0.10000 13950.00000 13948.61000 0.0 14200.00000 ";
  pos += "932 buy 0.10000 13750.00000 13749.44000 0.0 14000.00000 ";
  pos += "914 buy 0.10000 13800.00000 13799.88000 0.0 14000.00000 ";
  pos += "125 buy 0.10000 13900.00000 13899.11000 0.0 14050.00000 ";
  pos += "128 buy 0.10000 13900.00000 13899.11000 0.0 14100.00000 ";
  pos += "131 buy 0.10000 13900.00000 13899.11000 0.0 14150.00000 ";
  pos += "134 buy 0.10000 13900.00000 13899.11000 0.0 14200.00000 ";
  pos += "899 buy 0.10000 13850.00000 13849.62000 0.0 14000.00000 ";
  pos += "1042 buy 0.10000 13750.00000 13749.40000 0.0 13800.00000 ";
  pos += "1023 buy 0.10000 13850.00000 13849.90000 0.0 13950.00000 ";
  pos += "149 buy 0.10000 13850.00000 13849.94000 0.0 14050.00000 ";
  pos += "152 buy 0.10000 13850.00000 13849.94000 0.0 14100.00000 ";
  pos += "155 buy 0.10000 13850.00000 13849.94000 0.0 14150.00000 ";
  pos += "158 buy 0.10000 13850.00000 13849.94000 0.0 14200.00000 ";
  pos += "1069 buy 0.10000 13700.00000 13699.83000 0.0 13850.00000 ";
  pos += "1014 buy 0.10000 13900.00000 13899.97000 0.0 13950.00000 ";
  pos += "1048 buy 0.10000 13750.00000 13749.40000 0.0 13900.00000 ";
  pos += "887 buy 0.10000 13900.00000 13899.76000 0.0 14000.00000 ";
  pos += "515 buy 0.10000 13800.00000 13799.86000 0.0 14050.00000 ";
  pos += "518 buy 0.10000 13800.00000 13799.86000 0.0 14100.00000 ";
  pos += "521 buy 0.10000 13800.00000 13799.86000 0.0 14150.00000 ";
  pos += "524 buy 0.10000 13800.00000 13799.86000 0.0 14200.00000 ";
  pos += "1078 buy 0.10000 13700.00000 13699.83000 0.0 14000.00000 ";
  pos += "1066 buy 0.10000 13700.00000 13699.83000 0.0 13800.00000 ";
  pos += "1032 buy 0.10000 13800.00000 13799.90000 0.0 13900.00000 ";
  pos += "1020 buy 0.10000 13850.00000 13849.90000 0.0 13900.00000 ";
  pos += "1029 buy 0.10000 13800.00000 13799.90000 0.0 13850.00000 ";
  pos += "545 buy 0.10000 13750.00000 13749.62000 0.0 14050.00000 ";
  pos += "548 buy 0.10000 13750.00000 13749.62000 0.0 14100.00000 ";
  pos += "551 buy 0.10000 13750.00000 13749.62000 0.0 14150.00000 ";
  pos += "554 buy 0.10000 13750.00000 13749.62000 0.0 14200.00000 ";
  pos += "1072 buy 0.10000 13700.00000 13699.83000 0.0 13900.00000 ";
  pos += "1075 buy 0.10000 13700.00000 13699.83000 0.0 13950.00000 ";
  pos += "1063 buy 0.10000 13700.00000 13699.83000 0.0 13750.00000 ";
  pos += "1045 buy 0.10000 13750.00000 13749.40000 0.0 13850.00000 ";
  pos += "1035 buy 0.10000 13800.00000 13799.90000 0.0 13950.00000 ";
  pos += "878 buy 0.10000 13950.00000 13949.81000 0.0 14000.00000 ";
  pos += "578 buy 0.10000 13700.00000 13699.50000 0.0 14050.00000 ";
  pos += "581 buy 0.10000 13700.00000 13699.50000 0.0 14100.00000 ";
  pos += "584 buy 0.10000 13700.00000 13699.50000 0.0 14150.00000 ";
  pos += "587 buy 0.10000 13700.00000 13699.50000 0.0 14200.00000 ";
  pos += "1234 buy 0.10000 13650.00000 13649.77000 0.0 13700.00000 ";
  pos += "1095 buy 0.10000 13650.00000 13649.70000 0.0 13750.00000 ";
  pos += "1098 buy 0.10000 13650.00000 13649.70000 0.0 13800.00000 ";
  pos += "1101 buy 0.10000 13650.00000 13649.70000 0.0 13850.00000 ";
  pos += "1104 buy 0.10000 13650.00000 13649.70000 0.0 13900.00000 ";
  pos += "1107 buy 0.10000 13650.00000 13649.70000 0.0 13950.00000 ";
  pos += "1110 buy 0.10000 13650.00000 13649.70000 0.0 14000.00000 ";
  pos += "1113 buy 0.10000 13650.00000 13649.70000 0.0 14050.00000 ";
  pos += "1116 buy 0.10000 13650.00000 13649.70000 0.0 14100.00000 ";
  pos += "1119 buy 0.10000 13650.00000 13649.70000 0.0 14150.00000 ";
  pos += "1122 buy 0.10000 13650.00000 13649.70000 0.0 14200.00000 ";
  pos += "1260 buy 0.10000 13600.00000 13599.96000 0.0 13650.00000 ";
  pos += "1263 buy 0.10000 13600.00000 13599.96000 0.0 13700.00000 ";
  pos += "1266 buy 0.10000 13600.00000 13599.96000 0.0 13750.00000 ";
  pos += "1269 buy 0.10000 13600.00000 13599.96000 0.0 13800.00000 ";
  pos += "1272 buy 0.10000 13600.00000 13599.96000 0.0 13850.00000 ";
  pos += "1275 buy 0.10000 13600.00000 13599.96000 0.0 13900.00000 ";
  pos += "1278 buy 0.10000 13600.00000 13599.96000 0.0 13950.00000 ";
  pos += "1281 buy 0.10000 13600.00000 13599.96000 0.0 14000.00000 ";
  pos += "1284 buy 0.10000 13600.00000 13599.96000 0.0 14050.00000 ";
  pos += "1287 buy 0.10000 13600.00000 13599.96000 0.0 14100.00000 ";
  pos += "1290 buy 0.10000 13600.00000 13599.96000 0.0 14150.00000 ";
  pos += "1293 buy 0.10000 13600.00000 13599.96000 0.0 14200.00000 ";
  
  string out = " ";
  out += "START of Problem ";
  out += StringFormat ("set A(positions) %s<newline> ", pos);
  out += "END";

  m_file.WriteString (out);
  m_file.Flush();
  m_file.Close();
}


The content of file with name PosData.txt is:

 START of Problem END

Where are my pos-data???? Mostly(!) there are missing.

I don't get it now! Please help!

Thanks a lot.

I'm using Metatrader 5 build 2776


Matthias


____________

"It is more important to feel strong than to be strong."

 

No idea what the problem is but I get the same behavior here.

It looks like StringFormat doesn't accept a string argument that exceeds 4065 characters in length.

 
lippmaje:

No idea what the problem is but I get the same behavior here.

It looks like StringFormat doesn't accept a string argument that exceeds 4065 characters in length.

Hello!

That's it! Thank you very much. I tried it again and again: 


StringFormat doesn't accept a string argument that exceeds 4092 characters in length.


But I cannot find this important info in the MQL5 reference! That is very bad.

Yesterday I needed a whole evening fighting with this problem :-(


Now I know this limitation of the StringFormat function. You gave me the crucial information. Thanks again.

You are an experienced MQL5 software developer, aren't you? (May be I will have further questions in the future...)

Matthias

Documentation on MQL5: Conversion Functions / StringFormat
Documentation on MQL5: Conversion Functions / StringFormat
  • www.mql5.com
StringFormat - Conversion Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Hi, I assume there's an internal buffer with a fixed size, and if the sum of all strings used for StringFormat exceeds that size it will return an empty result. I need to run a few tests about this.

If you have more interesting questions, meet me/us here in the forum. As the language is evolving, and the documentation sometimes misses details, it's always good to know about such limitations.

 
lippmaje:

Hi, I assume there's an internal buffer with a fixed size, and if the sum of all strings used for StringFormat exceeds that size it will return an empty result. I need to run a few tests about this.

If you have more interesting questions, meet me/us here in the forum. As the language is evolving, and the documentation sometimes misses details, it's always good to know about such limitations.

Knowing the limitations: that is essential. 

Thank you, lippmaje. 

Matthias 

There are no limits. There are only plateaus and you mustn't stop there, you have to go beyond them.
 
Hmmm, why not using a loop?
 
Ahmad Zuhairdi Noh:
Hmmm, why not using a loop?

Do you mean a loop for incremental construction of the string? Yes, that is what I do now.

If you know your limitations you can overcome them :-)

Matthias