- Possible loss of data due to type conversion.
- Discussion of article "Migrating from MQL4 to MQL5"
- From Double to Int. How to remove the warning : possible loss of data due to type conversion.
This happens when you try to convert between different datatypes the compiler is warning you that there can be dataloss.
Please try:
The function returns the value of the corresponding object property. The object property must be of the datetime, int, color, bool or char type. There are 2 variants of the function.
1. Immediately returns the property value.
long ObjectGetInteger(
long chart_id, // chart identifier
string name, // object name
ENUM_OBJECT_PROPERTY_INTEGER prop_id, // property identifier
int prop_modifier=0 // property modifier, if required
);
Someone please help. datetime time=ObjectGet("name",OBJPROP_TIME2); gives a warning - possible loss of data due to type conversion. Why is it so? Thanks in advance
The old MT4 function ObjectGet() returns a "double" datatype. However, when getting a different type of data, such as a "datetime", you must typecast it to prevent the warning. So, your code would have to be as follows (both formats are valid):
// either the "C" style
datetime time = (datetime) ObjectGet( "name", OBJPROP_TIME2 );
// or the function style
datetime time = datetime( ObjectGet( "name", OBJPROP_TIME2 ) );
Please note however, that ObjectGet() is an older MT4 function and you should instead use the more modern version ObjectGetInteger() (as mentioned by Marco vd Heijden in the previous post) which is also compatible with MQL5.
You will however, still need to typecast it for a datetime data type, even with the newer function!
- docs.mql4.com
Someone please help. datetime time=ObjectGet("name",OBJPROP_TIME2); gives a warning - possible loss of data due to type conversion. Why is it so? Thanks in advance
Thank you eevviill6. I'm now enlightened on that
The old MT4 function ObjectGet() returns a "double" datatype. However, when getting a different type of data, such as a "datetime", you must typecast it to prevent the warning. So, your code would have to be as follows (both formats are valid):
// either the "C" style
datetime time = (datetime) ObjectGet( "name", OBJPROP_TIME2 );
// or the function style
datetime time = datetime( ObjectGet( "name", OBJPROP_TIME2 ) );
Please note however, that ObjectGet() is an older MT4 function and you should instead use the more modern version ObjectGetInteger() (as mentioned by Marco vd Heijden in the previous post) which is also compatible with MQL5.
You will however, still need to typecast it for a datetime data type, even with the newer function!
merci
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use