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
So, I have taken a look at the code for the classes CExpertBase and CExpert, and as you have already mentioned, what is preventing you from changing the symbol, is the current phase of the objects initialisation, which only allows changing the symbol during the INIT_PHASE_TUNING (which is after the Init() method but before the ValidationSettings() method).
Also, by default the CExpert constructor sets the member variable "m_other_symbol" to true, so it allows you to change the symbol when using Symbol() method, during the "INIT_PHASE_TUNING" phase.
So, what I would suggest is the following:
>Once the phase is changed, this part of the code will no longer try to update the symbol on the next call to OnTick() or in the OnTimer().
Unfortunately, this solution does not work for me because my requirement is:
- the underlying source symbol (= Symbol()) for data (i.e. CSignal and its indicators); this symbol can be fixed when initializing CExpert.
- the custom symbol (= m_other_symbol ???) with custom period (= m_other_period ???) for trades (i.e. CExpertTrade); this symbol can be changed e within void onTimer(). Subsequent calls to onTimer() may change the symbol again.
Btw, it seems a bit hacky to play around with internal stuff like INIT_PHASE_TUNING. I think the most clean solution is simply to override CExpert::initTrade:
and only intitalize my custom CExpert::initTrade within OnTimer() while leaving the other CExpert initialization within int OnInit():
The question is:
Does this solution have any hidden risks or limitations (e.g., historical trades, positions, etc.)? Perhaps one of the Metatrader maintainers who wrote the CExpert classes knows the right solution. Perhaps the solution offered here can be added to the standard CExpert by providing an overloaded method of CExpert::initTrade that accepts my_custom_symbol as a parameter. Would be nice if some of the MetaTrader maintainers can look at this issue.
Well, if your requirements are so unique, why not simply create your own base code?
The Standard Library is often too complex and tries to do too much. Plenty of its complexity is unnecessary for most EA requirements, in my opinion.
So, instead of trying to use it, simply make your own mini library or simply make classes according to your own needs. That is what I do!
I am very much in favour of the "keep it simple, stupid" principle, and that is how I code my EAs.
There doesn't seem to be a way around simply extending CExpert and overriding or redefining some methods. The only thing is, I don't understand the reason for the existence of m_other_symbol and m_other_period — perhaps I can use them for my use case, thus avoiding extending CExpert. But at the moment, I'm not sure.
The fact that you want to keep changing the symbol multiple times, means then the entire CExpert object needs to keep re-initialising completely. That is neither practical nor efficient. The class is not design for that, and trying to retro-fit it is also not ideal.
Create your own base class with your requirements in mind and build on that. Keep it simple.
>CExpert object needs to keep re-initialising completely. That is neither practical nor efficient.
I am looking to avoid this by overriding the appropriate methods. I need to look each class where m_symbol is used and if needed, override those methods, e.g.:I only need to change the symbol for trading and position, not for signal, indicators, etc.
> Create your own base class with your requirements in mind and build on that. Keep it simple.
I thought I'd use CExpert's standard libraries to avoid a lot of boilerplate code. I'm not sure which approach is better at the moment. Extending CExpert and overwriting or developing it from scratch. The only thing that could be a bit problematic is that if I use inheritance here, even the smallest changes to CExpert might require my class to be adapted again. Hmm. I'll look into it.
Thank you so much so far.