implicit conversion from number to string

Post Reply
User avatar
traderduke
Trader
Posts: 306
Joined: Mon Nov 28, 2011 7:30 pm
Location: East Coast USA

implicit conversion from number to string

Post by traderduke »

coders
When I changed line 16 to line 18 I got this warning, it affects the back ground coloring. I 've triedthe str string function on line 17 but I can't seem to get the syntax correct.

Any help would be appreciated
Ray

String Number to string.docx
You do not have the required permissions to view the files attached to this post.
User avatar
simplex
Trader
Posts: 127
Joined: Thu Feb 07, 2013 5:21 pm
Location: An insignificant small town close to an insignificant former capital at the Rhine River.

implicit conversion from number to string

Post by simplex »

In your new macro version you concatenate several strings and numbers to a new string.

Issue 1 - syntactical: missing explicit conversion of numbers - see IntegerToString and DoubleToString in the mq4 reference manual for details.

Issue 2 - methodical: macro version is obviously intended to hold a version name - a constant inside your project. By adding input parameters you turn the constant into a variable. It would be better to add parameter information directly to variable shortname. Later code maintenance should be easier then.
If you can't explain it simply, you don't understand it well enough. (Albert Einstein)
It appears that the Weighted Moving Average was invented by a trader who did not have a firm grasp of filter theory in hopes of reducing lag. (John F. Ehlers)
User avatar
renexxxx
Trader
Posts: 860
Joined: Sat Dec 31, 2011 3:48 am

implicit conversion from number to string

Post by renexxxx »

The MQL4 compiler is warning you that it needs to convert an integer to a string, in order to concatenate the expression into a longer string in:

Code: Select all

shortName=indicatorName+""+version+" - id"+almostUniqueIndex;
here, version is an integer, that is implicitly converted to a string.

Your options are:

1.

Code: Select all

shortName=indicatorName+(string)version+" - id"+almostUniqueIndex;
In here, version is explicitly converted to a string.

2,

Code: Select all

shortName=StringConcatenate(indicatorName, version, " - id", almostUniqueIndex);
as StringConcatenate takes arguments of any type.

3.

Code: Select all

shortName=StringFormat("%s%d - id%s", indicatorName, version, almostUniqueIndex);
In here, the first %s is replaced with the string indicatorName, %d is replaced with the integer version and the second %s is replaced with the string almostUniqueIndex.

You can also use the function IntegerToString, as Simplex suggested, to convert the integer to a string.

R.
User avatar
traderduke
Trader
Posts: 306
Joined: Mon Nov 28, 2011 7:30 pm
Location: East Coast USA

implicit conversion from number to string

Post by traderduke »

Thanks fellows for the help! Using the shortName for all info with "StringConcantenate" seems to be my best option since I'm always mixing apples & oranges.

Thanks Again
Ray
Post Reply

Return to “Coders Hangout”