creating comment on ordersend based on text and variable

 

Hi!


Does anyone know how to concatenate text for commenting when opening orders? I'm making a hedge EA and I'd like the comment to say "hedge PairNum()" where PairNum()is an integer. Please help. Below is the text I want to fix in blue..


OrderSend(Symbol(),OP_SELL,LotsOptimized(),Bid,3,0,0,"Hedge Pair :" & PairNum(),MAGICMA,0,Red)


Thank you!! =)

 

Hello heyarn

String building can be done via "+" concatenate operator or StringConcatenate() which is documented as being faster.

.

so, you could do:

"text"+PairNum()

or

StringContcatenate("text",PairNum())

.

Please notice the comma "," argument delimiter.

hth

 
fbj:

String building can be done via "+" concatenate operator or StringConcatenate() which is documented as being faster.

I've not tested this - and can't be bothered - but I'd be amazed if StringConcatenate() was anything more than microseconds faster on the sort of string lengths which are likely as order comments. Personally, I'd go for readability of code in this context, not a notional speed increase.


EDIT: I have now tested this, doing a concatenation of 10 strings of 100 bytes in length, and repeating 1,000 times. On these kinds of string-size, StringConcatenate() seems to be slower than standard concatenation using the + operator. A total of 0.041 seconds for the 1,000 StringConcatenate() iterations versus 0.035 for +. I'd imagine, based on experience with things like Javascript, that StringConcatenate() comes into its own when building significantly larger strings, with more concatenations. I'd still choose between them based on whichever you find more readable. (And, being pedantic, these timings include the time taken to do an API call to QueryPerformanceCounter).

 

just like .ru to make what your test demonstrates to be an untested/faulty documentation entry regards StringConcatenate().

I've been using it for many years, so I'm sticking with it but your test is, as usual, interesting...

 
fbj:

just like .ru to make what your test demonstrates to be an untested/faulty documentation entry regards StringConcatenate().

I've been using it for many years, so I'm sticking with it but your test is, as usual, interesting...

Yep, me too. Have always used StringConcatenate(). Not once have I used a +. Too many +'s in the code round here :-)


CB

 
cloudbreaker:

Yep, me too. Have always used StrginConcatenate().

I'm in the opposite position, probably because I come from a background of languages where there is no direct equivalent to StringConcatenate(), and concatenating strings in a fast way is therefore more cumbersome and requires a lot more premeditation.


BTW, fbj's remark prompted me to do some more timings using the example given in the documentation of StringConcatenate(). I'm seeing the commented-out "slow" version being about twice as fast as StringConcatenate() with these particular inputs (using static strings rather than the function calls in the documentation). But that's only the difference between about 1.3 and 2.6 microseconds per call - still a case where you pick whichever code you find most readable.

Reason: