How do I make the output on a chart in monospaced font? - page 3

 
Victor Ziborov:

At the stage of testing and optimising parameters the output to Comment and the output to Label can be disabled, but when it is time to use the EA in real life, the output to Comment and the output to Label should be enabled again.


thanks, cap )))))) we didn't know

 
Victor Ziborov:

At the stage of testing and optimising parameters, the output in the Comment and the output on the Label can be turned off, but when it is time to use the EA in real life, the output in the Comment, and the output on the Label should be turned back on.

In general, this is done automatically:

bool bIsComment = (!IsTesting() || IsVisualMode());

Then we check bIsComment in the code if the Comment is to be output or if any charting is to be performed. As a result, there is no need to switch anything manually.

 
Ihor Herasko:

This is done automatically:

Then we check bIsComment on the code when it is necessary to output Comment or make any graphical constructions. As a result, there is no need to switch anything manually.


Where it was said that you have to do it manually? Did I miss something?

 
Yury Kirillov:

Where did it say you have to do it manually? Did I miss something?


Responding to this post. It's basically ambiguous there. But somehow it seems more like "disable" and "enable" is a configuration parameter that is changed by the user depending on how the program is run. Just clarified that no such parameter is needed.

 
Artem Virskiy:

You can measure the width of each character in piskels (there will be several groups with the same width). Write a function that will append any string with spaces until it reaches a given width. Then assemble comment from these substrings.

If you make such function, post it in kodobase, many will thank you. And me too. I'm too lazy to bother myself.

In this case, symbol \x200A would be useful - minimum width of the space, for an exact fit. And replace regular spaces with symbol /1 - wide space (after all, the length of the comment is limited). Maybe there are other spaces useful, but I don't know them.


Thanks for the idea!

 
Yury Kirillov:
Comment is significantly faster than graphical fonts.

That's logical, but it's not.
And it's easy to check.
Here's a script on MQL5 (haven't tried it on MT4):

#property script_show_inputs
#include <Canvas\Canvas.mqh>

input uint   FontSize=12;                                   // размер шрифта
input ENUM_COLOR_FORMAT format=COLOR_FORMAT_ARGB_NORMALIZE; //Способ обработки цвета

void OnStart()
  {
   CCanvas Text;
   ulong ColorScreen=ChartGetInteger(0,CHART_COLOR_BACKGROUND,0);

   Text.FontSet("Arial",FontSize);
   string str="Соотношение времени выполнения Canvas/Comment = 0.00000";
   int H=Text.TextHeight(str);
   int W=Text.TextWidth(str);
   if(!Text.CreateBitmapLabel(0,0,"FONT",2,130,W,H,format)) Print("Error creating canvas: ",GetLastError());

   ulong t1=1,t2=1,t0;
   int i=0;
   color clr=(color)ARGB(255,255^GETRGBR(ColorScreen),255^GETRGBG(ColorScreen),255^GETRGBB(ColorScreen));
   while(!IsStopped())
     {
      t0=GetMicrosecondCount();
      Text.Erase((color)ColorScreen);
      Text.TextOut(0,0,str,clr);
      Text.Update();
      t1+=GetMicrosecondCount()-t0;
      t0=GetMicrosecondCount();
      Comment(str);
      t2+=GetMicrosecondCount()-t0;
      str="Соотношение времени выполнения Canvas/Comment = "+DoubleToString((double)t1/(double)t2,5);
      if(i==1000) {Print("Canvas - ",t1,"   Comment - ",t2); i=0; t1=1; t2=1; } else i++;
     }
   Text.Destroy();
   Comment("");

}

The test shows that graphical output is about 10% faster. But the interesting thing is that even if you set the font size to 30 (instead of 12), the speed is still faster. It's a mystery to me personally.

Files:
 
Alexey Volchanskiy:

I don't do 60k/sec cartoons, I just put them out and ok.

Canvas can do cartoons too.


Files:
 
Nikolai Semko:


Here's a script on MQL5 (haven't tried it on MT4):


I tried it on MT4. The code works there as well.
On MT4 it turned out that Comment is about 5 times faster than its graphical counterpart. And it turns out that Comment() is 5-6 times slower on MT5 than on MT4. Now this is an unpleasant and strange surprise. So my question is to the developers. How come? It's clearly a bug for 5!!!

 
Nikolai Semko:

It is logical, but it is not.
And this is easy to check.
Here is a script for MQL5 (I haven't tried it on MT4):

The test shows that graphical output is about 10% faster. But the interesting thing is that even if you set the font size to 30 (instead of 12), the speed is still faster. It's a mystery to me personally.


These measurements are about nothing. We should run separate loops of tens of thousands of passes for Comment and Canvas separately, then we'll be able to judge something. And the text to be printed should change, e.g. let the counter value be printed.

Couldn't you re-do it this way?

 
Alexey Volchanskiy:

These measurements are nothing. We should make separate cycles of several tens of thousands of passes separately for Comment and Canvas, then we can judge something. And the text to be printed should change, for example, let the counter value be printed.

Could you re-do it in this form?


I tried to make separate loops too and thought that the result was rather strange. Same results. Doesn't make any difference whether it's a general loop or separately. In my sample the text changes each time, I wonder why it hasn't been noticed. I know about compiler's optimization too. ))

Reason: