Include data files into ex4 file

Back to topics list To post a new topic, please log in or register
avatar
8
nojiko70-4 2016.08.20 10:35
 

Hi!

I have an indicator (and a EA) which reads a relatively large set of data from an external *.txt file in the "\MetaTrader 4\MQL4\Files" directory using FileOpen. Everything is working correctly, but I would like to ask if there is the possibility to include this set of data into the ex4 produced after compiling. In other words, instead of having an ex4 file and a txt file, having a single ex4 file with all the data packed in it. I searched extensively on the forum, but found nothing of this sort (and nobody asking for it). Yet, I find it odd that this kind of operation is not needed/implemented.

Thanks a lot in advance!

Nj

avatar
108
eddie 2016.08.20 11:30 #
 

You didn't find somthing in this forum, because it belongs to the basics of the programming language.

You only have to assign the data to arrays and structs at initialization time.

But to include the data, it anly makes sense, if you sell the EA and do not want to show the data to your customers.


avatar
8
nojiko70-4 2016.08.20 15:05 #
 
eddie:

You didn't find somthing in this forum, because it belongs to the basics of the programming language.

You only have to assign the data to arrays and structs at initialization time.

But to include the data, it anly makes sense, if you sell the EA and do not want to show the data to your customers.


Thanks for the reply!

> You only have to assign the data to arrays and structs at initialization time.

This is what I am doing, but I'm getting the data from external file, because it amounts to several thousands of strings/numbers.

So the question finally is: can I include these data while avoiding to write by hand in the EA code something like:

structarrayname[0].param1=132;

structarrayname[0].param2=432;

structarrayname[0].param3=390;

...

structarrayname[1500].param1=480;

structarrayname[1500].param2=573;

structarrayname[1500].param3=198;

....

?

I could write a small app in C# to create that code automatically and then paste it into the EA code, but it seems a bit odd to me that there is no better way to deal with this issue...

> But to include the data, it anly makes sense, if you sell the EA and do not want to show the data to your customers.

Yes, this is exactly the reason I want to do that... :)


Thanks,

Nj




avatar
12984
WHRoeder 2016.08.20 15:25 #
 
learn to code it, or pay someone. We're not going to code it FOR you.
We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem.
static string HiddenFile[] = {
   "line1",
   "line2"
   :
};
for(int i = 0; i <= ArraySize(HiddenFile); ++i)
   DoSomething(HiddenFile[i]);

avatar
8
nojiko70-4 2016.08.20 17:55 #
 

I didn't ask by any means to code anything, just to be pointed to the right direction.

If the thing I'm asking for is so customarily done, please give me some references that can be found on "Forum" or on "Book", because, no matter how "basic" that is, should be covered somewhere, shouldn't it? Thank you.

Nj


avatar
1197
FMIC 2016.08.20 18:20 #
 
nojiko70-4:

I didn't ask by any means to code anything, just to be pointed to the right direction. If the thing I'm asking for is so customarily done, please give me some references that can be found on "Forum" or on "Book", because, no matter how "basic" that is, should be covered somewhere, shouldn't it? Thank you.

WHRoeder, just gave you an example solution, yet you were so busy "defending" your position that you blindly ignored his example code! Since you seem to be using numbers instead of strings, here it is again in a format you might better recognise:

static int HiddenFile[] = { 132, 432, 390, ... 480, 573, 198 };
for(int i = 0; i <= ArraySize(HiddenFile); ++i)
   DoSomething(HiddenFile[i]);

Obviously, it does not have to be a 1 dimensional array, it can be multidimensional or what ever suits your needs. This however is nothing new and it is a basic coding skill from back in the days of early computers when all data was stored in programs in this way and no external files were used (e.g. BASIC programming language with its DATA and READ statements). Hence why eddie stated and I quote: "You didn't find something in this forum, because it belongs to the basics of the programming language."

And because it is "basic" coding skill, it is not in the scope of this forum and it is up to you, to do your due diligence and learn the basics of coding in which ever way you see fit, be it online on some website or other forum, by means of a teacher or tutor or by reading books. That is up to you, and since there are so many references, it is not up to us to remember exactly where to find it. So, "let your fingers do the walking" and carry out a few Google/Bing/whatever searches.

PS! If you really want to get creative but complicated, you can always use "Resources" that can be included in an ".ex4" files. In, in this case, provided your data is "integer" data only, you can create an "image" resource and use the "ResourceReadImage()" function to access the data of the included resource inside the ".ex4" file.

avatar
8
nojiko70-4 2016.08.20 19:39 #
 
FMIC:

WHRoeder, just gave you an example solution, yet you were so busy "defending" your position that you blindly ignored his example code! Since you seem to be using numbers instead of strings, here it is again in a format you might better recognise.

I DID read the code, but it didn't answer my question: it basically just gave a more elegant way to include the data manually into the code, compared to what I already described before. I'm programming since the C64 era, and this, as you pointed out, is like the READ/DATA way to proceed of those times... What I intended, however, was something different, like getting an external file of large data in form, for example, of an csv file, embedded into the ex4 at the moment of compiling. Probably your proposal of using "Resources" is the one that more get close to what I imagined (I will investigate this, thanks for suggesting it), but, given your premises, it seems it is not the usual or more elegant way to proceed.

avatar
1197
FMIC 2016.08.20 20:56 #
 
nojiko70-4:

I DID read the code, but it didn't answer my question: it basically just gave a more elegant way to include the data manually into the code, compared to what I already described before. I'm programming since the C64 era, and this, as you pointed out, is like the READ/DATA way to proceed of those times... What I intended, however, was something different, like getting an external file of large data in form, for example, of an csv file, embedded into the ex4 at the moment of compiling. Probably your proposal of using "Resources" is the one that more get close to what I imagined (I will investigate this, thanks for suggesting it), but, given your premises, it seems it is not the usual or more elegant way to proceed.

If you want to include CSV data in a ".ex4", then just do it. It is a "string" after all and as easy as this:

string CSVData =
   "Open,High,Low,Close\n"
   "1.234,1.235,1.123,1.231\n"
   "1.232,1.239,1.229,1.230\n";

Now you can process it with the function StringSplit() or however you see fit! You can even shorten it (removing headers and using ";" for a record separator) as such:

string CSVData = "1.234,1.235,1.123,1.231;1.232,1.239,1.229,1.230;1.229,1.232,1.219,1.221";

Obviously, if you want to be memory and processing efficient, just use the original array idea already proposed here, as such:

double CSVData[][4] = {
   { 1.234, 1.235, 1.123, 1.231 },
   { 1.232, 1.239, 1.229, 1.230 },
   { 1.229, 1.232, 1.219, 1.221 }
   };

EDIT: PS! By the way, you can also define the "string" or "array" data in an external header file (".mqh") and then "#include" it, in order to prevent cluttering up your main code file.

avatar
12984
WHRoeder 2016.08.20 22:02 #
 
nojiko70-4: What I intended, however, was something different, like getting an external file of large data in form, for example, of an csv file, embedded into the ex4 at the moment of compiling.
Which is what I gave you.

avatar
8
nojiko70-4 2016.08.27 11:47 #
 
FMIC:

EDIT: PS! By the way, you can also define the "string" or "array" data in an external header file (".mqh") and then "#include" it, in order to prevent cluttering up your main code file.

Cluttering up the main code was exactly what I wanted to avoid; hence the desire to leave the data to be included on an external file. I think that what you propose here is the ideal solution in mql4. Thank you!
Back to topics list  

To add comments, please log in or register