Questions from Beginners MQL5 MT5 MetaTrader 5 - page 1473

 
Valeriy Yastremskiy #:

Before you do anything with your money, at least do a minimal amount of checking.

Likewise.

Hopefully not credit... Definitely go to the police.

Thank you all for practical advice and help. Moderators please forgive me for breaking forum rules. I am a newcomer and did not know that it is not allowed to discuss brokers. I will carefully read the rules and undertake not to violate them. Thank you once again to all those who responded to my appeal and good luck.
 

I tried to make an analogue of the comment, but the letters were bigger.

In general, it worked, the letters are readable now.

But because of my ignorance of OOP, my comment does not affect the work of the computer very well,

Some time after running the Expert Advisor with a comment on several charts, something bad happens, up to the fading of the screen and rebooting the server)))))

In the terminal logs a bunch of these records.

MQL5  VirtualAlloc failed in large allocator, size=101104
MemoryException 101142 bytes not available, 0 heapmin result

Help those who know how to do, so that the memory does not leak.

The plug-in comment file looks like this:

#include <Canvas\Canvas.mqh>
void Comm(string txt, color clr = clrYellow, int FontSize = 20, string Font = "Consolas", int flag = FW_BOLD)
  {
   CCanvas canvas;

   int shift = 0;
   if(ChartGetInteger(0, CHART_SHOW_ONE_CLICK))
      shift = 60;
   canvas.Erase(0x00FFFFFF);
   canvas.FontNameSet(Font);
   canvas.FontFlagsSet(flag);
   canvas.FontSizeSet(FontSize);

   int width = 0, height = 0;
   string result[];
   int size = StringSplit(txt, StringGetCharacter("\n", 0), result);
   height = (int)(FontSize * 1.8 * size);

   for(int i = 0; i < size; i++)
     {
      int w = canvas.TextWidth(result[i]);
      if(width < w)
         width = w;
     }

   canvas.CreateBitmapLabel(0, 0, "Comment", 5, 20 + shift, width, height, COLOR_FORMAT_ARGB_NORMALIZE);
   for(int i = 0; i < size; i++)
      canvas.TextOut(0, (int)(FontSize * 0.8 * i), result[i], ColorToARGB(clr, 255));

   canvas.Update(true);
  }

Example of using it like this:

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


It is clear that I am doing something wrong with the CCanvas class, but what exactly is wrong, I do not understand.

Files:
Comm.mq5  2 kb
Comm.mqh  2 kb
 
Aleksandr Slavskii #:

I tried to make an analogue of the comment, but the letters were bigger.

The letters are now readable.

But because I don't know OOP, my comment doesn't affect the work of the computer very well,

Some time after running the Expert Advisor with a comment on several charts, something bad happens, up to fading screen and rebooting the server))))))

In the terminal logs a bunch of these records.

Help those who know how to do, so that the memory does not leak.

The attached comment file looks like this:

Example usage like this:


It's clear that I'm doing something wrong with the CCanvas class, but what exactly is wrong I don't understand.

If you are interested in the code without CCanvas library, but with OBJ_BITMAP_LABEL object, look at my code ...

ClosingLots
ClosingLots
  • www.mql5.com
Индикатор информер.
 
Alexey Viktorov #:

If you are interested in code without CCanvas library but with OBJ_BITMAP_LABEL object look at my code ...

Thanks, nice solution, I like it.


But, "a samurai has no goal , only a path ", the solution of how to make a comment is less important to me than finding out what my mistake is in using the class.

 
Aleksandr Slavskii #:

Thank you, beautiful solution, I liked it.


But, "a samurai has no goal , only a path ", I care less about figuring out how to make a comment than finding out what my mistake was in using the class.

How many, in how many BitmapLabel are created ? (Ctrl+B --> All).

 
Artyom Trishkin #:

How many, in what quantity is a BitmapLabel created ? (Ctrl+B --> All).

On one chart, one object.

And how can there be more than one? The name of all created objects is the same - "Comment".


I forgot to write.

The problem comes out on a super poor server with one core and 1gb memory. And then not immediately, but after some time.

But I think that if everything was normal with the code, there would be no problem. Something is clogging the RAM, I can't understand what it is.

Why is it important for me to know?

You can buy server capacity, you can buy memory, you can upgrade endlessly, but it will not make my code correct.

 
Aleksandr Slavskii #:

On one chart, one object.

How can there be more than one? The name of all created objects is the same - "Comment".


I forgot to write.

The problem comes out on a super poor server with one core and 1gb memory. And not immediately, but after some time.

But I think that if everything was normal with the code, there would be no problem. Something is clogging the RAM, I can't understand what it is.

Why is it important for me to understand ?

You can buy more server capacity, you can buy more memory, you can upgrade endlessly, but it won't make my code correct.

What is there in the log when an Expert Advisor is removed from the chart? Usually it tells you which objects are leaking, which gives you a search direction

 
Artyom Trishkin #:

What is in the log when EA is removed from the chart? Usually it tells you which objects are leaking, which gives you a search direction

Mm-hmm. I deleted the logs. But no problem, it won't take long to do it again. Now I will start the Expert Advisor on the server, in the morning (maybe earlier) will be logs.

But as far as I remember, I could not find in them an indication of where memory is leaking.

And the Expert Advisor is not removed from the chart, most likely just restarts the server, as there is no record of terminal closing in the logs. But this is not certain.

 
Aleksandr Slavskii #:

Mm-hmm. I deleted the logs. But no problem, it won't take long to do it again. I'll start the Expert Advisor on the server now, I'll have the logs in the morning (maybe earlier).

But as far as I remember, I could not find in them an indication of where memory is leaking.

And the Expert Advisor is not removed from the chart, most likely just restarts the server, as there is no record of terminal closing in the logs. But this is not certain.

You have not understood the meaning of my question. You don't need to wait on the server when it runs out of memory and bursts.

If there is an object leak in the code, recompile it on your home local computer when the Expert Advisor is running - a message about the number and type of leaked objects should be displayed in the logs. Or run it on a chart and take it down at once - a message about the leak should also appear, if there is one, of course.

 
Artyom Trishkin #:

You are missing the point of my question. You don't need to wait on the server when it runs out of memory and bursts.

If there is an object leak in the code, recompile it on your home local computer with the Expert Advisor running - a message about the number and type of leaked objects should be displayed in the logs. Or run it on a chart and take it down at once - a message about the leak should also appear, if there is one, of course.

It doesn't write anything when compiling. It deletes it and installs a new one. That's it.

NM      0       00:18:47.545    Experts expert Comm (SBRF-12.23,M1) removed
JI      0       00:18:47.547    Experts expert Comm (SBRF-12.23,M1) loaded successfully
KQ      0       00:18:47.560    Experts expert Comm (RTS-12.23,M1) removed
EE      0       00:18:47.562    Experts expert Comm (RTS-12.23,M1) loaded successfully

It is still working on the server. I'll wait, maybe it will write something in the logs.