- Is the code correct ?
- How to improve the code ?
- How to speed up the code?
What do you mean by right or wrong? If it works correctly, it's right. If it doesn't work, it's wrong.
Improve. Improve when something doesn't satisfy a need. What needs it doesn't meet, then you should improve it in this direction.
Why speed up? Orders don't open that often, even rarely compared to the total number of ticks in the tester.
But that was philosophy.
Practice. Why do we need this class if there is a great standard one? It's true, it is for MT5 and I do not know if it is available for MT4. Don't you have one?
There is one disadvantage in your code - absence of Stop Loss and Take Profit.
So OOP is just a function to cram into a class? Productive, it's going to be fun on the forum soon.
If you are so clever, then write the right way, the topic was not created for sarcasm ....
If you are so smart then write the right way, the topic is not for sarcasm ....
It depends on what you want, what you need, and what your programming style is.
You can make a class as a set of functions with parameters, like in your case.
You can make methods to set parameters, and directly open order by calling method without parameters.
It would be better when it is more simple - in this case, it will be more applicable in different cases. Trying to do something super-perfectly universal is the dream of an idiot, a waste of time and mental effort.
More. Until you have had to solve the same problem 20 times, you'd better not try to create a universal approach.
What does it mean right or wrong? If it works correctly, it's right. If it doesn't work, it's wrong.
Improve. You should improve when something doesn't meet a need. What needs are not met, in that direction to improve.
Why speed up? Orders don't open that often, even rarely compared to the total number of ticks in the tester.
But that was philosophy.
Practice. Why do we need this class if there is a great standard one? It's true, it is for MT5 and I do not know if it is available for MT4. Don't you have one?
There is one disadvantage in your code - absence of Stop Loss and Take Profit.
Stop losses and takeaways for orders are set separately, as we may not know what type of account we will be working on ....
You can make methods to set parameters and directly open an order by calling a method without parameters.
Can you demonstrate this with my example ?
I don't feel like coding. Anyway... In private section declare variables for Stop Loss, Take Profit and lot values. These variables are used in order opening methods, of course, lot is as it is and price levels are calculated using these variables. But we should set values for these variables. This means we need methods like: SetTakeProfit(int Value), SetStopLoss(int Value), SetLots(double Value).
In most EAs, methods SetTakeProfit(int Value), SetStopLoss(int Value), SetLots(double Value) will only need to be called once in the inite. Calling methods to open orders without parameters greatly speeds up execution time.
If you're so smart, write it down correctly, the topic was not created for sarcasm ....
As always, I wanted to learn, but there are bound to be those who have nothing more to say except to be clever...
I wrote a simple example to take it apart, I don't know how to write more competently with OOP ... It is just an example, if you know how to write a similar code correctly and OOP then please write, so that I and others could learn ...
As always, I wanted to learn, but there are bound to be those who have nothing more to say except to be clever...
I wrote a simple example to take it apart, I don't know how to write more competently with OOP ... It's just an example, if you know how to write such a code correctly and OOP then please write, so that I and others could learn ...
Don't mind me.
* * *
You should strive to ensure that the main and most frequently used methods are called without passing any parameters. This would increase performance. But it will reduce usability.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all!
I think it's time to create this thread, because there is no good OOP training anywhere, but we need and want to learn.
To litter the branch "questions from newbies" with more complicated and not understandable to newbies code examples, probably do not need.
Having read the two articles "The Basics of Object Oriented Programming andOOP in MQL5 by Example: Error and Warning Code Handling", I have written a sample code that I would like to explain in details.
I have written a sample code and I want to study it in details. I also suggest you to publish your own codes and discuss them together.
I am interested in the following: