Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 508
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
is this shorter? bool barup=... WindowRedraw(); will still execute - taken from if
it can also be shorter ... see my file
Kind of like the statement of the question is clear, isn't it. The point is to initialise the same thing.
How are you going to initialise something that doesn't already exist? After the object is created, it starts to exist, and that's when it can be initialized.
I told you right away - make an object a parametric constructor, and pass to it the required parameters, which will be used to initialize the newly created object.
You can pass parameters through a structure, which you fill with required (constant for all such objects) data in OnInit() of the program. Then, in OnTick(), for example, or in any other standard handler, you create your objects, but when you create it you write the following:
CMyObject object = new CMyObject(a_here_structure_with_set_parameters);
Or, if the object data doesn't change from program to program and always has the same values, then explicitly initialize them with the required parameters in the constructor through the initialization list, as Igor said above:
Forum on Trading, Automated Trading Systems and Strategy Testing
Any questions from newbies on MQL4, help and discussion on algorithms and codes
Ihor Herasko, 2018.03.28 17:31
This is done in the initialization list, which is located in the class constructor:
How are you going to initialise something that doesn't already exist? After the object is created, it starts to exist, and that's when it can be initialized.
I told you right away - make an object a parametric constructor, and pass the required parameters to it, which will be used to initialize the newly created object.
You can pass parameters through a structure, which you will fill with the required (constant for all such objects) data in OnInit() of the program. Then, in OnTick(), for example, or in any other standard handler, you create your objects, but at creation you write the following:
CMyObject object = new CMyObject(a_here_structure_with_set_parameters);
Yes, I see. Thank you. Well somehow just thought there was some solution so that when an object is created it has some pre-set parameters right away without having to pass them to the constructor or whatever. Through some parent class or something.
In my class I have all sorts of stuff like indicator parameters etc. as parameters. In general, things that will be static and the same. So why should I pass these values every time I create an object?
So don't pass it on. Initialize in the initialization list, as I've shown. At the moment of creating an instance of the class, the class constructor will be automatically called, which will initialize all members of the class, specified in the initialization list. Put the Print function in the CCandle method and you'll see how the constructor is called without any reference to it.
Yes, I see. Thank you. Well somehow just thought there was some solution, so that when an object is created it has some pre-set parameters right away without having to pass them to the constructor or whatever. Via some parent class or something.
Again. You can do it without transferring the data to the constructor.
So don't pass it on. Initialize in the initialization list, as I've shown. At the moment of creating an instance of the class, the class constructor will be automatically called, which will initialize all members of the class, specified in the initialization list. Put the Print function in CCandle method and you'll see how the constructor is called without any reference to it.
I don't get it, what difference does it make whether to pass them through the constructor or through the initialization function?
So don't pass it on. Initialize in the initialization list, as I've shown. At the moment of creating an instance of the class, the class constructor will be automatically called, which will initialize all members of the class, specified in the initialization list. Put the Print function in CCandle method and see how the constructor is called without any reference to it.
What will they be initialized with? With what values? I don't understand .
Suppose, I have initial values in the Expert Advisor input parameters. So, I need to pass them to each object of the class. But not to pass them to each newly created object.
how come in this cycle my limit order gets deleted only if after placing a limit order on the next bar another limit order has not been placed, i.e. a limit order gets deleted only if it is placed and then followed by two bars with no limit orders
What will they be initialised with? With what values? Not clear
The ones you write in the initialisation list.
Suppose I have initialized values in input parameters of Expert Advisor. So, I need to pass them to each object of this class. But not to pass them to each newly created object.
Here it is:
If we run it, we get: