Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1032

 

Is it possible to duplicate a Ccanvas object?


I create an object with Ccanvas and in the process have to create duplicates. Sometimes 10-20 and sometimes 100-200.

One time the object is definitely drawn. Is there any way to duplicate it?

 
Sergey Likho:

Is it possible to duplicate a Ccanvas object?


I create an object with Ccanvas and in the process have to create duplicates. Sometimes 10-20 and sometimes 100-200.

One time the object is definitely drawn. Is there any way to duplicate it?

CCanvas *canv = new CCanvas
But this is not duplicating an existing one. It's creating a new one and a pointer to it.
 
Artyom Trishkin:
CCanvas *canv = new CCanvad

I meant a graphic object.

   CCanvas obj;
   obj.CreateBitmapLabel(0,1,name,x,y,x_size,y_size,COLOR_FORMAT_ARGB_NORMALIZE);
   obj.FillRectangle(0,0,x_size,y_size,ColorToARGB(Color,Alpha));
   obj.Update(false);


Как сделать 10 копий с измененными координатами?
 
Sergey Likho:

I meant a graphical object.

I showed you. If you don't know beforehand how many objects need to be created, then only by means of new.
If the number is known, then
obj1, obj2, obj3,...,objN
 
Igor Makanu:

I could be wrong, but your link will be the author's thread, but you have to leaf through the whole thread, Igor seems to have posted slightly raw codes, and then sometimes rewrote what needed improvement, although again I could be wrong - I leafed through this thread about 5-6 years ago, I do not remember anymore

You are not mistaken. Recently leafed through the author's entire thread. It took me about 2-3 days. In the author's topic in view of the remoteness of writing some of his features are no longer relevant (or so it seemed to me).Read absolutely everything and highly topical and irrelevant little. And as you noticed, he did have mistakes that pop up after 2-3, or even more pages, when someone decided to use his function, found the error and either corrected it and just said that there was a mistake, or just pointed out. So even 10 pages later the same function may appear again, either corrected or improved (time has passed and he wanted to improve it).

So if someone pulled out only the most important and relevant topic, you can only say thank you and save a lot of time.

 
How can I pass a pointer to a function (meaning write a function that takes a pointer to a function as an argument) as a parameter? I've done it before in mql4, but I lost a copy of the file where this example was.
 
Seric29:
How to pass a pointer to a function (the function takes a pointer to the function as an argument) as a parameter? I have done it before with mql4 but I lost a copy of example file.

Did MQL ever support function pointers? I don't think so. One solution is to wrap the function in a class and pass the pointer to the object.

 
Sergey Popov:

Hi all!

I want to write a function in my EA that prohibits trading in the first 2 hours after the start of trading.

But I faced with the fact that iTime(Symbol(),1440, 0) does not correctly return the opening time of the day candle.

More specifically: on 26.12.2019 the market opened at 06:00:00, but iTime determines 00:00:00.

How do I calculate exactly the opening time of the day?

SymbolInfoSessionTrade will help me find out the trading time. I don't know if it reflects changes for Christmas and other holidays.

 
Aleksey Mavrin:

Did MQL ever support function pointers? I don't think so. One solution is to wrap the function in a class and pass a pointer to the object.

It does. This is done using typedif specifier read help but the scheme is different from c++. I found a forum where a person recorded this code but I didn't save the file and restarted the system, of course the file was deleted. But the help shows a simple example and I had an example I was asking about.

 
Aleksey Mavrin:

Did MQL ever support function pointers? I don't think so. One solution is to wrap the function in a class and pass the pointer to the object.

You can, code to reproduce:

#property copyright "Copyright 2019, IgorM"
#property link      "https://www.mql5.com/ru/users/igorm"
#property version   "1.00"
#property strict
typedef void(*TFuncvoidPTR)(void);
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
{
   TFuncvoidPTR f_ptr[3];
   f_ptr[0] = f_1;
   f_ptr[1] = f_2;
   f_ptr[2] = f_3;
   for(int i=0;i<ArraySize(f_ptr);i++)
   {
      printf("Вызываю фунцию № %i ",i);
      f_ptr[i]();
   }

}
//+------------------------------------------------------------------+
void f_1() {Print("Это вызов функции : ",__FUNCTION__);}
void f_2() {Print("Это вызов функции : ",__FUNCTION__);}
void f_3() {Print("Это вызов функции : ",__FUNCTION__);}

2019.12.30 18:30:55.518 Script tst EURUSD,H1: removed

2019.12.30 18:30:55.511 tst EURUSD,H1: uninit reason 0

2019.12.30 18:30:55.511 tst EURUSD,H1: This is function call: f_3

2019.12.30 18:30:55.511 tst EURUSD,H1: Calling function number 2

2019.12.30 18:30:55.511 tst EURUSD,H1: This is calling function : f_2

2019.12.30 18:30:55.511 tst EURUSD,H1: Calling function #1

2019.12.30 18:30:55.511 tst EURUSD,H1: This is calling function : f_1

2019.12.30 18:30:55.511 tst EURUSD,H1: Calling fuction no. 0

2019.12.30 18:30:55.511 tst EURUSD,H1: initialized

2019.12.30 18:30:55.496 Script tst EURUSD,H1: loaded successfully