StringAdd gives multiple pass of last string

 

Hi

I am trying to add the current spread to the comment for a buy / short event. The code is;

         double i_S1 = (Ask - Bid) * 10000;
         string i_S = DoubleToString(i_S1,1);
         StringAdd(comment,i_S);
         Print(comment);


comment shall of course be in the OrderSent, but are printed to find the failure. 

The code above give;

EA.1. Spread: 0.20.20.20.20.20.20.20.20.20.20.2

The correct print would be : 

EA.1. Spread: 0.2


comment are defined as a global variable ;

string comment = "EA.1. Spread: ";


Why are the 0.2 just repeating ? It will not repeat if I define the comment locally as;

         double i_S1 = (Ask - Bid) * 10000;
         string i_S = DoubleToString(i_S1,1);
         string comment = "EA.1. Spread: ";
         StringAdd(comment,i_S);
         Print(comment);
That code will print the correct values. 
 
Per Tobias Lindell:

Hi

I am trying to add the current spread to the comment for a buy / short event. The code is;


comment shall of course be in the OrderSent, but are printed to find the failure. 

The code above give;

EA.1. Spread: 0.20.20.20.20.20.20.20.20.20.20.2

The correct print would be : 

EA.1. Spread: 0.2


comment are defined as a global variable ;


Why are the 0.2 just repeating ? It will not repeat if I define the comment locally as;

That code will print the correct values. 
You dont reinstate the global string back to its original value, the more you StringAdd the spread, the more concatenation occurs..simple as that..in local the original value is restored upon function call is done
 

But of course.. Thanks for the suggestion, works now when I made some modifications.