Impact of email message format on processing speed

 

Hi all - Happy New Year!

I'm wondering what the best practice would be when adding the following content to an indicator for an email alert.  My concern is related to processing speed as I will have about 20 charts running, each loaded with multiple indicators that will be sending email alerts. Is it best to keep the code to a single line, or can I use multiple lines with no concerning impact. Thanks in advance for any help you can offer.

Single line:

string bodytext_sell = "Conditions are in place for a Sell on the \n \n+ Instrument  = " + StringConcatenate (Symbol(), " \n+ Price Level = " +  DoubleToStr(Bid ,Digits) + " \n+ Timeframe  = " + TFToStr(Period()) + " \n+ Alert Time   = " + TimeToStr(TimeCurrent(),TIME_DATE));

Multiple lines:

 string bodytext_sell = "Conditions are in place for a Sell on the \n \n
+ Instrument  = " + StringConcatenate (Symbol(), " \n
+ Price Level = " +  DoubleToStr(Bid ,Digits) + " \n
+ Timeframe  = " + TFToStr(Period()) + " \n
+ Alert Time   = " + TimeToStr(TimeCurrent(),TIME_DATE));


Regards,
Patrick

 
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. There is no difference. White space and new lines only affect the compiler.
    Are your books one column but two feet wide? No because that is unreadable. They are 6 inches, sometimes two columns, so you can read it easily. So should be your code. I'm not going to go scrolling (or moving my eyes) back and forth trying to read it.
 
whroeder1:
  1. When you post code please use the SRC button! Please edit your post.
              General rules and best pratices of the Forum. - General - MQL5 programming forum

  2. There is no difference. White space and new lines only affect the compiler.

Hi whroeder1,

Code re-posted correctly. Thanks for your fast response.

I hope you don't mind a follow-up question: In the case of the code I have posted, what is the best operation symbol for separating the different parts of the code?

This is code that I've found and I'm repurposing it. A you can see, both the plus sign (+) and comma (,) are both used. I've experimented with interchanging them and there's no effect when I compile the indicator, so I'm not worried about that. But, again, I'm wondering if one or the other (plus sign or comma) would be a better choice for performance.

Kind regards,
Patrick

 
Patrick Allossery:
I'm wondering if one or the other (plus sign or comma) would be a better choice for performance.

I haven't looked into performance comparisons.

In my opinion, StringFormat() makes code more readable. I rarely use + or StringConcatenate().

For example:

Print(StringFormat("%s: enable [%d] value [%d] start [%d] step [%d] stop [%d]", parameterName, enable, value, start, step, stop));

As for performance, this thread discusses this:

https://www.mql5.com/en/forum/139923

Does StringConcatenate speed up string concatenation?
Does StringConcatenate speed up string concatenation?
  • 2012.06.11
  • www.mql5.com
I personally had never used StringConcatenate because it would have made my code less readable and probably wouldn't have save much time anyway...
 
Anthony Garot:

I haven't looked into performance comparisons.

In my opinion, StringFormat() makes code more readable. I rarely use + or StringConcatenate().

For example:

As for performance, this thread discusses this:

https://www.mql5.com/en/forum/139923


Hi whroeder1 and Anthony,

I'm definitely having performance problems. With 20 charts and multiple indicators on each, my platform crashes before it fully loads. I've tried to clean up the code and I've reduced its length it by removing one of the parameters, but the problem still exists. Here's what I've arrived at:

string bodytext_buy = "Conditions are in place for a potential BUY. \n\n + Instrument  = " + StringConcatenate (Symbol(), " \n + Price Level = " ,  DoubleToStr(Bid,Digits), " \n + Alert Time   = " , TimeToStr(TimeCurrent(),TIME_DATE));
  

Anthony, I've tried to follow your suggestion of rewriting the code using StringFormat, and I've been reading the documentation on it, but I confess I don't really understand it. Would you be able to provide me with bit more direction or point me to some example code similar to what I'm trying to write?

Any help would be much appreciated.

Kind regards,
Patrick

 
Patrick Allossery:

Hi whroeder1 and Anthony,

I'm definitely having performance problems. With 20 charts and multiple indicators on each, my platform crashes before it fully loads. I've tried to clean up the code and I've reduced its length it by removing one of the parameters, but the problem still exists. Here's what I've arrived at:

Anthony, I've tried to follow your suggestion of rewriting the code using StringFormat, and I've been reading the documentation on it, but I confess I don't really understand it. Would you be able to provide me with bit more direction or point me to some example code similar to what I'm trying to write?

Any help would be much appreciated.

Kind regards,
Patrick


Also, I should add that I'm looking for the most computationally efficient code for email alerts, with the parameters of symbol, price and time (as in my most recent example above). The most efficient approach may be to use StringFormat, or it could be something else. I'm hoping someone here could provide me with guidance on this point.

For reference, when I started out, I tried incorporating HTML into my alerts. This allowed me to create emails with some design features, but it bogged my platform down terribly. Now, I've moved away from that and I want the code to be as efficient as possible.

Kind regards,
Patrick

 

Efficiency is irrelevant, you can only send a few emails. IIRC 2 per second 10 per minute.

If the platform is crashing, fix that!

 
Anthony Garot:

As for performance, this thread discusses this:

https://www.mql5.com/en/forum/139923

(Not really relevant to the main point of discussion in this thread, but... that discussion of StringConcatenate() is out-dated. There have been subsequent additions to the MQL4 language which affect the answer. Specifically, StringAdd() should now be the fastest way of doing repeated or large concatenations to a string.)
 

It's always fun analyzing the efficiency of code but in reality the time difference between string functions are mere microseconds, and if even it were 1000x difference it still wouldn't matter because this is not an HFT platform and 1ms won't make a difference let alone a few microseconds...

 
Patrick Allossery:
Anthony, I've tried to follow your suggestion of rewriting the code using StringFormat, and I've been reading the documentation on it, but I confess I don't really understand it. Would you be able to provide me with bit more direction or point me to some example code similar to what I'm trying to write?

For your example, something like this:

string bodytext_buy = StringFormat( "Conditions are in place for a potential BUY.\n\nInstrument = %s\nPrice Level = $.5f\n Alert Time = %s", 
                                    Symbol(), 
                                    Bid, 
                                    TimeToStr(TimeCurrent(),TIME_DATE));
 
nicholishen:

It's always fun analyzing the efficiency of code but in reality the time difference between string functions are mere microseconds, and if even it were 1000x difference it still wouldn't matter because this is not an HFT platform and 1ms won't make a difference let alone a few microseconds...

Yes.

Chasing down efficiencies in string functions makes for a good Stack Overflow post—for edification reasons—and for purists.

But as for practical use in a MetaTrader EA, string functions are likely not your bottleneck.



Reason: