A graphical approach to indicator testing

The first step in algorithmic strategy design usually is to find some indicators which give you an edge and tell you something about tomorrow’s market behaviour. You could use a lot of statistics to describe this edge, but I like to take a graphical approach in indicator testing first, and only later on worry about the math and statistics.

Scatter Charts

A scatter chart is a simple to read chart style to see the correlation between two input values. A regression line on the scatter chart gives you a visual idea if the two securities are positively or negatively correlated, the “cloud structure” of the scatter points tell you if this correlation is tight or loose.

This sample scatter shows the correlation between the DAX and DOW levels, and it can be easily seen that these two markets are tightly correlated in a positively way.

The horizontal scale is used for the second security (dax), the vertical scale is used for the first security (dow). This chart type is predefined in Tradesignal, just drag&drop it onto the securities on the chart and select the right amount of data to get the analysis you want to see. (eg. 2000-now). If you see a tight and positive correlation like on the chart above, It migt be used to select the instrument you want to trade. If market A is easier to predict than market B, select A.

Scatter on Indicators

Although a scatter chart is usually used to show the correlation between two markets, it can also be used to show the correlation between two indicators.

The chart above shows the correlation between digital stochastic and momentum. Have a look at the clustering of points in on the right side of the scatter, a high level in digital stochastic usually goes with a high momentum. This insight enables you to get rid of momentum, as digital stochastic is easier to read than the shaky momentum. Less indicators = less parameters = less curve fitting.

Scatter prognosis

Doing this analysis and getting rid of parameters is great if you want to minimize the dangers of curve fitting, but it does not tell you if your indicator is of any use at all, when it come to describing tomorrows move of the market. Surely it is valuable insight that a high level of stochastics corresponds to a high momentum, but does a high momentum today also mean that the market will move up tomorrow? And this question about tomorrow is the key question I ask myself when searching for some edge.

To get a glimpse on the prognosis quality of an indicator we will have to add some colour to our scatter chart. This colour tells me what the market has done after a specific indicator level has been reached. Green for an up move, red for a down move, black for not decided by now.

This chart shows the prognosis quality of the stochastic indicator. The left chart shows the 1 day prognosis of a 5 day stochastic, the right chart gives you the 5 day prognosis of a 21 day stochastic. Observe the clustering of the red and green dots. (black for not decided by now) As you can see on the left chart, the one day prognosis using a 5 day stochastic is not the thing to do. Regardless if stochastic is high or low, you get a nice mixture of red and green dots. This means the market, at a given stochastic level, sometimes moved up, sometimes moved down. Not this behaviour is not very useful for trading. Only in the extreme, near 0 and 100, this indicator seems to implicate a bearish next day movement.

The right chart, showing the longer term prognosis of a long term stochastic seems to be more useful. High levels of the indicator also show positive returns on the 5 days after, unfortunately you can not reverse the logic, as low indicator levels give a rater mixed prognosis. This visual analysis can give you an idea which areas of the indicator might be useful for further analysis.

A one dimensional analysis like on the chart above could also be done without this scatter chart. Going from one dimension to two dimensions is more useful, as it directly can be translated to do a kNN machine learning trading strategy. Have a look at the following chart. It shows the scatter of two indicators and the implication on the next days market move.

Lets start with he right chart. As you can see the red and green dots are evenly distributed, meaning there is no useful correlation between the used indicators and the movement of the market on the day after. If you would use a kNN algorithm with these two indicators, I would bet it would not return great results. Even if you would get a positive return, it might just be a lucky hit or curve fitting.

The opposite is true for the chart on the left. Here you can see some nice clustering of the red and green dots. Low indicator levels seem to predict a bearish move, high indicator levels result in a bullish move on the next day. A distribution like this is the perfect starting point for investing some time in a kNN machine learning  trading strategy. The kNN algorithm would give you a strong prognosis with high or low indicator levels, and most probably only a weak or no prognosis when the indicators are around 50. The returns will be stable, no curve fitting problems should be expected.


Using a scatter chart can give you a nice visual indication if your indicator might be useful for prognosing the next days market move. This is valuable insight, as you can see the whole data universe with one glimpse, even before you do a thoroughly statistical analysis. Numbers can deceive you, pictures usually tell the complete story.

[Tradesignal code]




Machine Learning – KNN using Tradesignal

I always thought that inspiration and experience is a key factor in trading. But everytime my chess computer beats me without any inspiration, just by brute force, I start to reconsider this assumption. This article will be about a brute force approach in trading.

Rule based trading

I have never been a great believer in classical technical analysis. If you ask 2 analysts about the current trend in the market, you get at least 3 answers. So I turned to algorithmic trading, using the tools of technical analysis in a new way, doing if..then conditions, backtesting them, refining the rules and parameters until the desired result was shown. These if..then based conditions, like if the market is above it`s 200 day line then go long, are mostly found by experience and inspiration. Isn’t my brain just a neural network which can be trained with historic data (experience), enhanced with a glass of wine for the inspiration?

Today I would like to take a voyage into machine learning. I would like to let my computer find the rules by itself, and just decide if I like the results or not. I’ll have the glass of wine with some friends and let the machine do the job; This sounds tempting to me, but can life really be as easy?

Unsupervised machine learning – kNN algorithm

The knn algorithm is one of the most simple machine learning algorithms. Learning might be the wrong label, in reality it is more of a classification algorithm. But first let’s see how it works.

The scatter chart above is a visualization of a two dimensional kNN data set. For this article I used a long term and a short term RSI. The dots represent the historic RSI values. Have a look at the fat circled point. It just means, that todays RSI1 has a value of 63, and RSI2 got a value of 70. Additionally the dots have got colours. A green dot means the market moved up on the following day, a red dot shows a falling market on the day after.

kNN – k nearest neighbours

To do a prediction of tomorrow’s market move, the kNN algorithm has a look at the historic data (shown on the scatter plot) and finds the k nearest neighbours of today’s RSI values. As you can see, our current fat point is surrounded by red dots. This means, that every time the 2 RSI values have been in this area, the market fell on the day after. That’s why today’s data point is classified as red. Call it classification or prediction, the kNN algorithm just has a look on what has happened in the past when the RSI indicators had a similar level. Have a look at this video, it is a great explanation on how the algorithm works.

kNN in Tradesignal

Computer kiddies would implement this algorithm in Python or R, but I would like to show you an implementation with the Tradesignal programming language Equilla. It is way faster than Python, and has got the advantage that I can directly see all the advantages and disadvantages on the chart. It is not just number crunching.

To implement the algorithm in Tradesignal we first have to do the shown scatter plot, but not graphically but store the 2 rsi values and the next days market move(colour of dots) into an array.

In line 8&9 the rsi values are calculated, line 12&13 calculates the next day`s market move. Line 15 to 20 then stores the data into the training data array. This is done for the first half of the data set, for my example I will use the data from bar 50 to 1000 on my chart of 2000 data points.

The next task to complete is to calculate the distances of today’s rsi point to all the historic points in the training data set.

Line 23 to 27 calculates the euclidean distance of today’s point to all historic points, line 29 then creates a sorted list of all these distances to find the k nearest historic data points in the training data set.

We are nearly done. The next step is just to find out what classification (colour) the nearest points have got and use this information to create a prediction for tomorrow. This is done in lines 33 to 35

Have a look at the scatter chart at the beginning. If this would be the data stored in our training data set, the prediction, using the 5 nearest neighbours, would be -5. All the 5 nearest neighbours of our current data point are red.

Now that we got a prediction for tomorrow, we just have to trade it:

kNN algorithm performance

Lets have a look if this simple machine learning algorithm works. Using 2000 days of backward adjusted brent data, I used a 14 and 28 day RSI to predict the next day move. The training was done on bar 50 to 1000, and I used the 5 nearest neighbours for the classification.

Knn algorithm – conclusion

Judging on the shown graph it seems to work. It seems to be possible to use these 2 RSI indicators to predict tomorrow’s brent move.

kNN algorithm gives me a framework to test all kind of indicators or even different data sets easily and see if they have got any predictive value.

This is definitely an addition to classical algorithmic trading, using if..then conditions build from experience and intuition.

But you might still need some intuition to find the right data sets, indicators and parameters to get a useful prediction. Not everything can be done by machine learning…




Measuring your EDGE in algorithmic trading

There are a lot of statistics which can be used to describe algorithmic trading strategies returns. Risk reward ratio, profit factor, Sharpe ratio, standard deviation of returns… These are great statistics, but they miss an important factor: Are your returns statistically significant or just a collection of lucky noise. The EDGE statistic might me the answer to this question.


Statistics in trading:

If the returns of your trading strategy are positive with in-sample and out-of-sample data this is a first sign that you are on the right path. The next step would be to have a look at the risk-reward ratio of your trading to get an impression if the strategy might be useful in a real world environment.

Assuming that your average yearly returns are about twice as big as the worst case historic draw down you can even be more confident that your strategy is useful. But there is still one thing to check before you can be sure that you are not just seeing a curve fit bullshit strategy. The standard deviation of the daily returns vs. your average daily return.

Defining EDGE

Assume your strategy made 250$ over the last year. This averages to about 1$ per day. This 1$ is a good or bad return, depending on the standard deviation of your equity line. If the standard deviation of your equity is 2$, then the 1$ average return strategy would be a bad strategy, as your average returns are way too small in respect to the volatility of your equity. If your volatility of your return curve would just be 50ct and you still make 1$ per day on average, your strategy would be ingenious.

Edge is the ratio of your average returns vs the volatility of your equity line. To be on the safe side,  your average return should be about 5% above the 90% confidence interval of your equity line volatility.

The left chart is a strategy trading an one month RBOB time spread, the right chart shows the same strategy trading German power. Rbob has got an edge of 3%, German power has got an edge of 5%.

If I would have to select which market I want to trade with this sample strategy, I surely would select German power over the rbob time spread. Both curves have their up and downs, but rbob is heavily relying on a lucky trade in September. This lead to a high standard deviation of the equity line , giving you a low edge reading.


Observing the ration between your average daily returns vs. the volatility of your equity curve can give you some valuable insights in the quality of your strategy. If it just called a few lucky trades in history, it will also show a high volatility in returns. And this you most probably want to avoid when turning to algorithmic trading. It`s not just the absolute profit at the end of the year, it is also the path you took to get to this number. The smoother, the better!

[Equilla / Easy Language code for EDGE indicator]


Ranking: percent performance and volatility

When ranking a market analysts usually pick the percent performance since a given date as their key figure. If a stock has been at 100 last year and trades at 150 today, percent performance would show you a 50% gain (A). If another stock would only give a 30% gain (B), most people now would draw the conclusion that stock A would have been the better investment. But does this reflect reality?

Percent Performance and Volatility

In reality and as a trader I would never just buy and hold my position, I would always adjust my position size somehow related to the risk in it. I like instruments that rise smoothly, not the roller coaster ones which will only ruin my nerves. So ranking a market solely by percent performance is an useless statistic for me.

Lets continue with our example from above: if stock A, the one who made 50% has had a 10% volatility, and stock B, the 30% gainer, only had a 5% volatility, I surely would like to see stock B on top of my ranking list, and not the high vola but also high gain stock A.

Risking the same amount of money would have given me a bigger win with stock B.

Combining Performance and Volatility

To get stock B up in my ranking list I will have to combine the absolute gain with the market volatility in between. This can be done quite simple. Just add up the daily changes of the stock, normalized by market volatility.Have a look at the formula of this new indicator:

index(today)=index(yesterday)+(price(today)-price(yesterday))/(1.95*stdev(price(yesterday)-price(2 days ago),21))

In plain English: Today’s Vola Return Index equals yesterdays Vola Return Index plus the daily gain normalized by volatility

So if the index has been at 100, the volatility (as a 95% confidence interval over 21 days) is 1 and the stock made 2 points since yesterday, then today’s index would be 100 + 2/1 = 3

Vola Return Index vs. Percent Return Index

Lets have a look at a sample chart to compare the 2 ranking methods. I therefore picked the J.P.Morgan stock.

The upper indicator shows you a percent gain index. It sums up the daily percent gains of the stock movement, basically giving you an impression what you would have won when you would have kept your invested money constant.

The indicator on the bottom is the Vola Return Index. It represents your wins if you would have kept the risk invested into the stock constant. (=e.g. always invest 100$ on the 21 day 95%confidence interval of the daily returns)

Have a closer look at the differences of these two indicators up to October 2016. JPM is slightly up, and that`s why the percent change index is also in the positive area. During the same time the Vola Return Index just fluctuates around the zero line, as the volatility of JPM picked up during this period of time. To keep your risk invested constant over this period of time you would have downsized your position when JPMs volatility picked up, usually during a draw down. No good.

The same can be observed on the upper chart, showing the last months movements of the index. Right now, after the recent correction the percent change index is, like the JPM stock, up again. On the other side the Vola Return Index is still down, due to the rising volatility in JPM.

Vola Return Index – Ranking

Lets put this to a test and rank the 30 Dow Jones industrial stocks according to the percent return index and using my Vola Return Index as a comparison, calculated since 01/01/2015.

The first three stocks are the same, they got the highest vola and highest percent return. But JPM and Visa would get a different sorting. Just see how low the JPM Vola Index is, it would not be the 4th best stock.

Percent returns says JPM and Visa are abou the same, only the Vola Return Index shows that VISA would have been the better investment vehicle compared to JPM. But see for yourself on the chart…


Make sure your indicators show what you actually can do on the market. There is no use in just showing the percent gains of a stock if you trade some kind of VAR adjusted trading style.

Keeping you risk under control is one of the most important things in trading, and using the Vola Return Index instead of just plotting the percent performance can give you some key insights and keep you away from bad investment vehicles.


[code for tradesignal users]



Digitale Stochastic

Die slow stochastic ist ein alter Begleiter für alle Trader. Zuverlässig zeigt dieser Indikator die Überkauft und Überverkauft Bereiche an. Doch leider hat der Indikator einen entscheidenden Nachteil – er hat einen sehr unruhigen Kurvenverlauf.

Stochastic Digital – mehr als nur Überkauft / Überverkauft


Die Digitale Stochastic glättet die normale Stochastic nicht nur, sie sorgt mit einer digitalisierung auch für einen ansprechenden Kurvenverlauf.

Hier ein Beispiel für den DAX Future im Stundenchart.

Digitale Stochastic DAX Stunde

Unter der digitalen Stochastic sehen Sie die altbekannte slow Stochastic mit der selben Parametereinstellung. Der Chart ist grün gefärbt wenn die digitale Stochastic steigt, ansonsten ist der Chart rot hinterlegt.

Digitale Stochastic Trading

Continue reading

Ichimoku Scanner

Der Ichimoku Kinko Hyo ist in Japan einer der beliebtesten Indikatoren. Es ist ein Indikator der Informationen über Trendrichtung und Trendstärke kombiniert.

Zudem gibt er schon heute seinen zukünftigen Wert an. Damit ist er ein Unikum unter den Chart Indikatoren.


Karin Roller Ichimoku Analyse

Wie dieser großartige Indikator interpretiert wird, habe ich hier aus der gestrigen DAX Tagesanalyse von Karin Rollers Webseite fit4trading.de kopiert. Sie definiert im Wesentlichen 5 Kriterien nach denen der Ichimoku Indikator zu bewerten ist.

Ichimoku Scanner

Anhand dieser 5 Kriterien habe ich einen Oszillator entwickelt, der ihnen auf einen Blick zeigt, wie der Ichimoku Indikator aktuell zu interpretieren ist.

Dreht man die Logik dieser 5 Ichimoku Kriterien um, erhält man einen Oszillator der immer zwischen -5 und +5 pendelt. (Den Tradesignal Code dazu finden Sie am Ende des Artikels)

Neben dem absoluten Wert des Indikators ist natürlich auch seine Richtung von Interesse.  Sehen Sie am nächsten Bild, wie selbsterklärend die Interpretation dieses Ichimoku Oszillator ist.

DAX Ichimoku Chart

Aktuell steht der Oszillator, wie auch Karin Rollers Ichimoku Analyse, auf plus 5 – alles bullish.

Ichimoku DAX Scanner

Continue reading

Opening Range Breakout

Ein Opening Range Breakout System von Perry Kaufmann.

Es wurde im Magazin “Technical Analysis of Stocks&Commodities” im Juli 1994 besprochen, und wie es scheint, funktioniert es noch immer.

Das System wartet die erste Handelsstunde ab und geht dann bei Ereichen eines neuen Hochs oder Tiefs  long oder short.  Die Einstiegs Order (Stop Buy / Stop Sell) wird nicht exakt auf das Hoch / Tief gelegt, sondern ein paar Punkte darüber /darunter. (hier 20 Ticks)

Prinzipiell ist die Strategie der Afternoon Trader Strategie sehr ähnlich.

TSM(S) 1st hour breakout detail

Da die hier vorgestellte Systemversion  ursprünglich für dieTradestation 2000i in Easy Language geschrieben wurde, ist das Laden von 3 Zeitreihen ein wenig kompliziert gelöst. Aber es funktioniert.

Backtest mit adjustiertem DAX Future:

TSM(S) 1st hour breakout backtest

zum Tradesignal Equilla Code Passwort “code”

DAX Marktbreite und 200 Tage Linie

Bald ist es wieder so weit und der DAX steigt über seine 200 Tage Linie. Das wäre an und für sich nichts Besonderes, steigt oder fällt der DAX doch jeden Tag über irgendeinen gleitenden Durchschnitt, doch ist die 200 Tage Linie etwas besonders an sich: Sie ist ein selbst erfüllender Indikator!

 Bankberater, Bild, Hausfrauen

Wenn jemand eigentlich nichts über technische Analyse weiß, die 200 Tage Linie kennt er. Jeder Bankberater versucht damit seine Aktien zu verkaufen; Wenn der Markt über der 200 Tage Linie liegt soll das  ein bullishes Signal sein.

DAX Above 200 Day Average


Und in der Tat, da jeder diesen Indikator kennt, ist es tatsächlich ein bullishes Signal wenn der Markt über seiner 200 Tage Linie liegt, schlussendlich trauen sich dann alle die fast nix von technischer Analyse wissen in den Markt.

DAX Marktbreite

Um zu sehen ob so ein Schnitt des DAX über die 200 Tage Linie auch signifikant oder nur ein Strohfeuer ist, kann man die Marktbreite des Index untersuchen.

Marktbreite=Wie viel % der Aktien eines Index liegen über der 200 Tage Linie

Diesen Indikator sehen Sie unter dem DAX Chart abgebildet.

DAX Above 200 Day Average history

Allgemein gilt für die Interpretation, dass wenn der DAX über der 200 Tage Linie liegt und mehr als 50% der Aktien des DAX ebenfalls über der 200 Tage Linie liegen, man trendfolgend vorgehen kann. Wenn dann einmal 100% der Aktien über der 200 Tage Linie liegen ist die Blase meist zu Ende und man sollte die Position mit einem engen Stop absichern.

zum Tradesignal Equilla Code Passwort “code”

Selbstlernende Handelssysteme

Ein jeder kennt die klassischen Indikatoren wie RSI oder Stochastic. Und ein jeder kennt die dazugehörigen Handelsanweisungen: Long, wenn überverkauft, Short wenn überkauft. Und zumindest im Lehrbuch funktioniert das auch. Aber wie sieht das ganze am realen Chart aus? Würden Sie dem Lehrbuch vertrauen und Ihren Kunden auch einen baldigen Kauf empfehlen wenn der RSI unter 20 liegt?

Testen anstatt zu studieren

Schön, wenn ein Indikator im Lehrbuch funktioniert, doch will ich hier ein Verfahren darstellen, bei dem der Indikator selbst angibt ob, wann und wie gut er funktioniert! Dazu habe ich mir für diesen Beitrag den RSI Indikator vorgenommen.

Zunächst wird der Wert des Indikators betrachtet, sowie, ob er steigt oder fällt. Mit diesen beiden Kriterien lässt sich der RSI einfach klassifizieren.

RSI Prognose

Dann erfolgt der eigentliche Backtest: Innerhalb der letzten 1000 Bars wird nun geschaut, wie sich der Markt bei einem gleichen Indikatorstand (zwischen 90 und 100) und Richtung (über Triggerlinie) verhalten hat.


Am Bild kam dies innerhalb der letzten 100 bars 36 mal vor. Dabei war die durchschnittliche Bewegung innerhalb der darauffolgenden 5 min DAX Futures Kerze -0.03%. Der RSI hat beim aktuellen Stand also eine negative Kurs Prognose.

Dass es auch nach dem nächsten bar statistisch nach unten geht, sieht man an den 5 Prognose Punkten am Chart. Sie zeigen, wie sich der Markt statistisch innerhalb der nächsten 5 Bars verhalten hat, unter der Bedingung, dass der RSI den aktuellen Stand und Richtung hatte.

Markt Performance als Indikator

Der obige Screenshot zeigt den Indikator und die Prognose für den kommenden bar (sowie die 4 darauf folgenden). Er zeigt jedoch nicht, wie sich diese Prognosen in der Vergangenheit verhalten haben, in welchen Bereichen der Indikator in der Vergangenheit seine höchste Aussagekraft hatte. Dies ist am nächsten Chart dargestellt.

RSI Prognose

Am Bild ist unter dem eigentlichen RSI seine aktuelle prognose für den nächsten Bar dargestellt. Um diese prognose ist ein Bollingerband gelegt, um so die Bereiche zu definieren, an welchen der RSI seine höchste Aussagekraft hat (= die stärkste Bewegung vorhersagt)

Continue reading

Reality vs. Robert W. Colby, CMT

Dont`t believe!

Papier ist geduldig, darum ist es oft besser wenn man selbst testet bevor man ein veröffentlichtes Handelssystem mit seinem Geld ausprobiert. Heute geht es hier um einen Handelssystem out of sample Test

Ein schönes Beispiel dafür ist eine Strategie aus Robert Colbys Buch “The Encyclopedia of Technical Market Indicators“, 2nd edition, 2003, page 791ff.

Darin wird ein einfaches moving average crossover Systeme vorgestellt, welches anscheinend seit beinahe 100 Jahren phänomenale Gewinne verspricht.

Hier eine Kopie aus dem Buch:

colby wma strategy


Tradesignal Backtest

Continue reading