tomas.vanek

The Psychology of Back testing: Avoiding Overfitting and Confirmation Bias

Back testing is a common practice in financial analysis, where analysts test trading strategies using historical data. While back testing can be a powerful tool for predicting future market trends and generating profits, it can also be prone to errors due to two key psychological biases: overfitting and confirmation bias.

Overfitting occurs when a trading strategy is designed and tested using historical data that is too specific and too limited. This can result in a strategy that is too closely tailored to the past and may not perform well in future market conditions. Confirmation bias, on the other hand, occurs when traders only look for evidence that supports their preconceived notions about the market, rather than seeking out contradictory evidence that could challenge their assumptions.

To avoid these psychological biases and make the most of back testing, here are some practical tips:

  1. Use diverse data: When back testing a trading strategy, it’s important to use a diverse range of historical data that includes a variety of market conditions. This can help prevent overfitting by ensuring that the strategy is designed to perform well in a range of different scenarios.
  2. Test multiple scenarios: To further prevent overfitting, it’s also important to test the trading strategy against multiple scenarios. This can help ensure that the strategy is robust and can perform well even in unexpected market conditions.
  3. Use out-of-sample testing: In addition to testing a trading strategy against historical data, it’s also important to use out-of-sample testing. This involves testing the strategy on data that was not included in the original back test, which can help reveal any potential weaknesses or flaws in the strategy.
  4. Challenge assumptions: To avoid confirmation bias, it’s important to challenge assumptions and seek out contradictory evidence. This can involve testing the strategy against different data sets, seeking out alternative perspectives, and looking for evidence that contradicts your initial assumptions.
  5. Avoid data snooping: Data snooping occurs when traders search through large data sets to find patterns that may not actually be significant. This can lead to overfitting and false conclusions. To avoid data snooping, it’s important to have a clear hypothesis and methodology in place before conducting any analysis, and to be transparent about the data sets and variables used.

By following these tips, you can avoid the psychological biases that can undermine the effectiveness of back testing, and make more informed decisions about their trading strategies. Ultimately, this can help improve your chances of generating profits and achieving long-term success in the financial markets.

How Swap Rates are Calculated in MetaTrader 4 and 5

If you’re new to trading forex or other financial instruments, you may have heard the term “swap” being used in MetaTrader 4 and 5. In this post, we’ll explain what swap is, how it works, and how you can use this information to improve your trading performance.

What is Swap?

In simple terms, swap is the interest rate that is charged or paid for holding a trading position overnight. It is also known as an overnight or rollover fee. When you open a trading position, you are essentially borrowing one currency to buy another. The interest rate on the currency you are borrowing is usually higher or lower than the interest rate on the currency you are buying. This difference in interest rates is reflected in the swap rate.

If the interest rate on the currency you are buying is higher than the interest rate on the currency you are selling, then you will earn a positive swap. This means that you will receive a small amount of money in your trading account for holding the position overnight. If the interest rate on the currency you are buying is lower than the interest rate on the currency you are selling, then you will incur a negative swap. This means that you will have to pay a small amount of money from your trading account for holding the position overnight.

How to View Swap in MetaTrader 4 and 5?

To view the swap rate for a currency pair in MetaTrader 4 and 5, you can follow these steps:

  1. Open the Market Watch window by clicking on View > Market Watch in the main menu.
  2. Right-click on the currency pair you want to view and select “Symbols” from the context menu.
  3. In the “Symbols” window, click on the “Properties” tab.
  4. You should now see the swap long and swap short values listed for that currency pair.

The swap long value represents the interest rate you will earn for holding a long (buy) position overnight, while the swap short value represents the interest rate you will pay for holding a short (sell) position overnight.

It’s worth noting that the swap rate can vary depending on the broker you are using and the currency pair being traded. Some brokers may also adjust their swap rates to reflect market conditions or other factors.

How to Use Swap to Your Advantage

Knowing the swap rate for the currency pairs you are trading can be useful in several ways. For example, you may choose to hold a position overnight if the potential profit from the trade exceeds the cost of the negative swap. Alternatively, you may decide to close a position before the end of the trading day to avoid paying a high negative swap.

Some traders may also use swap rates to inform their trading strategies. For example, they may look for currency pairs with high positive swaps and hold these positions over a longer period to maximize their returns.

Positive Swap:

Suppose you have a long position in the AUD/USD currency pair with a trading volume of 1 lot (100,000 units of the base currency – Australian dollar). The current interest rate on the Australian dollar is 0.5%, while the interest rate on the US dollar is 0.25%. The swap long rate for this currency pair is +3.3 pips.

In this scenario, you will earn a positive swap of $3.30 per day for holding the position overnight, as you are borrowing the US dollar and buying the Australian dollar, which has a higher interest rate. If you keep this position open for one week, you will earn a total of $23.10 in positive swap ($3.30 x 7 days).

Negative Swap:

Now suppose you have a short position in the EUR/GBP currency pair with a trading volume of 1 lot. The current interest rate on the euro is -0.5%, while the interest rate on the British pound is 0.1%. The swap short rate for this currency pair is -9.8 pips.

In this scenario, you will incur a negative swap of £9.80 per day for holding the position overnight, as you are borrowing the British pound and selling the euro, which has a lower interest rate. If you keep this position open for one week, you will have to pay a total of £68.60 in negative swap (£9.80 x 7 days).

It’s worth noting that swap rates can change over time, so a position that was earning a positive swap one day may earn a negative swap the next day. It’s important to stay informed about current swap rates for the currency pairs you are trading to make informed trading decisions.

Conclusion

In conclusion, swap is an important concept to understand in forex trading, as it can affect your trading profitability. By knowing how to view the swap rate in MetaTrader 4 and 5, and how to use this information to your advantage, you can make more informed trading decisions and improve your overall trading performance.

CAGR: Understanding the Concept and Its Practical Applications

Compound Annual Growth Rate (CAGR) is a financial metric used to measure the growth of an investment over a specified period of time. It is a smoothed and annualized rate of return that represents the average growth rate of an investment over a certain period. It gives a more realistic picture of the investment’s growth rate by taking into account the effects of compounding over time.

The formula for CAGR is: CAGR = (Ending Value / Beginning Value)^(1 / number of years) – 1

Here, the ending value is the value of the investment at the end of the specified period, and the beginning value is the value of the investment at the start of the specified period.

Practical Examples of CAGR

  1. Investment in the Stock Market One of the most common uses of CAGR is to measure the growth rate of an investment in the stock market. For example, if you invested $10,000 in a stock five years ago, and its value has increased to $15,000, the CAGR would be calculated as follows:

CAGR = ($15,000 / $10,000)^(1 / 5) – 1 = 0.10 = 10%

This means that the investment has grown by 10% annually on average over the last five years.

  1. Retirement Planning CAGR is also used in retirement planning to determine the growth rate of a retirement account over time. For example, if you are saving $5,000 annually for your retirement, and after 20 years, your retirement account has grown to $200,000, the CAGR would be calculated as follows:

CAGR = ($200,000 / ($5,000 * 20))^(1 / 20) – 1 = 0.06 = 6%

This means that the retirement account has grown by 6% annually on average over the last 20 years.

In conclusion, CAGR is a useful financial metric that provides a more accurate representation of the growth rate of an investment over time. It takes into account the effects of compounding and gives a more realistic picture of an investment’s performance. Whether you are investing in the stock market or planning for your retirement, understanding CAGR can help you make informed investment decisions and achieve your financial goals.

The Sharpe Ratio: Understanding and Using it for quant trading strategies

The Sharpe Ratio is a widely used metric for evaluating investment performance and risk-adjusted return. It measures the excess return per unit of risk taken by an investment and helps investors compare different investment options. In simple terms, the Sharpe Ratio indicates whether an investment’s returns are due to smart investment decisions or a result of excessive risk-taking.

The formula for the Sharpe Ratio is:

(Return of the Investment – Risk-Free Rate) / Standard Deviation of Returns

The risk-free rate is typically represented by the return on a government bond and is used as a benchmark for measuring an investment’s excess return. The standard deviation of returns measures the volatility of an investment’s returns.

An investment with a higher Sharpe Ratio is considered to be more attractive than an investment with a lower Sharpe Ratio as it indicates a higher return per unit of risk taken.

Example:

Consider two investments, Investment A and Investment B, with the following returns:

Investment A: 10% return with a standard deviation of 5% Investment B: 12% return with a standard deviation of 8%

Assuming a risk-free rate of 2%, we can calculate the Sharpe Ratio for each investment as follows:

Investment A: (10% – 2%) / 5% = 1.2 Investment B: (12% – 2%) / 8% = 0.7

In this case, Investment A has a higher Sharpe Ratio of 1.2 compared to Investment B’s 0.7, indicating that Investment A provides a higher return per unit of risk taken.

In conclusion, the Sharpe Ratio is a useful tool for evaluating investment performance and comparing investment options. By measuring the excess return per unit of risk taken, investors can make informed decisions about the potential return and risk of their investments.

How big impact has smooth execution of algos on your trading results?

Having all systems online is crucial for every AlgoTrader. Enjoy your life with confidence that your trading robots are working without any obstacle and your VPS is running smoothly. 

In this article we will talk about how big impact has the smooth execution on your trading account. Everything we will explain on examples and live simulations.

First of all, let me explain, which situations could happen?

  • Unexpected shutdown of the platform
  • Unexpected loss of connection to the broker
  • Low margin
  • Disabled Automated trading

Let’s simulate how these situations can impact your trading performance and your balance on your trading account. We will use Quant Analyzer software What-if scenario and Monte Carlo function for this.

What can happen if our platform has experienced unexpected shutdown?

Some trades can be running on the account without managing therefore our algos cannot manage trailing stop, profit target or exit of the trade at certain time (Dangerous holding during weekends.).

Here is result of original strategy

Result of original strategy

If we miss only 1 % of profit trades we can see performance impact

If we miss only 1 % of profit trades we can see performance impact

If we take only every 5 trade we can see performance impact

If we take only every 5 trade we can see performance impact

Comparison of all graphs above: Green: original Purple: every 5 trade Yellow: 1 % missed trades

Comparison of all graphs above: Green: original Purple: every 5 trade Yellow: 1 % missed trades

We can see that impact of smooth execution of trades is very important. Return Drawdown ratio has dramaticly dropped from 9 to 3.

Monte Carlo Analysis – 10 simulations of Random Skip trades with 5 % of probability.

During these unexpected moments it is crucial to be informed about these events ASAP. Therefore, we are offering professional solution which can immediately notify you via email or SMS when something unexpected happen. You will have time to solve the issue and prevent loses. This is what our monitoring platform can do. Try our monitoring platform and have all your algos monitored.

Check for FREE how can QuantMonitoring help you

Receive 30 days free trial period + access to interesting know-how

How to install Metatrader 4 under Linux

n today’s tutorial, I would like to show how to install Metatrader 4 or Metatrader 5 for Debian Linux distribution. The license fees for Windows Server are more than high and this can be the way how to save money for the VPS or physical server operating system.

Considering that some unexpected installation issues may occur during the installation or when running the Metatrader 4/5 process alone, this article is more considered for advanced users.

So let´s start. What are we going to need?

Now let’s start with the Wine installation:

 1. In order to avoid writing sudo with every command, switch to root user with the command and insert password.

su –

password:

2. First we allow the installation of the 32-bit packages

dpkg –add-architecture i386

3. Add a key for wine repository:

wget -nc https://dl.winehq.org/wine-builds/Release.key
apt-key add Release.key

4. Add this repository line to the file /etc/apt/source.list file

deb https://dl.winehq.org/wine-builds/debian/ jessie main

5. Install package support from https using the command:

apt-get install apt-transport-https

6. Then update the list of packages from the repository using the run command:

apt-get update

7. Then install Wine using the command:

apt-get install –install-recommends winehq-stable

8. After Wine is installed, it is necessary to configure the wine and run it with the command:

winecfg

after running this command, the pop up window will appear with the message that there are missing additional packages, that has to be installed, so click to download and install them.

9. When you start a winecfg, you need to set the emulation for Windows 7 (check the screen bellow):

We can now install Metatrader 4

1. Run the Metatrader 4 installation package and change the installation folder

2. Run Metatrader 4 and enter your login details

If we want to install MT5, we will use the same procedure. Metatrader 4 runs on Linux directly in portable mode, but the MT4 data are in a different location than in Windows.

!!! ATTENTION !!! Metatrader 4 data with strategies and indicators can be found in the following folder:

/home/USER_NAME/.wine/drive_c/MT4/MT41/MQL4/

Note at the end

I wanted to know how the MT4 on Linux is demanding CPU vise, so I made an experiment. I ran the same amount of MT4 instances on Linux and Windows. My measurements were clear, the Windows emulation is worth some HW costs. On Linux, the CPU usage was roughly twice as on Windows.

The most common errors in Metatrader 4 and how to solve them

Metatrader is the most widely spread platform and it may happen that it will report us an error during our trading. In today’s article, we will have a look at the list of most common errors and we will describe how to deal with them.

 I put the strategy into MT4 but nothing happens. Is anything wrong? What should I do?

There may not be anything wrong. Sometimes it takes time until the strategy starts trading. Check the MT4 log (the “log” tab in the terminal) and if there is no error, the smiley laughs, then just wait until the strategy starts trading.

 I found the Trade is Disabled error in the log. What should I do?

This is the most common error with XTB broker and Purple Trading and it means that trading is forbidden.

XTB Broker Solution – Trading is forbidden on a standard account, and you must switch to Standard +.

Purple Trading Broker Solution – Probably, you have put the strategies in the wrong chart. You need to add a strategy to the right chart. If you use a STP account, you need to put strategies in a graph without the _ecn suffix if you have an ECN account, you need to use symbols with the _ecn suffix.

What should I do if Metatrader 4 is disconnected from the broker´s server?

Here are two options. The first option is to restart MT4. The second option is to click on the account with the right mouse button and click on sign in. If it still does not help, contact the broker if there is a problem on his side.

Error Indicator is missing is shown it the metatrader. What should I do?

Make sure you have a copied StrategyQuant indicators. Indicators can be found in C: \ StrategyQuant \ custom_indicators \ mt4 \ indicators. Copy these indicators into the MT4 MQL4 \ Indicators folder

In the Metatrader 4 log appeared error the trade context is busy. What should I do?

Most often, this error occurs when a lot of strategies (10 or more) are in one MT4 and MT4 cannot handle so many commands at a time. In this case, I recommend splitting strategies into multiple MT4s – simply said, for example install 10x MT4 and then logging 10 times under the same account. The recommended maximum strategy for one MT4 is 10. This is the tested number of strategies in which the program runs steadily and without problems.

Errors in Metatrader

Here is the list of errors and messages in MT4. If you would meet one of them and did not know how to proceed, please contact us.

ErrorError IDDescription
ERR_NO_ERROR0No error returned.
ERR_NO_RESULT1No error returned, but the result is unknown.
ERR_COMMON_ERROR2Common error.
ERR_INVALID_TRADE_PARAMETERS3Invalid trade parameters.
ERR_SERVER_BUSY4Trade server is busy.
ERR_OLD_VERSION5Old version of the client terminal.
ERR_NO_CONNECTION6No connection with trade server.
ERR_NOT_ENOUGH_RIGHTS7Not enough rights.
ERR_TOO_FREQUENT_REQUESTS8Too frequent requests.
ERR_MALFUNCTIONAL_TRADE9Malfunctional trade operation.
ERR_ACCOUNT_DISABLED64Account disabled.
ERR_INVALID_ACCOUNT65Invalid account.
ERR_TRADE_TIMEOUT128Trade timeout.
ERR_INVALID_PRICE129Invalid price.
ERR_INVALID_STOPS130Invalid stops.
ERR_INVALID_TRADE_VOLUME131Invalid trade volume.
ERR_MARKET_CLOSED132Market is closed.
ERR_TRADE_DISABLED133Trade is disabled.
ERR_NOT_ENOUGH_MONEY134Not enough money.
ERR_PRICE_CHANGED135Price changed.
ERR_OFF_QUOTES136Off quotes.
ERR_BROKER_BUSY137Broker is busy.
ERR_REQUOTE138Requote.
ERR_ORDER_LOCKED139Order is locked.
ERR_LONG_POSITIONS_ONLY_ALLOWED140Long positions only allowed.
ERR_TOO_MANY_REQUESTS141Too many requests.
ERR_TRADE_MODIFY_DENIED145Modification denied because an order is too close to market.
ERR_TRADE_CONTEXT_BUSY146Trade context is busy.
ERR_TRADE_EXPIRATION_DENIED147Expirations are denied by broker.
ERR_TRADE_TOO_MANY_ORDERS148The amount of opened and pending orders has reached the limit set by a broker.

How to run the Metatrader in portable mode and what it is good for?

What is the portable version of Metatrader 4? What benefits does it bring? Learn all this is in our today’s article.

What is the portable version of Metatrader 4?

Portable is a portable program that can be booted from a portable device such as a flash drive, memory card or other disk location different from program files. The portable program is typically designed to store its configuration and user data in its own location and not on the system disk in the user’s data folder. In newer Windows, it can be usually found in:

“C \ Users \ ‘username’ \ appdata”, which is quite uncomfortable to work with. If we choose a portable version, we will have indicators, strategies, etc. in a folder such as C: \ mt4 \ MQL, which is more convenient.

What brings the portable version of Metatrader 4?

For me, it personally brings better overview and better handling of the MT4 platform. For example, I do not have to install MT4 every time, I can just copy the MT4 folder and use it for another account. Another advantage is greater simplicity when backing up the MT4 configuration or a possible shifting to another VPS – How to run Metatrader 4 on VPS.

Another advantage is that when I go for a holiday, I can have a MT4 backup on flash disk and if I there is a problem with my mobile or laptop, I can connect from any computer without installing MT4.

How to set up a portable Metatrader 4?

It’s fairly easy. In the shortcut icon/desktop icon just add / portable, as you can see bellow:

  • Right click on the mt4 icon
  • Select properties
  • Add to the target / portable

After this change, save the changes and then run MT4 as a portable from the directory where we you run it. I recommend to do this change right after installing MT4, if you modify an already running MT4, you may need to copy the original user data from the MT4 app data directory, which I do not recommend because you could forget something and then wonder that you have lost your indicator etc.

Tips for safe VPS operation with Metatrader 4

In today’s article, I will show you how, with a few tricks, we can secure our VPS, where our real accounts are running. This is the reason why we need to prevent our server from being hit by potential attackers. I know from my own practice that if you have opened a VPS port for a few minutes, the first attacks or attempts to connect are emerging. VPS security should not be underestimated.

Let’s take a look at some tips:

Tip 1: Restrict Remote Desktop Access (RDP) to a specific IP address

The most effective way is to restrict access to a specific IP address only. In order to connect, we need to have a fixed IP address or secure VPN server address from which we connect to VPS. If you do not have a static public IP or VPN, we recommend at least changing the default remote desktop port.

Tip 2: Change the remote desktop access port

Most RDP attacks take place on the default port 3389. You can easily change this port, but you need to consider other services that are using this port.

Tip 3: Back up

Most VPS providers offer the possibility to back up entire images – so-called snapshot VPS or they offer some backup space. In case of a server attack, the entire image of the disc with minimal downtime can be restored.

Tip 4: Do not open other than needed ports

Keep the firewall set strictly only for the services and IP addresses you need on internet.

Tip 5: Use strong passwords for Administrator and User Accounts

We recommend using a password that contains both uppercase and lowercase letters, digits and at least one special character.

Get access to the #1 Dashboard for AlgoTraders

Tip 6: Do not overload VPS

Monitor the VPS usage with Resource Monitor or Task Manager. When the Metatrader 4 is in the steady mode, the usage should not exceed 40% of the total VPS CPU. Ideally even less. We should not forget the sufficient reserve when the market starts to move and there is a high volatility. This moment is absolutely critical, and the VPS must stand this situation too. At this point, the platform must be stable and have sufficient power to keep robots working, as they were programmed. At this point, it is mainly about the trailing stop and the possible exit order.

If you use VPS from some commercial VPS providers, you should be cautious because some of them block VPS, which exceeds 60% of CPU for more than 30 minutes. In this case, there will be limitations to 200 MHz CPU power. This is causing that the VPS is lagging and can hardly be controlled when connected over a remote area.

Tip 7: Ensure that the VPS server is running

VPS Providers Offer Server Monitoring Service. In the event of a downtime, you will be informed about the possible problem by email or SMS to avoid unnecessary complications.

Tip 8: Update regularly

Keep the system up to date and apply the latest security patches. More at https://technet.microsoft.com/en-us/library/cc731322(v=ws.11).aspx. The same applies to Linux. After you apply the system update, restart it. This activity is appropriate during the weekend when the trading is stopped.

Tip 9: Update the Metatrader 4 platform

Metatrader 4 has automatic updates, so it is enough to turn the platform on and off, the update is done in the background when the platform is started. After updating, it’s a good idea to go through all charts if the strategy runs properly. From time to time, the strategy may disappear.

Get access to the #1 Dashboard for AlgoTraders

Tips for reducing Metatrader 4 CPU usage on VPS

Metatrader can take a lot of CPU resources because it does some extra operations that we do not need in order to run our automated strategies on VPS and this, of course, increases heavily the VPS usage. It renders charts, downloads unnecessarily long data, unused symbols, plays notifications and other features that are not necessary for running automated trading strategies. In today’s article, we’ll show you how to disable these features and reduce the CPU usage on VPS. Thanks to optimizations, we can multiply the number of running instances of Metatrader 4 to maximize the VPS potential. Regarding the VPS usage itself, I recommend tracking it with the Task Manager.

So, let’s start with the tips:

Minimize the MT4 application on the Windows bar

Minimizing the windows in MT4 – From practice, it turned out that at the moment when Metarader 4 renders charts, CPU usage is increased rapidly.

Hide all unnecessary symbols as shown in the picture – so the platform will not download unnecessary data for other symbols

Hiding the terminal with open commands – Metatrader does not have to render anything and the usage is smaller

Disabling news displayed in the platform,  please see the picture- this setting can be found in tools -> options

Disabling audio alerts, please see the picture – this setting can be found in tools -> options

Minimalizing the number of candles in the chart, see the image – here I recommend using a minimum value of 5000, when you put less candles, some strategies may not work accordingly.

Disabling the automatic movement of the candles in the chart, see the picture

After these optimizations, the Metatrader 4 platform may look like this.

As you can see it is not complicated and it is definitely worth running optimized mt4, so you can run as many MT4 platforms as possible on your VPS. You can save a lot of money 😉

Get access to the #1 Dashboard for AlgoTraders

Register for FREE and get access to:

By registering you agree with our Terms and Conditions