Is it possible to call one derived class into another derived class from the same Base/Parent Class ? if yes how to instantiate the 1st class into 2nd class ? - page 2

 
Amir Yacoby #:
Hi agree with the reason, Dominik, it is very limiting. But not with the conclusion, I think using procedural instead of the limited OOP is going way too far. 

There was an intention in metaquotes about 3 years ago to make the interface applied by a class in addition to class extension, seems easy to do and makes it much better for developing. Pitty the went off that.

Hi Amir

I agree with you and already noticing many ways to reduce my coding work by using classes.

regards

 
Dominik Egert #:
Welcome. NP.
There is one major limitation in MQL which I find very annoying, therefore I do not use OO but do all in procedural programming. MQL does not allow deriving from more than one class at the same time. This limits the whole OO concept to a single derive path and in my eyes limits the possibilities way to much.


Hi Dominik

How about these layer type

StrategyBase as main parent class // TrendBase as derived class from StrategyBase // Breakout as derived class from TrendBase ?

I feel it might work out, however if we have mutiple conditions to include in "Breakout" class this may not be possible. I will give it a try and see if it works out.

 
Very polite chat here.

I started to use namespaces as a "replacement" for classes. It seems odd, but the given OO model by MQL is not only limited by the deriving model, but also defacto broken by the limitations of return values from functions.

A real encapsulation is therefore simply not possible and drives the main spirit of OO ad absurdum.

Most, if not all tasks are, and this I think goes for the types of algorithms in general applied to EAs, is anyways better and more structured in procedural programming.

I've tried to build an encapsulation for the MqlRates data structure, but due to lack of return values interoperability, I had to realize, MQL does not "allow" such encapsulation.

The simple limitation of not being able to override the basic assignment operator makes it in my eyes a broken approach.

Try to assign an object to a basic data type, like double. It is not possible, even though the object is able to return such a value, the compiler will not accept the "dynamic cast", not even if it is the only return value the object is capable of.

I stick to structures, and yes, I do use deriving from them, and procedural functions.

It is a limited, or rather old style of developing, for me it does the job and I do not get tempted to "slip" into OO to much....
 
Dominik Egert #:
Very polite chat here.

I started to use namespaces as a "replacement" for classes. It seems odd, but the given OO model by MQL is not only limited by the deriving model, but also defacto broken by the limitations of return values from functions.

A real encapsulation is therefore simply not possible and drives the main spirit of OO ad absurdum.

Most, if not all tasks are, and this I think goes for the types of algorithms in general applied to EAs, is anyways better and more structured in procedural programming.

I've tried to build an encapsulation for the MqlRates data structure, but due to lack of return values interoperability, I had to realize, MQL does not "allow" such encapsulation.

The simple limitation of not being able to override the basic assignment operator makes it in my eyes a broken approach.

Try to assign an object to a basic data type, like double. It is not possible, even though the object is able to return such a value, the compiler will not accept the "dynamic cast", not even if it is the only return value the object is capable of.

I stick to structures, and yes, I do use deriving from them, and procedural functions.

It is a limited, or rather old style of developing, for me it does the job and I do not get tempted to "slip" into OO to much....

Dominik, yes we all are just discussing the subject, nothing personal.

I really appreciate all your responses. May be I have not yet reached to skill level in programming, where I can start facing challenges in OOP as you do. So far in my early stage of learning and development, it is helping me quite well.

and that makes me tempted to "slip" into OOP too much :) 

 
Dominik Egert #:

Hi Dominik

I found a simple way to handle my issue.

Created standalone class CTrend.mqh with required parameters for calculation.

Just included this Class into my CStrategyBase.mqh and initialized it. Wollaa from there derived classes of CStrategyBase have all of its methods.

Just thought to share my progress on this matter.

 
That sounds really good. Very nice.

Yes, we are sharing opinions. I started out with OO using VC++6.0 and MFC.

At first I didn't understand the concept, after I don't know how many attempts, I learned it's not always the best approach.

Especially when looking at YouTube tutorials for OO, most of the time procedural is much faster, easier and straight forward.

MQL taught me a hybrid model which works quite good for me and my thinking process.

Most of data related code I OO and logic I procedural. This gives me most of the time clean and easy to read code as well as fairly fast performance.

Lately I slipped I little and regretted it so badly. I had a data store with objects and I created a stable pointer object to the data store, derived it into a more sophisticated version and found myself locked again in return value issues...

The data store was dynamically changing and the pointer class/object was supposed to give persistently the same object anytime it was referenced. Struggles arose...eespecially because there had to be only one instance of the particular object from the store.

I slipped a little to deep into it.

When that happens, I begin to hate MQL and wish I could do it all in C++.

But if you are starting out still, let me state, OO is no holy grail as it iloften gets advertised, same to PP. It strongly depends on the use case, I suppose.

Neirher nor is bad pe see

 
Dominik Egert #:
That sounds really good. Very nice.

wow that's really great piece of information in your last reply.

True for MQL I am new and started with v4 then moved to v5 after couple of months. Basically I am a finance professional with a passion for Programming. I had used to work on Oracle Database (including OOP) loooooong back in 1998 till 2000 :). Then my profession in Africa made me loose all connections with programming. It is only in 2020 around April, I was introduced to Forex Trading, and in few months sitting in front of computer and looking for trades, made me realize that this is not my cup of tea.

Then I came to learn about Algorithmic Trading and Trading Robots. Since then I am into it and so far OOP in MQL helping me well with my codes, so keeping it on. What I personally feel that it may not be perfect but with some tweaks it can deliver what you need.

The biggest challenge I had, there was no proper source to learn MQL, and hence I had to rely on forum and youtube tutorials and some paid contents on Udemy.com. But in general not much good knowledge is available for MQL5.

I have been struggling a lot with Custom Indicators and Candle Patterns to try position opening. However it used to work on the time range I look at creating the codes and most of the time if I run EA on different time period, I start loosing out.

about 2/3 months back I come across tutorials from https://www.youtube.com/c/OrchardForex and that totally changed my working style. Yes I could not follow his framework approach, but then when I blended his approach with mine, things are moving smoothly.