I am playing around with my version of the ATR in MQL4 and this has only 64 lines(!) - and I am very much convinced: small is beautiful and smaller even more beatifull.
(Of course without becoming obfuscated!!)Carl
I bet i can do it in less then 64
But not in MQL5 of course and i pointed this out before but nobody believed me.
I just moved back and decided to stick to MQL4.
There is absolutely no reason to code a standard indicator like ATR using OOP. What do do ?
There is absolutely no reason to use OOP to code 1 simple indicator, you only have good reasons to use OOP if you want to code a lot of indicators or very complex indicators.
OOP is for complex project and/or code reusability.
There is absolutely no reason to code a standard indicator like ATR using OOP. What do do ?
There is absolutely no reason to use OOP to code 1 simple indicator, you only have good reasons to use OOP if you want to code a lot of indicators or very complex indicators.
OOP is for complex project and/or code reusability.
Sure - it is!! The ATR should be my first indicator of many others based (inherited) from a common base.
But if this simple indicator already is so complicated to realize (additional 300 lines on its base), what about the others more complicated indicators??
Reuseability of 686 lines compared to 64 - what is easier to reuse? Reading and trying to understand 686 lines plus adding your own new idea or writing the idea stand alone with estimated only ~100 lines?
I've just decided to stick to MQL4 too (it is my broker choice), but it seems that the future is MT5.
I don't know the differences between them so much, but I think now that, maybe, the best place to start is MQL5 for a newcomer like me who will learn from the ground.
... but they'll require a lot of typing. ;-) ..
I already started to read about OOP, but I prefer - not only this case - real world examples and facts, instead of abstract comments about theoretical(?) benefits of OOP over the traditional way.
One of the (typical?) OOP examples is summing up the area of different figures, so merging heterogeneous objects - but structs and arrays of struct provides similar things.
Any way, please - this to all the fans of OOP - provide a slim solution of the simple ATR on the base of \Include\Arrays\ ?? You can choose the sma-method to smooth the raw ATR to demonstrate a kind of slim how to use the arrays.?
Beside that I am still going on to try OOP and have a few questions.
1) Is it correct that in MQL4 I am not able to return a pointer of a data-array of a class by a public method? (Docs always say what can be done - 'not what not' or this is hard to find).
2) Would I be able to return a 'read-only' pointer to a protected data-array of a class - I haven't MT5 installed it yet? This is instead of returning element by element and/or to avoid to copy the whole array.
May be some will say this is against the ideas of OOP - may be! But at the moment I just want to know what can I do and what's impossible, even if I don't know yet whether I really would need this 'feature'.
In this example I'd like to know whether I can return a 'read-only' pointer to MqlArr[]?
#include <Object.mqh> class MyCQtsArray : public CObject { protected: // MqlRates MqlArr[]; // data array MqlRates voidElement; // void element in case of error int sz; // array size public: MqlRates getRate(int i); } MqlRates MyCQtsArray::getRate(int i) { if (i<sz) { return(¢q[i]); // returns a copy of this element - right? } //error: return( voidElement ); }
Thanks in advance!!
calli
I already started to read about OOP, but I prefer - not only this case - real world examples and facts, instead of abstract comments about theoretical(?) benefits of OOP over the traditional way.
One of the (typical?) OOP examples is summing up the area of different figures, so merging heterogeneous objects - but structs and arrays of struct provides similar things.
Any way, please - this to all the fans of OOP - provide a slim solution of the simple ATR on the base of \Include\Arrays\ ?? You can choose the sma-method to smooth the raw ATR to demonstrate a kind of slim how to use the arrays.?
Beside that I am still going on to try OOP and have a few questions.
1) Is it correct that in MQL4 I am not able to return a pointer of a data-array of a class by a public method? (Docs always say what can be done - 'not what not' or this is hard to find).
2) Would I be able to return a 'read-only' pointer to a protected data-array of a class - I haven't MT5 installed it yet? This is instead of returning element by element and/or to avoid to copy the whole array.
May be some will say this is against the ideas of OOP - may be! But at the moment I just want to know what can I do and what's impossible, even if I don't know yet whether I really would need this 'feature'.
In this example I'd like to know whether I can return a 'read-only' pointer to MqlArr[]?
Thanks in advance!!
calli
Not sure what a (read-only) pointer to array means in MQL, but you cannot return an array from a function in general.
Anyway, you may refer the array in the object, if you declare the array public instead of protected. Not quite the best practise, but for e.g. assigning the indicator buffers the only way I know of.
I've just decided to stick to MQL4 too (it is my broker choice), but it seems that the future is MT5.
I don't know the differences between them so much, but I think now that, maybe, the best place to start is MQL5 for a newcomer like me who will learn from the ground.
Sure - it is!! The ATR should be my first indicator of many others based (inherited) from a common base.
But if this simple indicator already is so complicated to realize (additional 300 lines on its base), what about the others more complicated indicators??
Reuseability of 686 lines compared to 64 - what is easier to reuse? Reading and trying to understand 686 lines plus adding your own new idea or writing the idea stand alone with estimated only ~100 lines?
The number of lines is irrelevant. Either you have a benefit to use OOP or not.
I am afraid you will have to find your own way to OOP and mql. Each one has it's own idea about how to code and use it.
In this example I'd like to know whether I can return a 'read-only' pointer to MqlArr[]?
You can't, MqlRates is a structure, you can't use pointer on structure.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
The last days I started to think about coding in OOP and MQL5 and I was searching for some examples - may be an indicator to start with?
I found this article about it with a coded example of ATR (and ZigZag) - and I got very, very frustrated!!
The simple ATR-indicator was realised by three files giving totally :
Even the final indicator (indicator_atrsample2.mq5 and atrsample.mqh) have nearly 300 lines.
I am playing around with my version of the ATR in MQL4 and this has only 64 lines(!) - and I am very much convinced: small is beautiful and smaller even more beatifull.(Of course without becoming obfuscated!!)
Everybody tells us OOP makes coding easier, better, and faster. But if such a simple thing needs more than 10 times the code it is definitely not easier, better, and faster!
Underneath the code of my ATR! It is sightly different to the original ATR as I use the ema-method for smoothing instead of the sma-method!
Is there an example of an MQL5-indicator in OOP (one abstarct indicator class and ..) that in total has not more than 200 lines?
I'd appreciate to know abou it.
Carl