anyone has an idea? is it only that the example was meant to be used only within a class?
anyone has an idea? is it only that the example was meant to be used only within a class?
Well, I sort of understood that even; what was weird for me, that in the documentation there are many examples how to generate classes, structures etc.,
but then almost nothing explaining how to use them in the main program....
But well, 20 years of procedural programming is quite hard in my brain :)
Well, I sort of understood that even; what was weird for me, that in the documentation there are many examples how to generate classes, structures etc.,
but then almost nothing explaining how to use them in the main program....
But well, 20 years of procedural programming is quite hard in my brain :)
Well, I sort of understood that even; what was weird for me, that in the documentation there are many examples how to generate classes, structures etc.,
but then almost nothing explaining how to use them in the main program....
But well, 20 years of procedural programming is quite hard in my brain :)
I attach here an example of an OOP wrapper so that you can work with indicators in a conceptual level, thinking in OOP terms. Please observe how you access private properties through the public getter and setter methods:
class CBearsPower { protected: int m_handler; double m_buffer[]; public: //--- Constructor and destructor methods CBearsPower(void); ~CBearsPower(void); //--- Getter methods int GetHandler(void); void GetBuffer(double &buffer[], int ammount); //--- Setter methods bool SetHandler(string symbol, ENUM_TIMEFRAMES period, int ma_period); bool SetBuffer(int ammount); //--- CBearsPower specific logic }; CBearsPower::CBearsPower(void) { ArraySetAsSeries(m_buffer, true); } CBearsPower::~CBearsPower(void) { IndicatorRelease(m_handler); ArrayFree(m_buffer); } int CBearsPower::GetHandler(void) { return m_handler; } void CBearsPower::GetBuffer(double &buffer[], int ammount) { ArrayCopy(buffer, m_buffer, 0, 0, ammount); } bool CBearsPower::SetHandler(string symbol, ENUM_TIMEFRAMES period, int ma_period) { if((m_handler = iBearsPower(symbol, period, ma_period)) == INVALID_HANDLE) { printf("Error creating Bears Power indicator"); return false; } return true; } bool CBearsPower::SetBuffer(int ammount) { if(CopyBuffer(m_handler, 0, 0, ammount, m_buffer) < 0) { Alert("Error copying Bears Power buffers, error: " , GetLastError()); return false; } return true; }
Then you can use the class above in another context, for instance:
class CTechIndicators { protected: CBearsPower* m_bearsPower; CBullsPower* m_bullsPower; public: //--- Constructor and destructor methods CTechIndicators(void); ~CTechIndicators(void); //--- Getter methods CBearsPower* GetBearsPower(void); CBullsPower* GetBullsPower(void); }; CTechIndicators::CTechIndicators(void) { m_bearsPower = new CBearsPower; m_bullsPower = new CBullsPower; } CTechIndicators::~CTechIndicators(void) { delete(m_bearsPower); delete(m_bullsPower); } CBearsPower* CTechIndicators::GetBearsPower(void) { return m_bearsPower; } CBullsPower* CTechIndicators::GetBullsPower(void) { return m_bullsPower; }
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I am kind of stuck! :(
I am using the example for OOP in one of the articles here.
It is clear how to create a class, but how can I use it?
In the MyDateClass example, several DateTime variables are declared (as int).
But how can I use them later in the code?
I managed to use classes where variables or functions were defined in the public section, something like my_class.XXX,
no problem. But in example below, how do I use it? Or is it maybe that the example is supposed to be used only inside of a class?
THANKS!