Add spread value to comment

 

Hi everyone


I am currently testing the results of an EA and would like to know the spread with which it opens each operation, so I have the idea of adding that data to the comment when opening the operation: "Name of my EA" + "spread".

The way I'm doing it is:

extern string co = "My custom EA ";   //EA Comment:
string     com = co + "(Spread: " + (MarketInfo(Symbol(),MODE_SPREAD)) + ")";

However when compiling it shows me the error: "implicit conversion from 'number' to 'string'.

How should I do that?

What is the correct way to do it?

 

Sure you cannot add number to string... you should convert it first to string

like this:

extern string co = "My custom EA ";   //EA Comment:
string     com = co + "(Spread: " + IntegerToString( ( int) MarketInfo( Symbol(), MODE_SPREAD)) + ")";
 
Thanks very much!!!
 

You might also want to try format strings. They make your code a lot easier to read and write. Here's an example: 


   string ea_name = "My EA";
   string comment = StringFormat("%s (Spread: %d)",
      ea_name, int(MarketInfo(_Symbol, MODE_SPREAD))
   );
Reason: