Download MetaTrader 5

Warning "implicit conversion from number to string"

To add comments, please log in or register
Do you want to deposit to your account? Do this in any convenient way!
Mark Falzon
140
Mark Falzon 2015.06.09 12:37 

Hi MQL4 forum.

I'v just started learning very simple MQL4 code and have converted a pre 2014 file to the current format. I've managed to work out all errors/warnings except "implicit conversion from 'number' to 'string' on Line 45 Market Hour GMT. Can someone please advise me what needs to be changed?

Mark 

Files:
Drazen Penic
2539
Drazen Penic 2015.06.09 13:48  

Compiler warns you that you are adding numbers and strings and that potentially there could be an error.

You need to explicitly tell compiler that you want  strings to be concatenated - convert integer to string:

IndicatorShortName("Mark Hour GMT("+ IntegerToString(MarkHourGMT) + ")");






Mark Falzon
140
Mark Falzon 2015.06.09 14:26  
Drazen Penic:

Compiler warns you that you are adding numbers and strings and that potentially there could be an error.

You need to explicitly tell compiler that you want  strings to be concatenated - convert integer to string:






Excellent. Thank you very much Drazen.
Alexander Voronkov
18868
Alexander Voronkov 2015.06.09 15:41  
Mark Falzon:

Hi MQL4 forum.

I'v just started learning very simple MQL4 code and have converted a pre 2014 file to the current format. I've managed to work out all errors/warnings except "implicit conversion from 'number' to 'string' on Line 45 Market Hour GMT. Can someone please advise me what needs to be changed?

Mark 

Use StringConcatenate to avoid warnings.

IndicatorShortName( StringConcatenate( "Mark Hour GMT(", MarkHourGMT, ")" ));
StringConcatenate - MQL4 Documentation
  • docs.mql4.com
StringConcatenate - MQL4 Documentation
Mark Falzon
140
Mark Falzon 2015.06.10 05:21  
Alexander Voronkov:

Use StringConcatenate to avoid warnings.

Thanks Alexander.

 So either of these two options work in my example. Would the function IntegerToString only work in specific instances where you start off with an integer but Concatenate would work with doubles, integers, etc.?


Mark. 

Marco vd Heijden
Moderator
4684
Marco vd Heijden 2015.06.10 11:54  

It's a warning not an error.

When you convert a double to integer it will warn you about the data loss since integer can only be a whole number and it will simply cut off the numbers after the . so for example double 10.34 simply becomes 10 when converted to integer.

For double you use:

DoubleToString 


For datetime as i believe in your example:

TimeToString

it is all in the MQL4 reference

IndicatorShortName("Mark Hour GMT("+ TimeToString(MarkHourGMT) + ")");

Then TimeToString has also modes:

mode=TIME_DATE|TIME_MINUTES

[in] Additional data input mode. Can be one or combined flag:
TIME_DATE gets result as "yyyy.mm.dd",
TIME_MINUTES gets result as "hh:mm",

TIME_SECONDS gets results as "hh:mm:ss".

IndicatorShortName("Mark Hour GMT("+ TimeToString(MarkHourGMT,TIME_MINUTES) + ")");


Mark Falzon
140
Mark Falzon 2015.06.11 02:04  
Thanks for expanding on this Marco. I have a huge task in front of me to learn C++.
data46
27
data46 2015.06.13 07:22  

Or you could type-cast:

IndicatorShortName("Mark Hour GMT("+ (string)MarkHourGMT + ")");
Mark Falzon
140
Mark Falzon 2015.06.14 10:38  
data46:

Or you could type-cast:

Thanks data46. So many options.
JD4
1101
JD4 2015.07.21 01:29  
Mark Falzon:
Thanks for expanding on this Marco. I have a huge task in front of me to learn C++.
Once you get done learning C++, do not forget to learn MQL.  They are similar, but not the same language.
To add comments, please log in or register