Hi guys, I don't seem to be comfortable with the warning "Possible loss of data due to type conversion". See the code below:
I understand that global variables return values of type double. But what I sent as global variable is integer value and that is what I want to get back, hence the "int PriceLeftShift".
int PriceLeftShift = (int) GlobalVariableGet(StringConcatenate("LineVert ",Symbol()," ",ChartPeriod()));
you can try this
you can try this
Wow, it worked like magic! But where on earth did you get that concept from bro? I doubt if it is in the Documentation. Thanks a lot.
https://www.mql5.com/en/docs/basis/types/casting
Typecasting of Numeric Types
In the expressions of the MQL5 language both explicit and implicit typecasting can be used. The explicit typecasting is written as follows:
var_1 = (type)var_2; |
An expression or function execution result can be used as the var_2 variable. The function style notation of the explicit typecasting is also possible:
var_1 = type(var_2); |
Let's consider an explicit typecasting on the basis of the first example.
//--- Third example |
Before the division operation is performed, the c1 variable is explicitly cast to the double type. Now the integer constant 2 is cast to the value 2.0 of the double type, because as a result of converting the first operand has taken the double type. In fact, the explicit typecasting is a unary operation.
Besides, when trying to cast types, the result may go beyond the permissible range. In this case, the truncation occurs. For example:
char c; |
Before operations (except for the assignment ones) are performed, the data are converted into the maximum priority type. Before assignment operations are performed, the data are cast into the target type.
Examples:....................................................
- www.mql5.com
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi guys, I don't seem to be comfortable with the warning "Possible loss of data due to type conversion". See the code below:
I understand that global variables return values of type double. But what I sent as global variable is integer value and that is what I want to get back, hence the "int PriceLeftShift". Or is there any way I can convert double to integer value for peace to reign.