Expert Advisors • Indicators • Scripts • Libraries

MQL.RobotFX.org is the biggest collection of MetaTrader expert advisors (MT5 & MT4), indicators, scripts and libraries that can be used to improve trading results, minimize risks or simply automate trading tasks

MetaTrader 5 Libraries | Comment

A simple replacement for a comment. Works in the tester 50 times faster than the standard function.

It is known that the standard "Comment" function slows down the tester very much.

Here is an example of code and its execution time in the tester.

void OnTick()    {     MqlTick tick;     SymbolInfoTick(_Symbol, tick);     if(tick.ask != 0 && tick.bid != 0)       {        string str = StringFormat("ask  = %.5f\nbid  = %.5f\ntime = %s", tick.ask, tick.bid, TimeToString(tick.time, TIME_DATE | TIME_SECONDS));        Comment(str);       }    }  //+------------------------------------------------------------------+

MetaTrader Experts, Indicators, Scripts and Libraries

11 minutes 28 seconds  !!!

MetaTrader Experts, Indicators, Scripts and Libraries

Just add the code  #include <Comm.mqh>

#include <Comm.mqh>  //+------------------------------------------------------------------+  void OnTick()    {     MqlTick tick;     SymbolInfoTick(_Symbol, tick);     if(tick.ask != 0 && tick.bid != 0)       {        string str = StringFormat("ask  = %.5f\nbid  = %.5f\ntime = %s", tick.ask, tick.bid, TimeToString(tick.time, TIME_DATE | TIME_SECONDS));        Comment(str);       }    }  //+------------------------------------------------------------------+

MetaTrader Experts, Indicators, Scripts and Libraries

14  seconds !!!  

14 seconds instead of 11 minutes 28 seconds

11*60+28=688,    688/14=49,   49 times faster!!!


MetaTrader Experts, Indicators, Scripts and Libraries

Example of usage with default settings.

No need to declare an instance of the class.

#include <Comm.mqh>  //+------------------------------------------------------------------+  void OnTick()    {     string str = "PROGRAM_NAME = " + MQLInfoString(MQL_PROGRAM_NAME) + "\n" + (string)TimeCurrent();     Comment(str);    }  //+------------------------------------------------------------------+

MetaTrader Experts, Indicators, Scripts and Libraries

Example of use with the ability to change settings.

#include <Comm.mqh>  //+------------------------------------------------------------------+  void OnTick()    {     string str = "PROGRAM_NAME = " + MQLInfoString(MQL_PROGRAM_NAME) + "\n" + (string)TimeCurrent();     Comment(str, _Xpx, _Ypx, _clrText, _FontSize, _clrBack, _Transparency, _Font, _corner);    }  //+------------------------------------------------------------------+

MetaTrader Experts, Indicators, Scripts and Libraries

Example of using multiple instances of a comment.

#include <Comm.mqh>  CComm comm1;  CComm comm2;  CComm comm3;  CComm comm4;  //+------------------------------------------------------------------+  void OnTick()    {     MqlTick tick;     SymbolInfoTick(_Symbol, tick);     if(tick.ask != 0 && tick.bid != 0)       {        string str = StringFormat("ask  = %.5f\nbid  = %.5f\ntime = %s", tick.ask, tick.bid, TimeToString(tick.time, TIME_DATE | TIME_SECONDS));        Comment(str);        comm1.Comm(str, _Xpx, _Ypx + 80, _clrText, _FontSize, _clrBack, _Transparency, _Font, _corner);        comm2.Comm(str, _Xpx + 10, _Ypx + 20, _clrText, _FontSize, clrGreen, _Transparency, _Font, CORNER_LEFT_LOWER);        comm3.Comm(str, _Xpx + 30, _Ypx, clrGreen, _FontSize, _clrBack, _Transparency, _Font, CORNER_RIGHT_LOWER);        comm4.Comm(str, _Xpx, _Ypx + 50, clrBlack, _FontSize, _clrBack, _Transparency, _Font, CORNER_RIGHT_UPPER);       }    }  //+------------------------------------------------------------------+

MetaTrader Experts, Indicators, Scripts and Libraries

update 05.12.2024   version   1.06

update 05.12.2024   version   1.07

53499