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
I would never go back to flat use of the functions! Long live the OOP
Please post compilable code that can reproduce the problem in the Tester.
here.
Are there reasons, aside from convenience, for loving OOP in MQL5?
will check out your code in 8 hours from now. whatever happens, thanks for being so generous with your time on this!
I haven't tested the comparative efficiencies of standard versus OOP, but I've always assumed that standard code is faster than accessing external include/library files.
Given your branching statements, OOP overhead is the last thing you should worry about:
Forum on trading, automated trading systems and testing trading strategies
dynamic lotsize not working. help!
Ryan L Johnson, 2026.04.28 15:54
Notes: positionTime is superfluous but I left it in place in case you have a use for it. The code can be sped up by replacing strings with int's─strings are merely more illustrative here. You can also get the count of positions from the custom function instead of PositionsTotal() if you wish. Order return results are omitted. The Bought/Sold variables also have to be conditionally reset to false at some point in the code─presumably when PositionsTotal() == 0. I wrote the OnTick() code directly into the Forum code module, so it is uncompiled and untested.Given your branching statements, OOP overhead is the last thing you should worry about:
Try wrapping similar code in functions and stop copying and pasting it. Then you'll see opportunities to optimize your branching statements. As you continue to refactor and optimize your code, you will most likely end up using OOP.
I like OOP and I use it a lot, but it's by choice not by facts. You will hardly find factual arguments to convince someone OOP is better than procedural coding.
I like OOP and I use it a lot, but it's by choice not by facts. You will hardly find factual arguments to convince someone OOP is better than procedural coding.
I love breaking code into small functions. I don't know how to continue breaking code into small functions as my codebase grows without encapsulation. I'm sure there are non-OOP approaches that solve this problem, but I'm not familiar with them, and I can't do without OOP.
Regarding other approaches, I've long been considering looking at the Linux kernel source code—I'm curious how they organized that huge C codebase, which, as far as I know, doesn't have OOP. But I keep putting it off because I love OOP.
Please post compilable code that can reproduce the problem in the Tester.
Try wrapping similar code in functions and stop copying and pasting it.
As a caveat to that, too many custom functions in an mq5 file will jam up the Tester as previously confirmed by Fernando.
@Michael Charles Schefe, you might even be confirming this based on the plethora of custom functions in your code and its Tester incompatibility. That has happened to me as well in the past.
Having said that, there's nothing preventing anyone from putting my proposed OnTick() code into custom functions.
As a caveat to that, too many custom functions in an mq5 file will jam up the Tester as previously confirmed by Fernando.
I will never believe this until someone provides me with a way to reproduce it myself.
Having said that, there's nothing preventing anyone from putting my proposed OnTick() code into custom functions.
Yes, sure! You claim that OOP can be "expensive" in terms of performance, and then you publish procedural code that can be optimized. That's why I wrote a couple of comments. But I'm already drifting off-topic, sorry, I won't continue.
Yes, sure! You claim that OOP can be "expensive" in terms of performance, and then you publish procedural code that can be optimized. That's why I wrote a couple of comments. But I'm already drifting off-topic, sorry, I won't continue.
even tho i would add an int variable=PositionsTotal() and reused this int for all those lines in OnTick; i do not see anymore optimising opportunities there. i woul also do same for ask and bid prices, however, this would only be out of habit, i do not think it would make the code run faster since these lines are not used at every tick -- correct?
all my trades use same signal conditions, ie not a grid system, just fyi, but thats ok i am sure i will still use your code to find a fix.