Introduction

The Fisher Transform theory is put into practice by implementing MQL5 version of Smoothed RSI Inverse Fisher Transform indicator presented in October 2010 issue of "Stocks and Commodities" magazine. The indicator profitability is backtested by Expert Advisor that uses signals based on Fisher indicator.

The article is based on J.F.Ehlers books and articles found on the Internet. All references are mentioned at the end of the article.

1. Gaussian PDF vs Market Cycles

A common assumption is that prices have normal probability density function.

This means that price deviations from the mean can be described as a well known Gaussian bell:

Figure 1. Gaussian bell

I mentioned normal probability density function. To fully understand that let's introduce several ideas and math formulas, I hope they will all be understandable for majority of the readers.

The ratio of the number of outcomes in an exhaustive set of equally likely outcomes that produce a given event to the total number of possible outcomes or

The chance that a given event will occur.

A random variable is a variable whose value results from a measurement on some type of random process. In our case the random variable is a price of an asset.

Finally, PDF is an acronym for Probability Density Function - a function that describes the probability that a random variable X (again - in our case price) assumes a value in a certain range of possible values. A random variable value that results from a Gaussian distribution or Normal distribution is a probability distribution that is often used to describe real-world random variables that tend to cluster around a single mean value.

This represents area under the curve f(x) from a to b. Probability is counted from 0 to 100% or from 0 to 1.00, therefore there is a limit that the total area under the f(x) curve must equal 1 (sum of the probabilities):

Now let's go back to the lower part of Figure 1:

Figure 2. Gaussian bell standard deviations

You can see here what percentage of values is under mean +/- 1-3 standard deviations (sigmas). With Gaussian PDF 68.27% of occurences fall within plus/minus one standard deviation from the mean, 95.45% fall within plus/minus two standard deviations and 99.73% fall within plus/minus three standard deviations from the mean.

Do you think that is the case with real market data? Not quite. When we look at market prices we can rather assume that the chart looks like a square wave - after breaching resistance or support levels where large orders are grouped prices tend to rise or fall to the next support/resistance level. That is why market can be modelled with great approximation as a square or sine wave.

Please observe sine plot below:

Figure 3. Sine plot

You should notice that in reality most trades are similarily placed near support and resistance levels, which seems quite natural. Now I will plot density plot of a sine wave. You could imagine that we are turning Figure 3 90 degrees to the right and let all circles that make the plot fall to the ground:

Figure 4. Sine curve density plot

You may notice that density is highest on the leftmost and rightmost positions. This seems to be in line with the previous statement that most of the trades are made very close to resistance and support levels. Let's check what percentage of occurences are by drawing a histogram:

Figure 5. Sine curve density histogram

Does it look like a Gaussian bell? Not exactly. First and last three bars appear to have most occurences.

J.F. Ehlers in his book "Сybernetic analysis for stocks and futures" described an experiment where he analysed U.S. T-Bonds over a span of 15 years. He applied a normalized channel 10 bars long and measured the price location within 100 bins and counted the number of times the price was in each bin. The results of this probability distribution closely reminds those of a sine wave.

2. Fisher Transform and its application to timeseries

Since we now know that PDF of a market cycle does not remind a Gaussian but rather a PDF of a sine wave and most of the indicators assume that the market cycle PDF is Gaussian we need a way to "correct" that. The solution is to use Fisher Transform. The Fisher transform changes PDF of any waveform to approximately Gaussian.

The equation for Fisher Transform is:

,

Figure 6. Fisher Transform

I mentioned that the output of Fisher transform is aproximately Gaussian PDF. To explain this it is worth to look at the Figure 6.

When the input data is near its mean, the gain is approximately unity (see the chart for |X<0.5|). On the other hand when normalized input approaches either limit the output is greatly amplified (see the chart for 0.5<|x|<1). In practice you might think of growing 'almost Gaussian' tail, when the most deviations occur - this is exactly what happens to the transformed PDF.

How we apply the Fisher Transform to trading? At first, due to |x|<1 constraint, prices must be normalized into this range. When normalized prices are subjected to Fisher Transform the extreme price movements become relatively rare. This means that the Fisher Transform catches those extreme price movements and allows us to trade according to those extremes.

4. Inverse Fisher Transform and its application to cycle indicators

The transfer response of this function is inverse of that of the Fisher Transform.

For |x|>2 the input is compressed to not exceeding unity (for negative numbers -1 and for positive +1) and for |x|<1 it is an almost linear relationship which means that ouput has more less the same characteristics as input.

The results is that when Inverse Fisher Transform is applied to properly prepared input data, the output has a big chance to be -1 or +1. This makes the Inverse Fisher Transform perfect to apply it to oscillator indicators. The Inverse Fisher Transform can improve them by giving sharp buy or sell signals.

5. Example of Inverse Fisher Transform in MQL5

In order to verify the Inverse Fisher Transform I implemented MQL5 version of Sylvain's Vervoort Smoothed RSI Inverse Fisher Transform indicator presented in October 2010 issue of "Stocks and Commodities" magazine and build a trading signal module and Expert Advisor based on that indicator.

Inverse Fisher Transform indicator has already been implemented for many trading platforms, the source codes are available at traders.com website and MQL5.com Code Base.

Since there was no iRSIOnArray function in MQL5 I added it to the indicator code. The only difference with the original indicator is default RSIPeriod set to 21 and EMAPeriod set to 34 since it behaved better for my settings (EURUSD 1H). You may want to change it to default RSIPeriod 4 and EMAPeriod 4.

Since I only presented transforms equations you might be puzzled on Fisher Transform and Inverse Fisher Transform origins.

When I was gathering materials for writing the article I got interested in how Fisher obtained both transforms but I did not found anything on the Internet.

But I looked at both Fisher Transform and Inverse Fisher Transform and both plots reminded me of a some kind of trigonometric or hyperbolic functions (can you see any similarities?). Since those functions can be derived from Euler's formula and expressed in terms of Euler's number 'e' I went back to calculus books and double checked that:

,

,

and since we now that tanh(x) can be obtained by:

,

and...

Yes, these are exactly the same equations I presented above. Fisher transform demystified! Fisher transform is simply arctanh(x) and Inverse Fisher Transform is its inverse, tanh(x)!

6. Trading signals module

In order to verify the Inverse Fisher Transform I build a trading signal module based on Inverse Fisher Transform indicator.

The article deals with the methods of indicators computational algorithms optimization. Everyone will find a method that suits his/her needs best. Three methods are described here.One of them is quite simple, the next one requires solid knowledge of Math and the last one requires some wit. Indicators or MetaTrader5 terminal design features are used to realize most of the described methods. The methods are quite universal and can be used not only for acceleration of the linear regression calculation, but also for many other indicators.

The article presents the indicators, described in the book by William Blau "Momentum, Direction, and Divergence". William Blau's approach allows us to promptly and accurately approximate the fluctuations of the price curve, to determine the trend of the price movements and the turning points, and eliminate the price noise. Meanwhile, we are also able to detect the overbought/oversold states of the market, and signals, indicating the end of a trend and reversal of the price movement.

The MetaTrader 5 Client Terminal offers a wide range of opportunities for optimization of Expert Advisor parameters. In addition to the optimization criteria included in the strategy tester, developers are given the opportunity of creating their own criteria. This leads to an almost limitless number of possibilities of testing and optimizing of Expert Advisors. The article describes practical ways of creating such criteria - both complex and simple ones.

A Ukrainian developer Andrey Voitenko (avoitenko) is an active participant of the "Jobs" service at mql5.com, helping traders from all over the world to implement their ideas. Last year Andrey's Expert Advisor was on the fourth place in the Automated Trading Championship 2010, being slightly behind the bronze winner. This time we are discussing the Jobs service with Andrey.