That doesn't make sense to me, why do you want a singleton to use an array of objects after that ?
I do not want one file with 6000 lines of code that switches between strategies. For now, the array of objects contains only one strategy but more can be added. Then I select one of them to run based on the market conditions.
I could use static classes but those cannot inherit..
Maybe my design is wrong. If so, can you provide some alternative?
I do not want one file with 6000 lines of code that switches between strategies. For now, the array of objects contains only one strategy but more can be added. Then I select one of them to run based on the market conditions.
I could use static classes but those cannot inherit..
Maybe my design is wrong. If so, can you provide some alternative?
In my opinion your design is wrong yes. Forget the singleton and proceed with your arrays.
A singleton should be ... a singleton, obviously a strategy is not a singleton.
Why do you want the Strategy class to be a singleton ? Maybe I am missing something.
angevoyageur:
In my opinion your design is wrong yes. Forget the singleton and proceed with your arrays. A singleton should be ... a singleton, obviously a strategy is not a singleton. Why do you want the Strategy class to be a singleton ? Maybe I am missing something. | agreed |
class Basic_Strategy{ protected: // Abstract Basic_Strategy(){} // Ctor public: // common to all void on_tick(){ do_on_tick(); } private: // customizable virtual void do_on_tick(){ /* pure or default */ } }; class Strategy1 : public Basic_Strategy{ private: virtual void do_on_tick(){ ... } }; class Strategy2 : public Basic_Strategy{ ... }; Basic_Strategy* strategies[99]; uint nStrategies = 0; : strategies[nStrategies++] = new Strategy2(); void OnDeinit(){ while(nStrategies > 0) delete strategies[--nStrategies];
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
In a static StrategyManager class I want to have a static array of Strategy Singleton classes who's functions i call depending on the current market's behavior. The static functions like OnInit() in the StrategyManager class are being called in the Expert's mq4 file.
When I try to compile this, the compiler returns the following error: "const expression required". The error is pointing towards the last line of the StrategyManager.mqh class (see below).
I need to 'resolve' the strategy array because it is static. But I can not use {} to assign data to it. How am I suppose to do that then? Thanks!
Strategy.mqh
StrategyRanging.mqh
StrategyManager.mqh