It is mostly a theoretical question ( but example code is always welcome ).
The real question is: how to correctly code the 'frame' of an EA that tests multiple scenarios from multiple custom indicators?
The way I'm ( busy ) building an EA, is not very much focused on 1 strategy, but is gonna try to 'test' multiple strategies and 'picks' the most appropriate one.
So I have created a few custom indicators, that are all returning an array of 'status data'.
For example I have the following indicators:
- Crossing moving average indicator, that gives a signal when the average is crossed and also the current position in percentage moved from MA.
- Bollinger Bands indicator, that returns the 'room' between the bands and gives a signal when the bands starts 'squeezing'.
- Multi timeframe 'direction/trend' indicator ( is a certain timeframe moving toward up or down ). That returns current directions and gives a signal, if a timeframe direction changes.
- ADX indicator, for checking 'small-scale' movement and picking best buy/sell points.
I could write one HUGE scenario, but I think it can be done much better. Because if, lets say, all timeframes are going down ( down trend ) You could have a special scenario to handle lots of down movement. But if there is no current trend, a different scenario would fit best.
So, I feel like its best to make multiple scenarios ( still in 1 EA ). First all custom indicator data is collected and then each scenario uses that data to calculate its stuff. It then returns a 'score' and the best one is picked.
But how can I layout the code in the best 'overview' way?
Should I create a Class for each scenario and give them a manual 'tick' with data? And just split them into multiple files and #include
them?
Or maybe event-driven? Created classes that just keeps on running, calculating and setting listeners to certain indicator events and go there own way (that would be awesome)
Any thoughts are much welcome!
UPDATE2016-01-11,12:00
I don't have time right now to create a UML.. But I do the following for now ->
Order
(Order
is a singleton, just performing order requests )Indicator
( Base class that each indicator extends )Strategy
( Base class that each strategy extends )IndicatorFetcher
( Holds all indicators, gets run on each tick )StrategyRunner
( Holds all strategies, gets run on each tick, afterIndicatorFetcher
)
Each Strategy
instance gets an access to the IndicatorFetcher
( Holding an overview with all indicators' data, and uses the Order
singleton to perform trading ).
For complex scenarios, splitting each scenario into classes will be useful. Classes are separated into Tasks and Data that interacts with each other. An indicator could be wrapped within a Data-class, which is fed into a Monitor-Task. A big Action-task-class can be created to react to multiple monitor classes.
Initial note: architecture is your enemy ( not the "layout"-of-
MQL4
-code )As discussed in your earlier question, a proper understanding if the MetaTrader Terminal 4 code-execution ecosystem is your best road-map.
Process Management limitations on MT4
this is the core alpha and omega for any larger scale project.
While having done GPU / GPU-grid / hybrid dual event-controllers on top of the MT4 event-scheme with GUI-Finite-State-Automaton Layer, feeding it's actual state into a distributed back-end processing for really fast MQL4-EAs, all these grand Projects are doable and work fine right due to a proper care taken onto shared-resources usage stability ( avoiding race conditions ) & onto a principally non-blocking design ( collision avoidance as a preferred concurrency aspect ).
For an introduction to the process management limitations on MT4, check this post
#include
or not#include
? ( that's a question... )Without having to ask Hamlet, the prince of Denmark, the
#include
directive is ready for your code-base, however it does not handle all your stress efficiently on it's own.Based on an experience of providing a development and maintenance for code-base spanning a bit more than a few hundreds man*years, the
#include
is not the Jack-of-all-trades.A well thought selection of ... The IDE plus some home brew lexers and syntax-validators ... is the key, because this is your team real productivity tool ( or performance brake, if chosen bad ).
Do not hesitate to read a few notes on this in this post
Final remark:
While the inital post
was motivated by
"how to program something HUGE in
MQL4
"[kindly forgive my knowingly over-simplification made in a name of having a bit sharper contrast & focus on the merit]
IMHO