Very BIZZARE and ILLOGICAL Array behavior... need help!!! - page 2

 
WHRoeder:

datetime and int are equivalent (syntax only,) double is not. Mql4 is a 32 bit application. Ints are 32 bits. If doubles are also 32 bits (normally called float) the total digits it can store is 7 decimal digits

1000000000 = Sun, 09 Sep 2001 01:46:40 GMT and 1000001000=Sun, 09 Sep 2001 02:03:20 GMT The accuracy of your timestamps is about 17 minutes. Periods smaller than that will compare equal.


Noooooo. You are way off here. Doubles are true doubles (8 bytes) - see help files. We also know they are about 15 (?) digits because of all the other threads on them failing to represent numbers correctly.

Furthermore MarketInfo only returns type double and can be asked for time info so it clearly all works, it's just really sucky from a data type point of view.

 
nanquan:

In what way is my method 'computationally gruesome' ? My logic was that the 'TickData' array is ever changing and constantly updates with every new tick. As a result it's impossible to define in advance how big it will be, and so I implemented this method to dynamically increment it's size by 1 with every new tick. Is there a downside to doing it like this? Do you have a better suggestion?

Is there a problem with doing it this way? As I understood it datetime is basically an integer 10 digits long. So if you type cast it to int or double type values, it would still retain the same value for any comparison calculations you wish to do.

Example:

The reason I save datetime value as a double is because I wanted to have one Array containing all the values which are important to me, instead of having to split different data types over several different arrays, and then juggling between them when doing any sort of calculations. The end result is the same, and my way is simpler. Unless I'm missing something and there are downsides to doing it this way?


Thanks Again!!!

nanquan

>Is there a problem with doing it this way? As I understood it datetime is basically an integer 10 digits long. So if you type cast it to int or double type values, it would still retain the same value for any comparison calculations you wish to do.

It is just poor programming practice to swap data types around like that. Most compilers would complain (to keep you from problems) but MQL4 is not type safe and just does the best it can.

>In what way is my method 'computationally gruesome' ? My logic was that the 'TickData' array is ever changing and constantly updates with every new tick. As a result it's impossible to define in advance how big it will be, and so I implemented this method to dynamically increment it's size by 1 with every new tick. Is there a downside to doing it like this? Do you have a better suggestion?

This is not an insult to your code, it is just "under the hood" the software has to do a lot of work. If you were doing this in C you do not have an ArrayResize facility. What you would have to do is on every ArrayResize you would have to create a new larger memory block, copy the old data to the new area, then delete the old memory block. Now the MQL4 programmers are not dummies and they probably have all sorts of tricks to give you what you ask for more efficiently. For example they could allocate 100 positions when you ask for 1. Then the next 100 times you ask to increment the size by 1 they wouldn't have to do much work. It is a bit gruesome "under the hood" but the code itself looks fine, and if you have the resources to do it (RAM/CPU) then it is not a problem.

Personally I would use 4 single variable arrays. That way you have a sensible name for each position, eg TickBid[], TickAsk[], TickTime[]. you can also use a datetime array for TickTime so things match up nicely. But if you find it easier/simpler the other way then, hey, it's your code :-)

Of course in the real world of C a structure (struct) would be used, but MQL4 doesn't support structs.

 
dabbler:

[...] Now the MQL4 programmers are not dummies and they probably have all sorts of tricks to give you what you ask for more efficiently. [...]

( I would have guessed that MT4 allocates arrays in granular blocks, and that ArrayResize(x, ArraySize(x) + 1) doesn't necessarily cause an actual memory re-allocation. But that appears to be wrong. Each call to ArrayResize() changes the address of an array, suggesting that MT4 is allocating a new block of memory in order to accommodate the resize. However, it's also possible that the resize merely causes things to be moved around within a pre-allocated heap, which would be more computationally trivial than repeatedly asking Windows for more memory. )
 

I understand your points, dabbler. For the record, I was not at all insulted by any of your comments. My questions stem from a genuine desire to learn and improve, as I am still relatively new to programming in MQL4 :) I am definitely open to constructive criticism, and that's exactly what you provided, so thank you!

I will probably be implementing some of your suggestions in my code, including splitting up the array, as that would me more convenient now that I think about it!

You also put me on the right track to troubleshooting my code, so again it is much appreciated!!!

I also figured out that the conditional:

if (TickData[i][0]==time) {found = true; break;}

is not really practical, as there could be more than one entry with the same timestamp value in the array (i.e. several price changes in under 1 second).

So you actually need the last entry in the series of identical timestamp values, and not the first one you encounter!

Thank you once again! :)

nanquan

 
nanquan:

You also put me on the right track to troubleshooting my code, so again it is much appreciated!!!

 
I just managed to resolve all the problems! I'm so happy! :D
 
dabbler:

Noooooo. You are way off here. Doubles are true doubles (8 bytes) - see help files. We also know they are about 15 (?) digits because of all the other threads on them failing to represent numbers correctly.

Furthermore MarketInfo only returns type double and can be asked for time info so it clearly all works, it's just really sucky from a data type point of view.

Writing before coffee (BC). I didn't see the actual size mentioned in the docs but I should have known that from the Can price != price ? discussion.
 
dabbler: :)
Thats one happy-a$$ sunny-boy. Reminds me... I need to step away from this Pc and go bathe in the Sun. Happy Pip-ing yall.
Reason: