Download MetaTrader 5

Warning "implicit conversion from number to string"

To add comments, please log in or register
Mark Falzon
140
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 

Files:
Drazen Penic
2740
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:

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






Mark Falzon
140
Mark Falzon  
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
23225
Alexander Voronkov  
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  
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
5804
Marco vd Heijden  

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  
Thanks for expanding on this Marco. I have a huge task in front of me to learn C++.
data46
27
data46  

Or you could type-cast:

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

Or you could type-cast:

Thanks data46. So many options.
JD4
1100
JD4  
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