Download MetaTrader 5

Typecasting Question

To add comments, please log in or register

Hi there

 This question might sound foolish - my apologies! 

I have 3 types of params in my EA: int, bool and double. I'm backing everything up during runtime in a csv file, using an array of type double. 

This is how  I'm doing the backing up: saving all the params in the array and then storing the array in the csv file...

When I save the INT or BOOL params in the array I'm typecasting it: array[0] = (int) param1;   array[1] = (bool) param2; 

 My question is: when I'm loading the data from the file (let's say if the system crashed and started over again) back to the array and then back to the params, should I do some sort of typecasting as well?

 for example: param1 = array[0]; param2 = array[1];

or:  param1 = (int) array[0];  param2 = (bool) array[1];




Each of your parameters is a specific type of unit.  Int is obviously integers (whole numbers only), double is (if my programming knowledge and/or memory is serving me correctly) is used for what is called floating point or decimal numbers, and bool is short for boolean, which is basically a true/false possibility.  Since you are using an array of double, at best, you would be able to store the double and the int within the array, the boolean will most likely give your program fits.  Since you are forcing it on saving it to fit in the typed double array, most likely, your code will see it, by default, as doubles, so forcing it back would work as well.  I am 99% sure you would have to re-type them back to their original values, but it seems like making more work doing it this way.  

The type explanations are for those people who might be reading the thread and not know this, so they can catch up a little easier.

Another possibility you could try, and I am not sure how MQL handles it, is make them all strings and send them to the array that way, but it is basically the same thing you are doing now except with strings instead of a typed double array.

From my small amount of experience in programming in Java, it seems that there logically has to be an easier way to do this, but again, IDK MQL at all.

To add comments, please log in or register