DEVELOPMENT OF AN OPTIMIZED INTELLIGENT MACHINE LEARNING APPROACH IN FOREX TRADING USING MOVING AVERAGE INDICATORS

This research presents the development of an optimized intelligent machine learning approach in Forex trading using two variants of Moving Average indicators. The main aim of the Expert Advisor (EA) development is to introduce a new intelligent model for automated execution of trades in the Forex market, reducing potential losses due to human errors and sentimental factors in trading Forex. In developing this trading model, Momentum strategy was used since it takes advantage of market swings, along with Machine Learning - Genetic algorithm, being a type of supervised learning used in training the past historical data based on selected trading parameters in a Meta Trader 4 (MT4) platform. The new Expert Advisor –Exponential Moving Average (ESMA) was built using the MQL4 language which is based on C++ for programming specific trading strategies and easily facilitates automated trading. The result is an optimized intelligent trading system that implements the intersection of the two moving averages at various periods, to execute trades autonomously with a profit pass rate of 75% visible from the Optimization chart of the MetaTrader 4 (MT4) platform


INTRODUCTION
The recent interest of Forex analysts and traders in financial institutions and academic communities in the area of intelligent trading systems, otherwise known as Expert Advisors (EA's), has led to the intensive research on the development of various types of Forex trading systems.This is relatively due to its captivating techniques to outrun the financial market.
Many attempts have been made to come up with a consistently profitable system and inspiration has come from different fields ranging from Technical analysis, fundamental analysis, econometric modeling of financial markets, to machinelearning,.Few efforts were profitable and those that appear most promising often could not be utilized in trading real markets due to related practical disadvantages.Among others, these included large draw-downs in profits and excessive switching behaviour resulting in very high transaction costs (Dempster and Romahi, 2002).Proficient traders do usually consider those automated systems as being highly risky in contrast to the returns they themselves were capable of delivering.Even though a trading model was publicized to generate an acceptable risk-return report on the historical data, there is no guarantee whatsoever that the system would still be effective in the future.It would cease working precisely at the moment it became unable to adapt to the changing market conditions, (Moody and Saffell, 1999).
These developed intelligent systems are able to trade financial markets most times, better than humans (profit, risk management) and most are fully autonomous, Martinez (2007).Many concepts, divided into technical analysis and fundamental analysis are implemented into the systems, but the tweaks making them successful remain unidentified, LAUTECH Journal of Engineering and Technology 17 (2) 2023: 18-27 shrouded in mystery.Different individuals have strived to overcome this by coming up with different trading approaches that can protect them from the inhospitable downfalls of the market, as well as still allowing them to access the profitable nature of the market.This has led to some strategies, such as market timing approach utilizing the moving averages from technical analysis becoming exceedingly prevalent, (Greene and Gerald,2008).
Machine learning techniques are applied to train the moving averages indicator over a historical data generated from over a given period of time for the sake of gaining long-term profits, (toptal.com, 2018).The trading approach is to ensure that currency pair values and positions are monitored during the daily trading sessions, where this action is either buy or sell based on the prediction obtained.
The prediction problem is viewed as a binary classification task, and not as trying to predict the actual exchange rate between two currencies, but rather, if that exchange rate is going to rise or fall.
Each day there are four observable rates, namely; the "Open", "Close", "Low" and "High" in the Forex market which are duly monitored, (Forexboat.com, 2015).

METHODOLOGY
The following materials were used in the development of this software-based research work.

Data Collection
Acquiring historical data were crucial for the model training and testing of the developed trading system.
In the quest for obtaining a quality, verifiable data, various sources of historical Forex data was sourced for, which varied wildly in quality and price.This option of data collection was equally used to source for historical data and it was found that the data delivered is of high quality and format.This proved to be the fastest way to obtain high-precision, wide- Calculating the Simple Moving Average (SMA) The SMA indicator is common on Metatrader4 trading software and the calculation formula smoothes pricing information by averaging as follows: 1. Choose a "period" setting -assume "10" for example; 2. Choose a "price" setting -assume "closing price"; Formula for Calculating EMA BabyPips.com(2015) stated that the EMA indicator is common on Metatrader4 trading software.The calculation formula is more complex than for an SMA and follows these steps: Choose a "price" setting -assume "closing price"; Choose a "period" setting -assume "10" for example; Calculate the "Smoothing Factor" = "SF" = 2/(1 + "10");  Machine learning strategy is also implemented in the training of the data to make the trading system behave intelligently in its activities during the trading sessions.

Results
The  For this, they must be compiled and located in the /EXPERTS folder.
Having all the necessary data available, the training is initiated.MetaTrader 4 (MT4) offers an option to use a genetic algorithm for the optimization.This is very useful, as it can decrease the amount of required parameter configuration performance measurements from billions down to about 10000 usd.Another method to accelerate the processing is by setting an optimization limit.
When the limit is reached, the measurement is stopped and the result is discarded.
As all the trainings will be run with an initial balance of 10000 usd, it is decided that a suitable limit for stopping of the test should be the balance dropping below 9000 usd.Before any training is conducted, all the parameters must be set carefully.
This includes the model, training start and end, timeframe (period), spread, optimization, initial deposit and its currency, allowed position types, optimized parameter, genetic algorithm, input parameters ranges and optimization limits.After the expert has been selected, one has to make an additional setup and set the inputs.This can be done by pressing of the "Expert properties" button.(2), (3) respectively.
time span historical data suitable to train the developed ESMA model.Since InstaForex Trader (IFX) does not provide long term historical data, the historical data was gotten from OANDA broker from OANDA trading company; because it has a reputation of offering high-quality historical data feeds with periodicity of one tick.However, OANDA does not offer historical data in a format compatible with MetaTrader 4. To get a compatible format of the historical data needed for the training of the developed model in this study, Tickstory utility is used.This utility software is needed to convert the historical data into a MetaTrader 4 (MT4) compatible format and then imports it into the trading platform (MT4) for the required Optimization, training and testing of the ESMA model.Design Methodology -The Moving Average Systems Simple Moving Average (SMA) trading system According to BabyPips.com(2015), The "Simple Moving Average", or "SMA", indicator is one of the oldest and most common indicators used across all financial markets, including the Forex market.Its origins are unknown, but its use was designed to smooth out the effects of price volatility and create a clearer picture of changing price trends.Financial currency traders use an SMA, sometimes in conjunction with another SMA of a different period, for signal confirmation of a change in price behavior.The SMA indicator has only two variables involved in its computation -"period" and "price".The period can be chosen, but values over "20" are normally better when dealing with longer trend lines.Price can be set at open, close, high, or low.Since the SMA is so popular, it can often form a support or resistance line, depending on the type of trend that traders respect in their decision-making process,BabyPips.com (2015).Period can be in Minutes, hours or even days dependent on the market timeframe where the ESMA model is implemented.
3. Add up the sum of the last "10" closing prices and divide by "10" 4. Repeat the same process when the next closing price is posted.SMA for 10 Periods = (X1+X2+X3+X4+X) / 10 (1) Where X1-X10 represents the different Period values Exponential Moving Average (EMA) Trading System The Exponential Moving Average (EMA), indicator was developed to counter the lagging weakness of the SMA indicator by weighting more recent prices more heavily.Its origins are unknown, but its use was designed to smooth out the effects of price volatility and create a clearer picture of changing price trends.Traders use an EMA, sometimes in concert with another EMA for a different period, to signal confirmation of a change in price behavior, Forexboat.com,(2015).The EMA indicator uses "period" and "price", as does the SMA, but fresher prices are given more weight to make the indicator respond more quickly to market changes.Since it reacts more quickly, it is prone to generate more false signals.The EMA works well in tandem with another EMA in strong trending markets, but the use of an EMA in a sideways market is not recommended.Since the EMA is so popular, it can often form a support or resistance line, depending on the type of trend that traders respect in their decision-making process.BabyPips.com (2015); Forexboat.com,(2015)

2 )
Software programs perform the necessary computational work.Two EMA lines are presented below calculated using two different periods ( Red = 12, Blue = 26 ).Software platforms generally place the EMA indicators alongside the existing candlestick formations as depicted in the diagram.The EMA "Blue" line with a longer period setting follows the upward trend, lagging below and forming an angled support line until the trend begins to reverse its direction.The "Red" EMA line, with period setting 12, reacts more quickly and is embedded inside the candlesticks, Forexboat.com,(2015).Block diagram for the Developed ESMA model The block diagram as illustrated by Fig. 1, demonstrates the presence of a reversible communication of information between the Broker Server (InstaForex) with the rest of the market participants.It sends the current market state information to the client's terminal, which in turn, receives orders from it.This communication with the market participants here is dependent on the Internet connection of the trader.A very stable Internet connection is crucial for a timely order execution and for obtaining the most current market information.The client interface contains the program environment, a set of parameters with information about the market state and about the relations between the trader and the Broker Server.These parameters include the information about the current prices, the limitations on the maximum and minimum order size, the minimum distance of stop orders, the allowance and prohibition of the automated trading, and many other useful parameters characterizing the Current state.The program environment is updated when new ticks are received by the interface through the instructions input.

Fig. 1 :
Fig. 1: Block diagram for the developed model development of the ESMA trading model was carried out using the MetaTrader 4 environment, the results of the tests carried out using the historical data acquired, Training and Optimization of the model in the Meta Trader4 environment, the discussions on the outcome of the tests are discussed as seen in Figures 2 and 3. Optimization of the ESMA model and Training Parameter settings Optimization is testing different values and combinations of input parameters to obtain the best result.Optimization denotes successive passes of the same expert with discrete inputs applied on the same data.Hence, the parameters can be said to make the expert efficiency maximal.During the selection of the parameters, One has to select expert the parameters of which should be optimized in the "Tester -Experts" window.

Fig. 2 :
Fig. 2: The "Tester" environment for testing of the ESMA model

Fig. 4 :
Fig.4: ESMA Expert Model Testing As deduced from Fig.5 above, the number of trades executed and their corresponding profits for the five weeks testing on a demo trade with account balance of 10000 USD, the profit margin (%) was

Fig. 6 :
Fig. 6: Chart showing varying periods of Exponential and Simple Moving averages with the ESMA model