This article provides the full source code of an example presented in a webinar on 2021.07.10. In the webinar, it discussed how to convert a Simple Moving Average Strategy from MT4 EA to ALGOGENE.
Many experienced retail traders should already be familiar with MetaTrader (MT4/MT5), which has a popular feature called Expert Advisor (EA) for trading strategy automation. When we open MetaEditor, we can find a number of pre-built technical indicators and trading strategies.
Simlpe Moving Average Strategy
Let's take the Moving Average as example. The trading idea is that if the market price crosses the MA line from bottom, it indicates a short-term up trend which suggests a buy signal. On the other hand, it indicates a sell signal if the market price crosses the MA line from the top.
The trading logic can be formulated as follows:
- if Open < MA and Close > MA, then BUY
- If Open > MA and Close < MA, then SELL
MT4 Source Code
Below is the source code of the Simple Moving Average strategy exported from MT4. The syntax is equivalent to C++.
Implementation on ALGOGENE
Following a similar programming structure, we can easily convert the EA as follows.
We can then reproduce a similar backtest result as in MT4/MT5.