\section{Introduction}
The Foreign Exchange, also known as Forex, is a decentralized global market with trillions of dollars of daily turnover~\cite{britanicaforex}. Some unique features of the Forex market make it highly suitable for technical analysis and algorithmic trading~\cite{thompson2017time}. Technical indicator functions are popular heuristics used by Forex traders to identify trading opportunities. Multiple research efforts have been focusing on the proof of efficiency of certain existing indicator functions for fixed trade setups~\cite{yazdi2013technical,5358946, krishnan2009impact,yong2015technical,ozturk2016heuristic,yazdi2012technical,ni2009exchange}. However, as we demonstrate in Section~\ref{section:preevaluation}, the values of popular indicators are different for different data sets and brokers. This compromises the accuracy of machine learning of the historical Forex data and impedes the development of concrete recommendation for the traders. Moreover, we also demonstrate that the indicator heuristics reduce the overall count of trade opportunities, and thus reduce the final profit.

In this paper, we develop two dataset-agnostic price-action heuristic templates for trade signals on the Forex Exchange market: \emph{candle trend continuation} and \emph{candle trend reversal}. These heuristics are characterized by a very high rate of trading opportunities, compared to popular technical indicators. The ultimate goal of this work is to determine most optimal parameters for the given heuristic templates for each combination of Forex instruments and trade periods given in the input data set. In order to achieve that goal, we develop \mbox{\textsc{SmartFX}}\xspace, a machine learning tool which analyzes 10 years of historical Forex price data over three low-margin instruments and 6 different OHLC granularities, delivering a specific and reproducible list of most optimal trade parameters found for each input granularity of each instrument.

\subsection{Motivation}

Although the research and analysis of the Forex market is abound with original approaches, the practical application of these approaches is challenged by the ambiguity of results, unrealistic assumptions, or simply the lack of proper methodology for historical data analysis~\cite{rosenstreich2005forex,guides2017personality}.

Thus, the motivation of this work is to deliver a clear, specific, evidence-supported, realistic, and reproducible practical trading model with concrete parameters that can be applied by all tiers of Forex traders.

\section{Background}

\subsection{Definitions}

\paragraph{Foreign Exchange (Forex)} The Foreign Exchange is a global market in which national currencies and some commodities are exchanged~\cite{britanicaforex}.

\paragraph{Forex Instrument (Forex Pair)} Forex Instrument is a pair of equities, which are either
currencies (e.g. U.S. Dollar) or commodities (e.g., gold). For example, the pair EUR/USD is a Forex instrument for trading U.S. Dollars for Euros and vice versa. Some examples of Forex instruments are given in Table~\ref{table:instruments}. The taxonomy of Forex pairs includes several types, such as \emph{major pair} or \emph {cross pair}, but they are all traded in the same manner.

\paragraph{Pip} Pip is a small unit of price movement (change) in the Forex market. The value of one
pip is different depending on the instrument. For EUR/USD 1 pip = 0.0001,
for USD/JPY and EUR/JPY, 1 pip = 0.01.

\begin{table}[]
\caption{Examples of Forex instruments and their types.}
\label{table:instruments}
\begin{tabular}{|l|l|l|}
\hline
\textbf{Instrument} & \textbf{Description}               & \textbf{Type} \\ \hline
EUR/USD             & Euro/U.S. Dollar                   & major pair    \\ \hline
USD/JPY             & U.S. Dollar/Japanese Yen           & major pair    \\ \hline
EUR/JPY             & Euro/Japanese Yen                  & cross pair    \\ \hline
GBP/AUD             & Pound Sterling/Australian Dollar   & cross pair    \\ \hline
NZD/CAD             & New Zealand Dollar/Canadian Dollar & cross pair    \\ \hline
XAU/USD             & Gold/U.S. Dollar                   & commodity     \\ \hline
XAG/USD             & Silver/U.S. Dollar                 & commodity     \\ \hline
\end{tabular}
\end{table}


\paragraph{Long trade} The Forex market allows two trade directions: buying and selling. The buying trade is commonly called a \emph{long trade}.

\paragraph{Short trade} The Forex market allows to submit a selling trade even if there is no active buying trade; for a trader it may be perceived as betting on a downward price trend or as a reverse trade. Regardless of the trader's perception, the selling trade is commonly called a \emph{short trade}.

\subsection{Spread}
Many Forex brokers do not charge any direct per-trade commission. Instead, they establish a difference between the buying price (called the \emph{ask price}, denoted $P_a$) and the selling price (called \emph{bid price}, denoted $P_b$). Then the \emph{spread} of a broker $\beta$ for an instrument $i$, denoted $P_{\beta,i}$, is defined as follows\footnote{In some literature, the spread is represented as a negative value. We use the absolute value notation to emphasize the simple fact of the difference, regardless of its sign.}:
$$
S_{\beta,i} = |P_b - P_a|
$$

\subsection{Margin trading}
In most days when the market is open, the Forex prices experience only minor fluctuations, which would require traders to make very large deposits in order to gain a feasible profit. In order to make price movement more influential, most Forex brokers allow for \emph{margin trading}, in which the broker lends the client an amount of money $V_{m}$, called the \emph{margin}, which is $M$ times greater than the actual deposit $D$, thus:
$$
V_{m} = M \times D
$$

The value $M$, usually denoted $M:1$, e.g., 1:50, is called the \emph{leverage}. Most Forex brokers in the United States offer the 1:50 leverage.


\subsection{OHLC Candlestick Data}

The raw Forex price data is usually provided by a broker in the form of a series of \emph{ticks}. Each instrument has its own stream of ticks, and each tick includes a timestamp, bid price, ask price, and an optional trade volume data. Depending on the broker and its API, the period between ticks can vary between 50 ms to several seconds. The tick data is necessary for trading, but in most cases it is overwhelmingly excessive for a technical analysis. Thus, a more analysis-friendly cmopressed form, called \emph{OHLC candlestick data}, is commonly used in most markets, including Forex.

OHLC (Open, High, Low, Close) data is a set of points, called \emph{OHLC candles}, \emph{OHLC candlesticks}, or \emph{OHLC ticks}, summarizing the price movement during a fixed period of time using four parameters: 1) price at the beginning of the period (O); 2) maximum price during the period (H); 3) minimum price during the period (L); and 4) the price at the end of the period (C). Figure~\ref{fig:candlesticks1} demonstrates the chart and CSV representations of OHLC data. The period of time that one candle spans in a data set is called the \emph{OHLC granularity}. Common OHLC granularities for the Forex market are: M1 (1 minute), M2 (2 minutes), M5 (5 minutes), M10 (10 minutes), M15 (15 minutes), M30 (30 minutes), H1 (1 hour), H2 (2 hours), H4 (4 hours), H8 (8 hours), H12 (12 hours), D1 (one day), W1 (one week), and MN (one month).

\begin{figure}[H]
    \centering
    \includegraphics[width=3.3in]{img/candlesticks1.png}
    \caption{The OHLC candlestick data in chart and comma-separated value (CSV) representations.}
    \label{fig:candlesticks1}
\end{figure}

\subsection{Forex Analysis}
The goal of a the Forex analysis is to predict the future movement of the price and identify trading opportunities. There are two major types of the market analysis: a) the \emph{fundamental analysis} and b) the \emph{technical analysis}. The fundamental analysis uses economic, political, and other news data to predict the future behavior of the market. The technical analysis uses present and past movement of the market price to infer the future move of the price, regardless of any outside (fundamental) events. Many traders also use various combinations of the fundamental and technical analyses. The technical analysis may be based on heuristic functions called \emph{technical indicators}, or it can be based solely on the past and present values of the price. The latter case is called the \emph{price-action}. \mbox{\textsc{SmartFX}}\xspace focuses on the pure price-action technical analysis only.

\section{Related Work}

    \subsection{Research}
Automated Forex exchange trading is a popular topic among peer-reviewed studies~\cite{de2012comparative,5358946,yazdi2013technical,8096360,wilson2010interday,pinto2012strategic}. In the last two decades, many studies have been conducted on different aspects of foreign exchange technical indicators~\cite{vezeris2019adturtle,5358946,yazdi2013technical,8096360,wilson2010interday,pinto2012strategic}. Many patents have been filed for automatic Forex trading systems~\cite{schoen2011automated,chait2007foreign,peterson2005foreign,ogg2005automated,owens2005automated}. Also, the Artificial Intelligence and Machine Learning has been used for price prediction of the Foreign Exchange market~\cite{983110,abraham2001intelligent,czekalski2015ann,lee2014hidden,yazdi2013technical,barbosa2010multi,shahbazi2016forex}.

However, the number of combinations of possible settings, as well as the abundance of pre-existing constraints for Forex automated trading is virtually infinite. As the number of constraints is growing, the necessity to employ the methods of Artificial Intelligence and Machine Learning becomes an urgent necessity because the space and time complexity of a brute-force trial exceeds storage and computational abilities of existing computers. To the best of my knowledge, none of the existing studies delivers a complete set of trading parameters for automated or semi-automated Forex trading with low equity and other parameters representing a non-institutional trader.
    
\subsection{Trading Heuristics}

Most popular heuristics for technical analysis are technical indicators~\cite{ozturk2016heuristic}. For example, one of the largest Forex brokers in the United States, GAIN Capital Group LLC~\cite{macerinskiene2015evidence}, provides 75 classes of technical indicators as part of its Web Trading Platform~\footnote{https://webtrader.forex.com/workspaces/default}.
    
\subsection{Retrospective Simulation}

The retrospective simulation of Forex trading is a software-based processing of historical Forex price data, using a given trade model and a set of heuristics. There is a number of software trade simulators available on the market, such as MetaTrader\footnote{https://www.metatrader4.com/en}, NinjaTrader\footnote{https://ninjatrader.com/Simulate}, Forex Tester\footnote{https://forextester.com/}, Soft4Fx\footnote{https://soft4fx.com/}, fxSimulator\footnote{https://fxsimulator.com/}, and others. All these tools allow to test a given strategy, automatically or manually, using a historical data. However, to the best of my knowledge, none of these tools is capable of \emph{calculating the most optimal strategy}, which is the main goal of \mbox{\textsc{SmartFX}}\xspace.
    
\subsection{Other Works}

There are multiple books written on the topic of Forex trading optimization. The "forex trading" search result at the Book Department of Amazon web store returns more than 6,000 results\footnote{https://www.amazon.com/s?k=forex+trading}. The same search request on a popular platform for online video courses, Udemy, returns 3,934 results\footnote{https://www.udemy.com/courses/search/?src=ukw\&q=forex\%20trading}.

\section{Pre-Evaluation}\label{section:preevaluation}

\subsection{Inconsistency of Technical Indicators}

Moving Average Convergence/Divergence (MACD) is one of the most popular technical indicators among Forex traders~\cite{yazdi2013technical}. However, different data sets and different trading tools reveal significant differences between the actual values of popular technical indicators, and this is easily demonstrable by comparing the charts of MACD for the same instrument with the same OHLC granularity within the same time frame, with time zone differences properly synchronized.

For this experiment, we observe four charts of the MACD technical indicator, produced by different trade tools with the same parameters (fast MA: 12, slow MA: 26, length: 9) generated for 24 OHLC H1 candlesticks representing the Forex price during November 28, 2019 EST, accounting for the differences in time zones\footnote{Two out of four data sets used the GMT time zone, which was shifted to match the EST time zone.}. As we can see in Figure~\ref{fig:preeval}, there is a significant differences between the MACD indicators with the same parameters over the same time period. One reason for such a discrepancy may be the fact that November 28, 2019 was the Thanksgiving Day in the United States, during which the trading activity is very low, whereas in most other countries it was just a regular business day, resulting in Forex activity difference in brokers from different regions (which has some effect upon the price). Regardless of the reason, the experiment demonstrated that \emph{there was at least one day, during which MACD showed significantly different results for different brokers}.

\begin{figure}[H]
    \centering
    \includegraphics[width=1.5in]{img/macd-mt4-win.png}~~~
    \centering
    \includegraphics[width=1.5in]{img/dukascopy-macd.png}\\
    ~(a) Forex.com/MT4~~~~~~~~~(b) Dukascopy Demo/JForex\\
    \vspace{0.5cm}
    \centering
    ~\includegraphics[width=1.5in]{img/oanda.png}~~~
    \centering
    \includegraphics[width=1.5in]{img/mt5.png}\\
    ~~~~~~(c) Oanda/iOS~~~~~~~~~(d) Metaquotes Demo/MT5 iOS\\

    \caption{MACD charts produced by different trading tools, which use different data sets for the same period of time (November 28, 2019 00:00---November 28, 2019 23:59, EST, adjusted for differences in time zones) of the same Forex instrument (EUR/USD) with the same OHLC granularity (H1).}
    \label{fig:preeval}
\end{figure}


\subsection{Trade Opportunities Rate Reduction}

In this work, we propose a price-action trade model, in which every OHLC candle, upon its closure time, delivers a new trade signal. For example, for the H1 OHLC granularity, the number of trading signals per day is 24. In other words, in \mbox{\textsc{SmartFX}}\xspace the signal period $T_{SmartFX}$ is constant and equal to the granularity $G$:
$$
T_{SmartFX} = G
$$

When the trade signals come from traditional technical indicators, the trade signal period $T_{ind}$ is variable, and presumably many times larger than $G$. In order to demonstrate this, we conducted a short experiment, in which we counted the number of possible configurations for MACD and RSI technical indicators that can be treated as signals over one month of historical Forex data (November 2019, EUR/USD) with OHLC granularity H1. Table~\ref{table:macdrsi-experiment} shows the results of this experiment.

\begin{table}[H]
\caption{Number of trade signal signatures per month produced by MACD, RSI, and \mbox{\textsc{SmartFX}}\xspace  for EUR/USD pair with OHLC granularity H1, counted during November 2019. For \mbox{\textsc{SmartFX}}\xspace, se assume that there are 20 full days when the Forex market is open during the month.}
\label{table:macdrsi-experiment}
\begin{tabular}{|c|l|c|}
\hline
\multicolumn{1}{|l|}{\textbf{Heuristic}} & \textbf{Heuristic Parameters}                                                 & \multicolumn{1}{l|}{\textbf{\begin{tabular}[c]{@{}l@{}}Number of Signal\\ Signatures During \\
November, 2019 \\
\end{tabular}}}\\ \hline
MACD                                     & \begin{tabular}[c]{@{}l@{}}Fast MA: 12\\ Slow MA: 26\\ Length: 9\end{tabular} & 55                                                                                                             \\ \hline
RSI                                      & Length: 14                                                                    & 64                                                                                                             \\ \hline
\mbox{\textsc{SmartFX}}\xspace                                  & N/A                                                                           & 480                                                                                                            \\ \hline
\end{tabular}
\end{table}

Let us show that on average the technical indicators produce less trade signals than \mbox{\textsc{SmartFX}}\xspace. Suppose that there is a set of parameters $\Upsilon$ for a traditional technical indicator $I$, which is twice as more successful than \mbox{\textsc{SmartFX}}\xspace (with the same take-profit/stop-loss settings), and which also produces twice as more trade signals than RSI-14. Then, if the average proportion of successful trades for \mbox{\textsc{SmartFX}}\xspace is $N_{SmartFX} (0 \le N_{SmartFX} \le 1)$, then the number of successful trades per month for \mbox{\textsc{SmartFX}}\xspace will be as follows:

$$
ST_{SmartFX} = 480 \times N_{SmartFX}
$$

Whereas the number of successful trades for the hypothetical indicator will be as follows:

$$
ST_{I(\Upsilon)} = 2 \times (2 \times 64 \times N_{SmartFX}) = 256 \times N_{SmartFX} 
$$

As it is seen from the experiment, even with unrealistically optimistic assumptions, $ST_{SmartFX} > ST_{I(\Upsilon)}$. And therefore it is fair to conclude that even if the traditional technical indicators have higher rate of successful signals, the decreased overall number of trading opportunities yields a lower overall profit compared to per-candle price action.



\section{SmartFX Design}

Figure~\ref{fig:smartfxdesign} demonstrates the basic design of \mbox{\textsc{SmartFX}}\xspace. The market data, which is described in detail in Section~\ref{section:dataset}, is being pre-processed to facilitate the performance of the simulation. Specifically, the market data is being saved twice in two different data structures: hash table and serial list. This allows to reduce the processing time because the latter is the system's performance bottleneck.

\begin{figure}[]
    \centering
    \includegraphics[width=3.2in]{img/smartfxdesign.png}
    \caption{An overview of the \mbox{\textsc{SmartFX}}\xspace design. The market data, which consists of several subsets, is pre-processed for performance optimization by generating an auxiliary hash maps for the data subsets. The pre-processed data is used by the generator of heuristics, along with the set of heuristic prototypes and constant parameters (e.g., broker's spread). The generated heuristics are fed to the multi-threaded trade simulation learning algorithm, along with a set of constraints (representing the trader), and the trade model (representing the rules of the Forex market). The results of the simulation are being analyzed to produce a set of the most optimal trading parameters.}
    \label{fig:smartfxdesign}
\end{figure}

The pre-processed market data goes to the generator of the set of heuristics, along with the set of heuristic prototypes and constant parameters (or assumptions). The two heuristic prototypes are presented in Algorithm~\ref{alg:alg1} and Algorithm~\ref{alg:alg2}. The constant parameters include: maximum total loss allowed in pips, maximum take profit, maximum stop loss, take profit and stop loss steps, and the broker's spread.

The fist heuristic prototype, called the \emph{trend continuation heuristic}, denoted as $h_{1}$, simply signals a long trade at the end of a ``green'' candle period, and it signals the short trade otherwise. The second heuristic prototype, called the \emph{trend reversal heuristic}, denoted as $h_{2}$, signals a short trade at the end of a ``green'' candle period, and it signals a long trade otherwise. It is important to note that in order to avoid risks, only one trade at a time can be placed in \mbox{\textsc{SmartFX}}\xspace model.

 \begin{algorithm}[]
 \caption{Trend Continuation Heuristic $h_1$}
 \label{alg:alg1}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{INPUT:}}
 \renewcommand{\algorithmicensure}{\textbf{OUTPUT:}}
 \REQUIRE $O, H, L, C$
 \ENSURE  trade decision
  \IF {no current trades}
  \IF {$C > O$}
  \RETURN long trade
  \ELSIF {$C < 0$}
  \RETURN short trade
  \ELSE
  \RETURN no trade
  \ENDIF
  \ENDIF
 \end{algorithmic}
 \end{algorithm}

\begin{algorithm}[]
 \caption{Trend Reversal Heuristic $h_2$}
 \label{alg:alg2}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{INPUT:}}
 \renewcommand{\algorithmicensure}{\textbf{OUTPUT:}}
 \REQUIRE $O, H, L, C$
 \ENSURE  trade decision
 \IF {no current trades}
  \IF {$C < O$}
  \RETURN long trade
  \ELSIF {$C > 0$}
  \RETURN short trade
  \ELSE
  \RETURN no trade
  \ENDIF
  \ENDIF
 \RETURN no trade
 \end{algorithmic}
 \end{algorithm}


When the set of heuristics is generated, they go to the trade simulation algorithm along with the trade model (which represents the rules of the Forex market) and the set of constraints (which represents the parameters of a Forex trader). The trade model, constraints, and the set of heuristics are the same for each subset of the market data. The subsets of market data are formed by combining all the given instruments with all the given OHLC granularities. Each subset of data can be independently processed by the trade simulation algorithm, thus this algorithm can be run in a multi-threaded environment.

Each simulation thread maintains its own log of results, which is analyzed to determine the set of optimal parameters. Then the sets of all optimal parameters for each subset of the market data are processed manually in a spreadsheet software.


\section{SmartFX Implementation}

\mbox{\textsc{SmartFX}}\xspace is a multi-threaded open-source tool written in Java, totalling 859 lines of code. The value of spread is fixed and set to 2.0 pips. The software performs data preprocessing and generation of heuristics in a linear fashion. However, the most computation-consuming part, the trade simulation learning, is performed in a dedicated thread for each subset of the market data.

The range of the values of the stop loss (SL) parameter is set to [3,50]. The same range is used for the take profit (TP) parameter, accounting for 2,209 distinct $(SL,TP)$ tuples. We stochastically determined that the largest ranges are not likely to yield any combinations with better efficiency. Moreover, higher values of TP reduce the number of trades, whereas larger value of SL increases the risk of unexpected large loss of profit.

\section{Data Set}\label{section:dataset}

We use 18 subsets of historical Forex data from the Dukascopy Swiss Banking Group data set\footnote{https://www.dukascopy.com/swiss/english/marketwatch/historical/}. The subsets are tuples $(\eta, G)$, where $\eta$ is a Forex instrument, and $G$ is a granularity, such that:
$$
\eta \in \{EUR/USD, USD/JPY, EUR/JPY\}
$$
$$
G \in \{H1, H2, H4, H8, H12, D1\}
$$

Each subset is stored in a comma-separated value (CSV) data file. Each CSV entry includes the OHLC candlestick data. The entries also include the trade volume data, but this parameter is ignored by \mbox{\textsc{SmartFX}}\xspace.

\mbox{\textsc{SmartFX}}\xspace records the following parameters for each of the 36 runs (18 subsets of market data processed with each of the two heuristic prototypes) during the learning simulation: a) total profit in pips; b) total loss in pips; c) heuristic used; d) take profit (TP) policy simulated; e) stop loss (SL) policy simulated; f) number of long trades; g) number of short trades; h) Forex instrument; and i) granularity of OHLC data.


\section{Evaluation}

\subsection{Setup and Run}

We used a Dell PowerEdge T640 server with two Intel Xeon Gold 5218 processors and 200 GB of RAM, running Ubuntu 18.04.03 LTS. The \mbox{\textsc{SmartFX}}\xspace tool was executed in two separate processes, each running 18 threads (36 threads total). The first process was resposible for the heuristic $h_1$, and the second process was responsible for the heuristic $h_2$. The choice to run the tool in two multi-threaded processes was determined by implementation convenience, and was not intended to achieve any performance improvement. The length of the entire cycle for all data subsets took about two hours.

\subsection{Results}

The raw results of \mbox{\textsc{SmartFX}}\xspace execution are recorded in the Appendices, and below are the most essential summaries and explanations.

\subsubsection{Worst Performers}

Table~\ref{table:worstperformers} presents the four worst 10-year balances. It is important to note that these cases are worst compared to other cases, but they are best cases locally. For example, the first row indicates that the best combination of take profit and stop loss values for the EUR/JPY instrument for OHLC H2 granularity and trade continuation heuristic could maximize the ending balance only to the value of -75,380 pips. As we can see, all the four worst performers use the trend continuation heuristic prototype. The performance of the two heuristic prototypes is discussed later in this section.

\begin{table}[]
\caption{Four simulations that resulted in lower 10-year ending balances.}
\label{table:worstperformers}
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Instrument} & \textbf{Period} & \textbf{Heuristic} & \textbf{10-year Balance (pips)} \\ \hline
EUR/JPY             & H2              & $h_1$                 & -75,380                  \\ \hline
EUR/JPY             & H4              & $h_1$                 & -41,338                  \\ \hline
EUR/USD             & H4              & $h_1$                 & -39,953                  \\ \hline
EUR/USD             & H2              & $h_1$                 & -29,397                  \\ \hline
\end{tabular}
\end{table}

\subsubsection{Best Performers}
\label{section:bestperformers}

The best four performers, shown in Table~\ref{table:bestperformers}, all use the trend reversal heuristic prototype. Also, the best four performance have finer OHLC granularities than the four worst performing cases. As we can see from the table, the \mbox{\textsc{SmartFX}}\xspace model can deliver on average up to 118 pips of profit. The performance of the two heuristics is discussed in later in this section.

\begin{table}[]
\caption{Four simulations that resulted in best 10-year ending balances.}
\label{table:bestperformers}
\begin{tabular}{|l|l|l|l|l|}
\hline
\textbf{Instrument} & \textbf{Period} & \textbf{Heuristic} & \textbf{\begin{tabular}[c]{@{}l@{}}10-year\\ Balance (pips)\end{tabular}} & \textbf{\begin{tabular}[c]{@{}l@{}}Avg. pips\\ per day\end{tabular}} \\ \hline
EUR/JPY             & H1              & h2                 & 432,192                                                                   & 118.31                                                               \\ \hline
EUR/USD             & H1              & h2                 & 348,611                                                                   & 95.43                                                                \\ \hline
EUR/JPY             & H2              & h2                 & 302,022                                                                   & 82.68                                                                \\ \hline
USD/JPY             & H1              & h2                 & 293,121                                                                   & 80.24                                                                \\ \hline
\end{tabular}
\end{table}

\subsubsection{Number of Trades}

Table~\ref{table:numberoftrades} summarizes the number of trades statistics among the top 4 performers discussed before in this section. We are interested in the number of trades only for top performers because they are the ones to be used in real trades. However, the information about the number of trades for the remaining cases is available in Appendix~\ref{appendix:numberoftrades}.

\begin{table}[]
\caption{Number of trades over the 10-year learning simulation period averaged between the four highest performing simulations, and also the calculated average number of trades per day among the top four performers.}
\label{table:numberoftrades}
\begin{tabular}{|l|l|l|}
\hline
\textbf{Average among the top four performers}                                     & \textbf{Value} & \textbf{$\mathbf{\sigma}$} \\ \hline
Number of trades over 10 years & 48,078         & 12,641 \\ \hline
Average number of trades per day & 13.16          & --- \\ \hline
\end{tabular}
\end{table}

\subsubsection{Heuristics Performance}\label{section:heuristics-performance}

The best possible performance of the two heuristics is summarized in Table~\ref{table:heuristicperformance}. As we can see, the performance of the trend reversal heuristic is much better than of the trend continuation one. Also, we observe smaller average number of trades for the trend continuation heuristic. It is also worth mentioning that, as it is seen in Table~\ref{table:appendixA}, among all the 21 cases with positive final balances, only three are produced by the trend continuation heuristic, and all these cases are among bottom five performers with positive balances. 

\begin{table}[]
\caption{Summary of best possible performance of the two heuristic prototypes.}
\label{table:heuristicperformance}
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{\begin{tabular}[c]{@{}l@{}}Heuristic\\ Prototype\end{tabular}} & \textbf{\begin{tabular}[c]{@{}l@{}}Average 10-year\\ Balance (pips)\end{tabular}} & \textbf{\begin{tabular}[c]{@{}l@{}}Avg. Number of \\ Trades over 10 years\end{tabular}} & \textbf{$\mathbf{\sigma}$} \\ \hline
$h_1$                                                                    & -10,574                                                                           & 15,101                                                                                  & 13,997         \\ \hline
$h_2$                                                                    & 186,869                                                                           & 19,007                                                                                  & 18,399         \\ \hline
\end{tabular}
\end{table}


\subsubsection{Optimal TP/SL Settings}

Table~\ref{table:optimal-ttsl} is the culmination of this research, delivering the set of optimal trading settings that allows to achieve the best profit results.

\begin{table}[H]
\caption{Optimal TP/SL parameters for the top 7 most profitable simulation cases.}
\label{table:optimal-ttsl}
\begin{tabular}{|l|l|l|l|}
\hline
\textbf{Instrument} & \textbf{Period} & \textbf{\begin{tabular}[c]{@{}l@{}}Take Profit\\ (pips)\end{tabular}} & \textbf{\begin{tabular}[c]{@{}l@{}}Stop Loss\\ (pips)\end{tabular}} \\ \hline
EUR/JPY             & H1              & 3                                                                     & 14                                                                  \\ \hline
EUR/USD             & H1              & 3                                                                     & 11                                                                  \\ \hline
EUR/JPY             & H2              & 3                                                                     & 20                                                                  \\ \hline
USD/JPY             & H1              & 3                                                                     & 9                                                                   \\ \hline
EUR/USD             & H2              & 3                                                                     & 16                                                                  \\ \hline
EUR/JPY             & H4              & 3                                                                     & 28                                                                  \\ \hline
USD/JPY             & H2              & 3                                                                     & 13                                                                  \\ \hline
\end{tabular}
\end{table}


\section{Discussion}
\mbox{\textsc{SmartFX}}\xspace is purposefully designed to be broker-agnostic, which allows to develop trading setups that are universally applicable to diverse trading environments. However, this decision comes at a cost of the necessity to specify a fixed spread value, whereas many Forex brokers use floating spread policy. As a result, the user of \mbox{\textsc{SmartFX}}\xspace must specify the spread that is large enough. Although the static spread value does not compromise the quality of the result produced by \mbox{\textsc{SmartFX}}\xspace, the parameter must be chosen carefully in order to avoid overly optimistic scenarios.

\section{Conclusion}
Market trading optimization is a popular application of Artificial Intelligence (AI), delivering endless opportunities for research and profound insights. The Forex market is often being chosen as a target environment because it allows unlimited spread-based day trading without additional fees, long market hours, and easy entrance requirements. In this research, we demonstrated that popular technical indicators may be ambiguous and less optimal for automated trading. We developed \mbox{\textsc{SmartFX}}\xspace, an automated constraint-based machine learning tool that determines optimal parameters for given heuristic prototypes.

We evaluated 10 years worth of market data for 3 popular Forex instruments using two simple price-action heuristic prototypes, along with 6 different OHLC granularities of the input data. The results clearly demonstrated that the trade reversal price-action heuristic is significantly more profitable than the trade continuation, and capable of delivering up to 118 pips of profit per day on average. We determined exact trading parameters for the optimal trade, and thus achieved the goal of this research: to deliver practically working, specific and evidence-based optimal trade parameters for price-action Forex trading. We make \mbox{\textsc{SmartFX}}\xspace available under an open source license for everyone to use, evaluate, and build upon.

\clearpage
\bibliographystyle{IEEEtran}

