graziani: Raptor showed a correct way to use it. Check the documentation.
datetime a = Time[index];
I don't think he did. The original question was:
bushTrader: "string name" + Time[index] ... instead of Time[index] giving the number of seconds, it gives the time in a text. I need the number of seconds like in build 509.
Functions Time()/iTime() return type datetime. So the only proper way of using these functions is
datetime a = Time[index];
Further, to print it out you can use
Print((string)a); // now
Print(TimeToString(a,...)); //now & before
This is the only correct way, otherwise you can expect undefined behaviour in case of library/compiler change.
BUT, knowing that internal representation of this datatype is time elapsed in seconds since 1970 stored in 8 bytes long unsigned integer type, and that ulong type is 8 bytes long, you can trick it:
ulong ul = (ulong)a;
Print((string)ul);
Print((string)(ulong)a);
Unfortunately, to be sure that your program will always run, you are not allowed to do this. User should ONLY use functions defined for manipulating of datetime type.
So, where is the problem? Traders are not programmers. They are not interested in structured or OO programming. They just want to use the simplest way to define behaviour of an EA. Forcing strict C rules on some C like language like mql4 NOW is stupid. Also i am not sure that forcing C++ rules (MQL5 in MT5) will result any better. Although the EA generator in MT5 doesn't look bad, IMO it is too complicated for an average trader. Basic (language) or something alike, would be the most appropriate language in this sense.
And what now? I don't see a good way nor simple way: the simplest solution is to learn proper C programming. Which is far more easier than C++.
Do it properly, use the correct variable type . . .
try to Print() it & c the difference
Raptor showed a correct way to use it. Check the documentation.
try to Print() it & c the difference
Like this . . .
datetime a = Time[index]; Print("Time[", index", "] in seconds since 1st Jan 1970 is ", (int)a);Do it properly, use the correct variable type . . .
OK, i see.
Functions Time()/iTime() return type datetime. So the only proper way of using these functions is
Further, to print it out you can use
This is the only correct way, otherwise you can expect undefined behaviour in case of library/compiler change.
BUT, knowing that internal representation of this datatype is time elapsed in seconds since 1970 stored in 8 bytes long unsigned integer type, and that ulong type is 8 bytes long, you can trick it:
Unfortunately, to be sure that your program will always run, you are not allowed to do this. User should ONLY use functions defined for manipulating of datetime type.
So, where is the problem?
Traders are not programmers. They are not interested in structured or OO programming. They just want to use the simplest way to define behaviour of an EA.
Forcing strict C rules on some C like language like mql4 NOW is stupid.
Also i am not sure that forcing C++ rules (MQL5 in MT5) will result any better. Although the EA generator in MT5 doesn't look bad, IMO it is too complicated for an average trader.
Basic (language) or something alike, would be the most appropriate language in this sense.
And what now?
I don't see a good way nor simple way: the simplest solution is to learn proper C programming. Which is far more easier than C++.
Like this . . .
datetime a = Time[index]; Print("Time[", index", "] in seconds since 1st Jan 1970 is ", (int)a);Thanks, after removing the double quote after index, I succeeded with this.
datetime a = Time[index]; Print("Time[", index, "] in seconds since 1st Jan 1970 is ", (int)a);So, would the following be proper?
"string name" + (int)Time[index] //to name objects on my charts
or even this
StringConcatenate("string name",(int)Time[index])
Thanks, after removing the double quote after index, I succeeded with this.
So, would the following be proper?
"string name" + (int)Time[index] //to name objects on my charts
I think that would work . . . but might give a warning, maybe this is technically correct . . . even if it looks horrible.
using long or ulong instead of int doesn't giving a warning