Building a simulator for forex trading

TomHortons
24 min readMar 2, 2023

--

This article introduces the construction of an environment for analyzing forex information using these platforms. I used Meta Trader 5 (MT5) as my trading platform and built an application that communicates with MT5 to control trades.

In my last article I introduced a platform that integrates data analysis and simulation. This is the environment I use when I am private and not bound to an analytical platform. I use DVC, an open-source data version control system, as a reference, and manage the algorithms for automatic control as Strategy. Strategy integrates the analysis in Notebook, the evaluation in simulation, and the work of actually running the application.

There are three tasks required to run Strategy for forex trading: 1. design the Strategy, 2. recreate the account information, and 3. integrate the Strategy with the recreated account information. This allows me to build a common mechanism for Notebook, simulation, and application.

In addition, I will create a simulation environment for Strategy, 4. build a reproduction of MT5 in the simulation. The uses and purposes of the simulation are detailed in previous articles; I will build it as a means to better understand the background of the data during the exploration phase of the Strategy. Finally, I will introduce the 5. basic valuation metrics used in forex trading, which do not use Strategy’s internal data, but are complete with trade information only.

The above content integrates the implementation of an analytical environment, simulation, and application for forex trading.

1. Strategy design

The first step is to determine the basic Strategy structure, which is a set of scripts in DAG format, with a specific order in which they are executed. More details can be found in previous articles.

In forex trading, Logic’s role seemed to fall into several distinct groups, so I divided it into five major ones. As long as the order in which the groups are executed is followed, the same results can be obtained.

FIg.1 Forex Trading Strategy

Fig. 1 shows the DAG containing five nodes. DAG is an ordered graph of program execution. Each node processes one or more Logic in any order.

Filter is a group of indicators that are processed together for the overall calculation. For example, if I wanted to use BollingerBands in the Entry and the Exit groups, I would add a Logic to the Filter that would perform the BollingerBands-related calculations. I considered jumping to End without executing further processing if the Filter condition is not met. However, for the sake of convenience when analyzing the simulation results, I have settled on the current state.

Exit is executed when a position is held. Exit is usually one Logic, sometimes more than one Logic when I want to add a pSAR or trailing stop. I also update the Take Profit & Stop Loss (TPSL) of the position I am holding in the Exit group.

Entry determines Buy and Sell signals literally. It is also executed when a position is already held. However, since holding positions in different currency-pairs simultaneously in a single account complicates the management of margin level, it basically does nothing when a position is held.

The Controller organizes the results of Exit and Entry and makes the final decision. If more than one Logic is present in Entry or Exit, there may be discrepancies in decision making. the decision is made when any one Logic makes a decision to manipulate the position. The Controller is responsible for overall decision in such cases.

Money Management (M2s) determines the number of lots to buy when a Buy or Sell signal is given. For examle, fixed lots for evaluation, x% of equity, and the use of an expected value table that analyzes the win rate and Pips range of the entry pattern.

Fig.2 Currently used forex trading strategy

Currently, in addition to Fig. 1, I have included temporary parameters in the Setting node (FIg. 2), that calculate dynamically changing rule.
For example, leverage limits vary depending on the asset situation, but since the limit rules cannot be automatically retrieved from the account information, they are calculated here. I also check the time difference between the Tokyo and New York markets from the broker’s base time. Daylight saving time changes from one country to another, so if you want to know the exact time difference, you can calculate it here.

In addition to DAG, there are several other settings in Strategy.
For example, Logic parameter information. If you want to evaluate a parameter in a simulation, you intentionally design Logic to read it, and Strategy requires you to set this parameter in advance. Also, the maximum window size is determined when building the Strategy. Strategy also specifies the main timeframe and the upper timeframes.

It is important to note that Strategy and account information are completely independent of each other; even when Strategy determines the number of lots based on the account balance, the balance figures are managed independently by the Account class, which is introduced next section. This is true not only for analyzing data from forex trading, but also for handling any kinds of data.

2. Reproducing MT5 account information

The execution of the Strategy requires MT5 state management. As a mechanism to reproduce the internal state of MT5, I will design an Account class that operates in the same way as an MT5 client. The design of the account class varies greatly depending on the target platform, and a very deep understanding of the data is gained through the design process.

Fig.3 Diagram of MT5 account information

First, I have divided some basic information of MT5 into four groups for ease of understanding in Fig. 3. It should be noted that MQL, the MT5 programming language, uses a completely different classification scheme.

Main Property is the account settings information. It includes settings such as the name of the trade server provided by the broker, the currency of the deposit, and the type of account. It also includes leverage limits. This information does not change regardless of the state of the equity.

Margin Property is the information set when a position is held. SO SO (Stop Out) is the lower limit of the margin level. If you get too greedy and the margin level falls below the lower limit, you will be forced to close your position. SO SC (Stop Call) is the stop call, and if the margin level falls below the broker’s specified limit, various restrictions will occur. Again, Margin Property does not change regardless of the outcome of the trade.

Account is the account balance. There are several types of “balance. When you deposit money into your account, your Balance will increase by that amount. Equity is the sum of the unrealized gains or losses on the positions you hold and your Balance. Various promotions offered by brokers are added as Credit, which is a virtual asset that cannot be withdrawn, and the sum of Equity and Credit is Margin Free. The Margin Free is the sum of Equity and Credit. Since the margin level is calculated from the Margin Free, the more Credit you have, the more positions you can purchase with less assets.

Position is the information of the positions purchased. Margin is the amount of positions held, Margin Level is the margin maintenance rate calculated from Equity and Margin, and Profit is the unrealized profit and loss.

Of these pieces of information, position information is somewhat unique. As Meta Trader users know, Meta Trader allows positions associated with the same account to be handled under different conditions. These conditions are the device, the Meta Trader terminal, and the automated trade (EA). Therefore, there are situations where a controlled account may have positions that were purchased by means completely unrelated to the Strategy. Also, during the course of actual operation, the automated trades may behave unexpectedly and modify the positions purchased by the Strategy.

Thus, position information may be fine in the simulation, but may behave unexpectedly in the actual operation. To prevent unexpected malfunctions during operation, Strategy execution is independent from MT5 position information.

Fig.4 Relationship between Account and Position Data

The Trade class connects MT5 and Firestore position information.
Fig.4 shows how the Account class handles trade information. The Strategy uses only the position data read from Firestore for its execution.
Thus, position operations are independent of account information to some extent in the Account class, and are managed as a Trade class. The Magic Number (MN) parameter can be specified for position purchases, and only positions filtered by the MN are stored in the Firestore.

Apart from the manipulation of position information, the core reproduction of account information is the calculation of the impact of positions on assets. In the following sections, I will introduce the elements necessary to simulate MT5 account information: 2.1. calculating profit/loss using pip value, and 2.2. calculating margin level.

2.1. Profit and Loss calculation using Pip Value

Fig. 5 Profit and loss calculation using Pip Value

Pip Value is a coefficient used to calculate profit and loss, and it seems to be one of the most common stumbling blocks for traders who are just getting into automated trading. Using Pip Value, you can intuitively calculate the profit/loss of a currency pair without being tied to Buy or Sell, as shown in Fig. 5.

Pip Value is defined as “the profit/loss when one lot changes by one pip. In other words, if the Pip Value is $10 and the number of lots in the position is 15, the profit when you win 18 pips is 10 * 18 * 15 = $2700 (Fig.5). This calculation is the same for both Buy and Sell; the formula for Pip Value depends on the combination of the currency pair you are trading and the currency of your account (deposit currency). I will see how to derive it in the following sections.

Fig.6 Currency Pair Structure

Pip Value is determined from the currency pair and the deposit currency. The deposit currency is the currency you have deposited into your account. The currencies on either side of the currency pair have various names depending on the industory. As shown in Fig. 6, this article refers to the Base Currency on the left and the Quote Currency on the right.

The Base Currency is only the currency in which the purchase was made, and the Quote Currency, the currency used for the purchase, is the target of the profit/loss calculation. In this example, the deposit currency is USD, the standard account, 1.5 lots of EURGBP are purchased, and the winning margin is 10 pips.

Fig.7 Example of profit/loss calculation without Pip Value

Fig. 7 shows a specific calculation example. PipPoint is the coefficient for converting pips to price. Here, to convert price to pips, I am multiplying by the reciprocal. The second step is the lot size of the currency pair to be traded. It is generally said that “a standard account will make a profit or loss of $10 per pip,” which is the value obtained by multiplying the LotSize by the Pip Point. The third factor is important: it converts the profit/loss of the Quote Currency (GBP) to the Deposit Currency (USD). Since the Deposit Currency is USD, it is multiplied by GBPUSD where USD is the Quote Currency.

The definition of Pip Value is “profit or loss per Pip in 1 lot. There are two things to consider when calculating Pip Value: first, whether the Quote Currency of the currency pair you are trading matches the deposit currency, and second, the Quote Currency of the currency pair that falls under Quote to Depo.

Fig.8 List of Currency Pairs and Pip Values

PipValue can be complicated to understand, so here is an overview of the calculation in Fig.8. GBPUSD has a Quote Currency of USD, which means that USDUSD is always 1 (although such a currency pair does not exist); EURAUD has a Quote Currency of AUD, and AUDUSD has a Quote Currency of USD, so they are multiplied together. USDJPY and CHFJPY have a Quote Currency of JPY and USDJPY is divided because the Base Currency is USD.

As the coloring result shows, there are three ways to calculate Pip Value. As for GBPUSD, if you consider USDUSD, there are just two ways to think about whether the Quote Currency of the Quote to Depo matches Depo or not.

This raises a few questions about the formula for calculating profit/loss. That is, does Quote to Depo use the price at the time the position is purchased or the price at the time the position is closed? It is obvious, but the rate at which the AUD profit earned by purchasing EUR is converted to USD is always fluctuating. In other words, it is natural that the Pip Value at the time of purchase of the position and the Pip Value at the time of settlement will be different.

The simulation profit/loss calculation uses the pip value at the time of settlement. Therefore, not only the price data of the currency pair to be traded, but also the price data of the currency pair consisting of the Quote Currency and the Deposit Currency are required to reproduce the account information.

2.2 Calculation of Margin Level

Margin level is an indicator that controls the health of a trade. If the margin maintenance ratio is below the threshold, greed is out of control and normal risk management is not in place. Conversely, if the margin level is too high, no matter how many trades are won, there is little profit in terms of overall assets. This is a wasteful trade that takes too little risk.

It is a good rule of thumb to determine your own target margin level based on the win rate and expected value of the strategy you have detected.

Fig.9 Relationship between Currency Pair and Margin

The margin level is calculated from the margin, which is calculated in a very similar way to the pip value (Fig.9). Let us consider the example of EURGBP.

Fig.10 Example of calculating Margin

The margin value can be calculated from the highlighted area in Fig. 10. The LotSize is fixed at 100,000 for standard accounts, and the leverage is 200x here. The first factor is to determine the leverage based on the size of the Equity and the contractual terms of the account, since leverage generally varies with the size of the Equity. The second row is the element that converts the EUR price purchased into the deposit currency. EURUSD is converted from EUR to USD because the deposit currency, USD, exists in Quote Currency. The third step is the number of lots.

Unlike Pip Value, Margin Value has nothing to do with pips and is much simpler than Pip Value because it only converts the value of the Base Currency to the Deposit Currency.

Fig.11 List of Currency Pairs and Margin Value

As with Pip Value, let’s check the calculation pattern of Margin Value (Fig.11). USDJPY has USD as Base Currency, which means USDUSD is always 1 (although such a currency pair does not exist). CADCHF has Base Currency of CAD, and USDCAD has Quote Currency of CAD, so it is multiplied by the inverse of USDCAD. EURUSD is also multiplied by EURAUD since the Base Currency is EUR and the Quote Currency is USD.

As with Pip Value, Margin Value can be calculated in three ways. As for USDJPY, if you consider USDUSD, there are just two ways to think of it: whether the Quote Currency of Base to Depo matches the Depo or not. In this respect, it is the same as Pip Value.

Fig.12 Example of Margin Maintenance Ratio Calculation

The Margin Free is the total assets that you have after taking into account the profit and loss of the positions you have, the bonus (Credit) provided by your broker, and the margin you already have. Fig. 12 shows an example with no position and with a position. For example, if Equity is $200,000 and the margin on the new position is $100,000, the margin level is 200%. If the margin on the existing position is $150,000, Equity is $200,000, and the margin on the new position is $100,000, the margin level is 50%.

3. Integration of Strategy and account information

Strategy does not have the ability to run Logic, it is just DAG information. Repository class that utilize MT5 account information is required to run Strategy along with price data.

The structure of the Account class will change significantly when you change the target to be reproduced to something other than forex trading. On the other hand, Repository has almost the same structure regardless of the data handled. Here we will introduce two important aspects of executing an forex transaction: one is the build of the input to Logic, and the other is the configuration information of the currency pair.

3.1. Building input to Logic

Fig.13 Example of building Logic input/output

Fig.13 shows a group of Logics being executed in sequence. In addition to the results of the previous group, information such as price, account information, and Strategy settings are used to build input to the next group. In Fig.13, there are two Logics in the Exit group, and the results of each run are organized to create the input of the next Entry group.

Thus, Repository is a simple mechanism: it builds the inputs from the Strategy settings and account information, and determines the outputs of the group from the Logic results.

Fig.14 Information to be entered into Logic

There are three major inputs to Logic (Fig. 14). Data, which contains price information, Context, which is environmental information, and Store, which manages external inputs and outputs. The following shows the contents of the data for an forex transaction.

Data is the price data retrieved from MT5. Configurations such as the timeframe and amount of data required for Logic’s calculation are retrieved from the Strategy setting information.

Context holds almost all environmental information that can be retrieved in MQL, the MT5 programming language. For account information, this includes the basic account information already mentioned, as well as the positions held, and the Pip Value and Margin Value.

Store holds all of the “output” from Logic. For example, the functionality related to Firestore documentation. In the system described in this article, a portion of the Firestore is pre-allocated to the user running Strategy, and the user can read and write to the allocated Firestore through the Store. Other pre-trained models that exist in CloudStorage are pre-installed and used from the Store.

The above three elements are built from Strategy configuration information and Account, and the Repository class executes Logic. I believe there is still room for improvement regarding the Store design, but I have settled on the current state.

3.2. Configuration information of currency pair

MT5 shares the same module for forex and CFDs (Contract for Differences) trading. While this specification is very convenient in terms of creating automated trades and tools, there is a large amount of information that is obviously unnecessary if limited to forex trading. For this reason, only the most frequently used information for forex trading is retrieved from MT5 for the information of currency pair recorded in Context.

Properties in MQL are classified by data type. For example, the minimum lot number of an currency pair is of type Double and can be obtained from SymbolInfoDouble(), while Digit, which indicates the relationship between the decimal point and pip, is of type Integer and can be obtained from SymbolInfoInteger(). All information that can be obtained is described in the following links. These information are passed to Logic from the Context prepared by the Repository class. In the following, I will briefly introduce the information recorded in Context.

Symbol is the name of the currency pair. In forex trading, it is limited to currency pair such as EURUSD, and when using MT5 for CFDs trading, it is applicable to Crude Oil, etc.

The pip, point, and digit are the relationship between the decimal point and the PIPS. 1.07316 (EURUSD) would have a pip of 0.0001, point of 0.00001, and digit of 5. 130.000 (USDJPY) would have a pip of 0.01, point of 0.001, and digit of 3. For 130.000 (USDJPY), pip is 0.01, point is 0.001, and digit is 3.

The ask and bid are the current asking price of the currency pair. Pip Value (Ask or Bid) and Margin Value (Ask or Bid) calculated from each price can also be obtained.

Symbol leverage is the leverage of the currenct pair. Leverage is determined by the broker, and is based on the currency pair and its equity. In general, currency pair with high volatility (CHF, MXN, etc.) have less leverage, and the smaller the Equity, the greater the leverage. Symbol Leverage is the leverage of the currency pair as finally determined.

Volume max, volume min, and volume step are the lot settings. Literally, they indicate the maximum and minimum number of lots that can be purchased.

Note that some information is not available in the simulation.
For example, ask and bid are disposable information that is not stored in MT5. Since historical data cannot be retrieved, a design that uses the most recent close and spread instead would work in the simulation.
Also, Equity and leverage rules are not provided by MT5. If you simulate with a setting of $10,000 even though the actual Equity is $100,000, the margin level will be calculated with a smaller leverage of $100,000 unless you specify it yourself.

4. Mechanism for running simulations

When actually running the application on a Python server, the Repository introduced in section 3 exchanges information from MT5 and Firestore. In the simulation, it is assumed that Repository’s control information is sent to MT5, and the Process class reproduces MT5 and Firestore.

Through the construction of Process class, you can gain a deep understanding of the environment surrounding the forex data. For example, the MT5 reproduction provides a deeper understanding of how price information works that executes automated trades. The two topics presented here are 1. price information reproduction and 2. trade information handling and position management.

4.1. Preparation of pricing information

Fig.15 Price information to be prepared for simulation

The first assumption is that the simulation is run for one currency pair only. The shortest timeframe is the main timeframe (Main TF), the upper timeframe required by the Strategy is the sub timeframe (Sub TF), and the cross rate is the price information required to obtain the Pip Value and Margin Value introduced in section 2 (Fig. 15).

When EURGBP is the trade target, Main TF and Sub TF are obtained from MT5 for Time, OHLC, Spread, and Tick Volume. Cross rates are EURUSD and GBPUSD in H1 timeframe, and only Time and Close will be retrieved.
Price information acquired from MT5 is repeatedly input to Repository in a loop process. The method of dividing time-series data is as described in the past articles.

Fig.16 Example of a candlestick with a transaction occurring every minute

The actual timing for MT5 to receive the data is the moment the Main TF is determined. Fig.16 shows an image of the H1 and H4 timeframes, assuming a currency pair that trades every minute for illustration. The candlestick at 12:00 is fixed at 12:59 on the H1 timeframe and at 15:59 on the H4 timeframe.

The H1 timeframe on the left side of Fig.16 shows that the 12:00 candlestick, which fixed at 12:59, is the latest information for the 13:00 Strategy calculation. However, in reality, at 13:00, an H1 candlestick with 1 transaction (1 tick volume), a time stamp of 13:00, and OHLC of the same value is formed. In actual operation, the 13:00 calculation is expected to be delayed by seconds, and when manipulating a position, one trades close to the opening price at 13:00. For these reasons, when purchasing a position based on the 13:00 Strategy calculation, the simulation uses the opening price determined by this 13:00 candlestick as the reference price at the time of purchase. It is important to note that the most recent data that Strategy can use for its calculation is the closing price determined at 12:59.

This effect is more pronounced when sub TF is used: in the H4 timeframe on the right of Fig. 16, the Strategy calculation occurs four times (12:00, 13:00, 14:00, and 15:00). During this time, the latest H4 information available for the Strategy calculation is 8:00. However, when a purchase of a position occurs, the opening price of the H1 candlestick, which is the Main TF, is used as the reference price at the time of purchase.

4.2. Trade handling and position management

In section 2, I introduced how the Account class provides trade information to the Strategy, and the Account class can execute Repository without manipulating MT5’s account information. However, in the simulation, it is necessary not only to execute Repository but also to update the account information that MT5 was originally supposed to process. This section introduces a reproduction of the case where MT5 receives operations related to positions.

When the Repository is executed by loop process, it checks for output that changes the position status. If there is a purchase order, it records the order while considering the spread, and if there is a settlement order, it adds the price information at the time of settlement to the recorded position information. In addition, the account information of the Account class in the Repository is updated. The important updates include profit/loss, margin level, and the settlement process between loops.

Fig.17 Margin level management between candlesticks

Fig. 17 shows a Buy order at 23:00 using data at 22:00. At this time, the hourly price is the Main TF, and the M15 price is depicted together to show a concrete example. Note that M15 price is not provided when simulating the Strategy. The Buy price is the opening price at 23:00, followed by the lowest price at 0:30. Below graph is an image of the margin level. In this example, I am operating near the limit of stopout.

In the simulation, the worst value of the margin level is calculated from the H1 timeframe: from 23:00 to 0:00, the margin level is above the stop call, but when the lowest price is recorded in the H1 timeframe from 0:00 to 1:00, the margin level is below the stop call. At this time, the loss amount is reflected in the account at the start of the loop at 1:00, based on the assumption that the trade was forced to close at the lowest price at 0:00. In other words, at 1:00 Strategy is executed with no position. However, Main TF does not know the detailed price at the time of the stopout, so the lowest price on the H1 timeframe is used as the settlement price.

The swap information is a little bit special: MT5 does not provide swap rates and there is no history of swaps. Therefore, the impact of swaps on the account must be designed by the user who runs the simulation. In Fig. 17, the swap profit/loss is reflected in the account at the start of the loop at 0:00. In other words, the effect of swap is taken into account in the margin level at 0:00.

Fig.18 Stop Loss management between candlesticks

Settlement management is also very important. There are two major types of position manipulation: one is direct manipulation by the Strategy, and the other is closing with a pre-set TPSL (Take Profit & Stop Loss).

The Buy decision is made at 22:00 on the H1 timeframe, and the price is purchased at the opening price at 23:00. Looking at the more detailed M15 timeframe, the lowest price exceeds Stop Loss at 0:15 and is automatically settled. The simulation checks to see if the lowest price at 0:00 exceeds Stop Loss at the start of the loop at 1:00. In this example, the Stop Loss is trapped, so the Strategy calculation at 1:00 begins with a loss and no position. Unlike the margin level management, the settlement price is the amount specified by TPSL.

5. Evaluation

The simulation results are output to a file. The Process class implemented in section 4 records this information at each loop and outputs it to a file in a batch process when the number of loops exceeds a set value.

Fig.19 Simulation outputs and images used for evaluation

In general, performance of automated trading sysmte can be measured using only trade information (Fig. 19, green). Green part in the figure is the basic evaluation using trade information, and pink part is the Strategy-dependent evaluation using observer information intentionally output by the Logic.

The basic evaluation corresponds to the win rate and the number of trades where the evaluation method is not related to the Strategy. On the other hand, observer information includes internal conditions, indicators, and inputs to the learned model. Unlike the observer information, the basic evaluation does not allow for in-depth analysis, but it is sufficient to get an overall picture of the Strategy, and has the advantage that the program being evaluated can be reused regardless of the Strategy.
Here is a brief introduction to the basic evaluation for evaluating automated trading system. The evaluation using observers is omitted because the text is too voluminous.

There are two types of base evaluations in forex trading: one is the PIPS evaluation and the other is the Asset evaluation; the PIPS evaluation measures the win rate and expected value, while the Asset evaluation measures the performance of money management (M2s). If you are simply purchasing an automated trading system without analyzing it, these basic evaluations alone are sufficient to make a statistical assessment. It is important to note, however, that both of these evaluations are basic evaluations of the overall Strategy and are not sufficient information for performance improvement.

5.1. Pips evaluation

The Pips rating is an evaluation of a trade’s results minus the number of lots, and it provides the most basic information about a Strategy’s performance. A good Strategy does not necessarily need to earn a large number of pips; a stable and repeatable trade is sufficient. Below is an example of a Pips evaluation.

Number of trades: A good Strategy needs to have a sufficient number of trades enough to see its performs. When you evaluate a Strategy with no edge, the performance appears to improves as the number of trades decrease.

Profit Factor (PF): This gives an indication of the overall performance of the automated trades. A PF with enough trades and OoS (Out of Sample) repeatability is credible.

Win Rate: Different PFs and Strategy tendencies require different levels of win rate: 30% may be sufficient, while 50% may not be enough if you want to Take Profit early.

Risk Reward: This is the ratio of the winning margin to the losing margin, and shows the strategy’s personality. The higher the risk reward, the more room for growth, and the lower the risk reward, the higher the winning rate.

Total PIPS: Even if a Strategy has a good win rate and PF, be careful if the total pips are unstable in OoS. It may be extremely dependent on a trade that just happened to hit the jackpot.

Maximum Draw Down (MDD): Maximum accumulated pips divided by the current accumulated value; if Total Pips reaches 500 pips and then drops to 250 pips due to consecutive losses, the MDD will be 50%.

Buy Ratio: This is the ratio of buys to all trades. For example, you can find unusually good performance only when there are many Buy (or Sell) trades in a simulation. A closer look at the results may show that the strategy is not good at Sell, but it may also reveal a risk that the performance is being boosted to take advantage of a long term trend that is not reproducible.

Z-score: Shows the trend of losing streaks, which can easily swing to extreme values depending on the Strategy. If the value is close to 0, it is statistically tractable, but it is not always a good choice, as it may conversely worsen performance.

All of the above ratings are listed in the table. In addition to the above, there is other information that is difficult to check in the table. These include the relationship between the day of the week, time of day, and pips. For such evaluations, I have prepared individual functions.

5.2. Asset evaluation

Asset Evaluation measures the results of a trade in terms of Equity; unlike Pips Evaluation, it looks at the profit/loss of a trade and is also an evaluation of the performance of Money Management (M2s), which is a rule for setting the number of lots.

Below is some basic information on asset evaluation, omitting the exact same indicators as for Pips evaluation.

Gross Profit: This is the final profit within the simulation period. There are two types of units: monetary and %.

Profit Factor (PF): Unlike Pips PF, this is the PF calculated as the profit or loss from the number of lots and Pips. If PF (Pips) is sufficient, aim for good PF (Assets) while maintaining margin level.

Maximum Draw Down (MDD): This is the MDD from the perspective of Equity, not Pips. The unit of measure is either an amount or a percentage.

Ret / MDD: This is the ratio of Gross Profit to MDD. For example, if you increase the number of lots and the total profit increases by 10%, you will feel that the performance has improved. However, if the MDD deteriorates to an unacceptable level, the increase in profit is not worth the cost. This indicator serves as a guide to cost and return.

As with the Pips evaluation, if it is too complicated to be expressed in a table, it is graphed individually.

Conclusion

In this article, I have built a Strategy for forex trading based on the analytical platform described in previous articles. This allows us to compare and evaluate the Strategies created on Notebook in a simulation, and to run the Strategies I like in MT5 as actual applications.

As mentioned in previous articles, this analysis platform is used to explore strategies and metrics, and to gain a better understanding of forex trading by recreating the inner workings of MT5. You will then solidify your own strategy by analyzing existing automated trading algorithms.

Once you have found a strategy that you are happy with and you have a set of metrics to evaluate its performance, you can push it to the Python server and running. The next bottleneck when running multiple Strategies simultaneously is the computation speed of the simulation and the evaluation of the combination. Once you have reached this point, there is no situation where you need to make major changes to the Strategy design, and you can safely implement it in a vendor-dependent language (MQL5) or C instead of Python. You should be familiar with the elements to be analyzed, so you only need to monitor the numbers used in the evaluation.

--

--