Warning "implicit conversion from number to string"

 

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:
 

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) + ")");






 
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.
 
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
 
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. 

 

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) + ")");


 
Thanks for expanding on this Marco. I have a huge task in front of me to learn C++.
 

Or you could type-cast:

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

Or you could type-cast:

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

implicit conversion from 'number' to 'strig'

what i have to type?

void myAlert(string type, string message)

  {

   if(type == "print")

      Print(message);

   else if(type == "error")

     {

      Print(type+" | KWM OSIA @ "+Symbol()+","+Period()+" | "+message);

     }

Reason: