Algorithmic Trading Tips 10.

ALGORITHMIC TRADING WITH RENKO CHARTS.

HOW TO COMBINE RENKO CHARTS AND BAR CHARTS TO CREATE A PROFITABLE TRADING STRATEGY.

Renko charts are a fascinating chart type, which filters out insignificant price information. For this reason, they are ideal for the development of trend-following strategies. In our three part series we will show you step by step how you can combine traditional bar charts with Renko charts and put them together to a complete strategy.

PART 1: How to define trend direction and local highs and lows.

Strategy description.

The general idea behind this trading strategy is a trend following approach. Therefore we will have to find out if there is a trend and define its direction. In the next step we will use the local highs and lows for the entry and exit. If our trend detection thinks that there is a bullish trend in the market, we will go long if the market makes a new high. To close the long position we will use the local lows. If the market makes a new low, this will be our exit signal. Additionally some kind of trailing stop to lock in profits and reduce risk will be required. If done, we will have a fully automated trading strategy that can be tested for profitability in any given market.

Defining the trend & local highs and lows.

Let us start with the definition of the trend first with a classic approach which uses two moving averages. If the short average is above the long average, and the market trades above the short average, this will be our definition of an up-trend. Don’t worry about the period of the moving averages, when the strategy is done Tradesignal will find the perfect period using the built-in optimizer.

Because this is quite a simple concept, which can be found in any beginners guide to technical analysis, we will also use the local highs and lows so the quality of the trend detection itself is not so important. While bar charts or candlestick charts offer no objective and satisfying solution, Japanese Renko charts are the perfect choice for defining local highs and lows. Similar to point & figure charts, they show the price without a continuous time axis and are constructed from “boxes”, each box representing a specific price change. For example, a Renko chart where one box represents 10 points and the markets moves up 100 points, the Renko chart will show you 10 bullish boxes; regardless if this move takes place in one day or one year. If the market moves less than 10 points, no new box will be drawn. To reverse the direction a minimum counter move of at least 10 points will be needed. As you can see, this simple box algorithm filters out small price moves, so the fuzz is being removed and only significant price moves are plotted.

Now have a look at the chart and you will see how easy it is to define local highs and lows in an objective way: A local high is defined as the point, where the Renko chart changes from bullish boxes to bearish boxes. That’s all! The following comparison between a candlestick chart and a Renko chart speaks for itself.

FIG. 1: RENKO CHARTS SHOW TRENDS AND REVERSALS IN A CLEAR AND OBJECTIVE MANNER. HENCE THEY ARE A VERY GOOD TOOL IN A SIMPLE TRADING SYSTEM.

Programming the indicators.

Using this definition of local highs and lows we can write a short script to calculate these points on the Renko chart and show them on a candlestick chart. The calculation of the highs and lows is done with the following Renko Master indicator.

Two global variables above were used in order to pass this information to the following Renko Slave indicator, which in turn plots the Renko highs and lows on a classical candlestick or bar chart by plotting points or circles (see code 2).

// definition of global variables

Variables:​​ renko::hi,​​ renko::lo;

 

// if there is a bearish renko today and there was a bullish renko yesterday, then // yesterdays close (+1 renko) is a local high ​​ 

if​​ close<high​​ and​​ close[1]>low[1]​​ then​​ renko::hi=close[1]+(high-low);

// if there is a bullish renko today and there was a bearish renko yesterday, then // ​​ yesterdays close (-1 renko) is a local low

if​​ close>low​​ and​​ close[1]<high[1]​​ then​​ renko::lo=close[1]-(high-low);

 

CODE 1: Equilla Code for the indicator „Renko Master“.

meta:​​ subchart(false);

 

// get the renko local highs and lows and plot them on the barchart

drawsymbol(renko::hi);

drawsymbol(renko::lo);

 

CODE 2: Equilla Code for the indicator „Renko Slave“.

Do it yourself manual.

How to chart this graph on your own and see local highs and lows from the Renko chart on another chart? Very simple:

  • 01. Open a chart for your underlying
  • 02. Add the same instrument as a sub chart below
  • 03. Set one of both charts to Renko
  • 04. Drag and drop the Renko Master indicator onto the Renko chart
  • 05. Drag and drop the Renko Slave indicator onto the candlestick chart

FIG. 2: USING THE RENKO MASTER AND SLAVE INDICATOR THE LOCAL HIGHS AND LOWS FROM THE RENKO CHART ARE TRANSFERRED TO THE BAR CHART. THE BOX ALGORITHM FILTERS OUT SMALL PRICE MOVES, SO ONLY SIGNIFICANT PRICE MOVES ARE PLOTTED.

By implementing both indicators a significant step towards our Renko trading strategy is accomplished. In the second part of this mini series we will add a trend detection and colouring of the chart based on the trend direction, which will mark another step forward. The third issue of our Renko trading strategy series will provide a programming code which defines the entry and exit rules.

 

PART 2: LONG OR SHORT? THE COLOR OF THE CHART WILL TELL YOU!

The first part of this mini series showed you a way to combine different chart types and pass information from one chart to another, using global variables. We used Renko charts to calculate local highs and lows. These important chart points where then displayed on a Candlestick chart. The second part of this series will utilise moving averages to define the direction of the current market trend, combining it with the Renko highs and lows and colour code the chart according to the outcome of our computer analysis. At the end of this article you will have a chart that turns green when it is time for a long position, and red, if the bears have taken control.

Trend detection made easy.

To define a bullish market we will proceed as recommended by any book on technical analysis: If the short moving average is above the long moving average and the market is trading above the short moving average, this will be our definition of a bullish trend. Just reverse the conditions to get the definition of a bearish market. Apparently, this trend definition is more than primitive. It doesn`t account for volatility or volume, so used on its own it most probably will generate many bad signals. But don’t forget – we already have calculated the local highs and lows of the market, and they will filter out many of the bad signals. Therefore we just have to add one more condition: If the averages signal a bullish market phase and the price trades above its most recent local high, then – and only then – our trend detection should colour code the chart in green. So there is no bull market unless the price generates a new high.

Programming code.

Now let`s have a look at the code of this trend detection indicator. The ‘meta’ section defines where this indicator should be shown on the chart. ‘Sub chart (false)’ means that it is shown on the chart, not in a separate sub chart like the RSI. The input section defines the length of the moving averages. By doing so the periods can be optimized later on to adjust this indicator to any market and time frame. The variables section is needed to define the placeholders for our calculations. Beside the local variables for the moving averages, the colour and the Renko highs and lows, two more global variables were added to pass the outcome of this indicator to the trading strategy. The global colour is needed to define whether the market is in a long or short mode. The global long average will be used as some kind of trailing stop loss (to be described in part 3 of our series).

Meta:​​ subchart(false); ​​ // indicator is drawn on chart, not as a subchart like RSI

Inputs:​​ LongPeriod(54),​​ ShortPeriod(21);​​ // Period of the short moving average

Variables:​​ shortAV,​​ longAV,​​ colour,​​ trend::colour,​​ global::longAV,​​ currenthigh,​​ currentlow;

 

// calculate long and short average

longAV=average(close,LongPeriod);

shortAV=average(close,ShortPeriod);​​ 

 

drawline(shortAV);

drawline(longAV);

 

// get the renko high/low​​ 

currenthigh=renko::hi;

currentlow=renko::lo;

 

// basic colour of barchart (if no trend)

colour=black; ​​ 

 

// definition of bearish trend

if​​ close<shortAV// close below short average

and​​ shortAV<LongAV ​​ // short average below long average

and​​ low<renko::lo  ​​​​ // barchart low is below last local renko low

then​​ colour=red;​​ // then colour=red (=bearish)

 

// definition of bullish trend​​ 

if​​ close>shortAV// close above short average

and​​ shortAV>longAv// short average above long average

and​​ high>renko::hi ​​ // barchart high is above last local renko high

then​​ colour=darkgreen;​​ // Wenn bullish dann grün

 

drawbar(open,high,low,close,​​ colour,colour);​​ // draw the colour coded barchart

 

// pass the colour information to other scripts

trend::colour=colour;

global::longAV=longAV;

CODE 3: Equilla Code for the „Trend Paint Renko Filter“.

The following chart shows the EUR/USD daily chart with the Trend Paint Renko Filter discussed above. The price chart is being coloured green (red) when the following conditions are met: Firstly, the moving averages have to signal a bullish (bearish) market phase. Secondly, the price has to break above (below) the previous Renko high (low).

The first half of 2012 serves as a good example for the advantage of using the local highs and lows as an additional filter. As you can see, no bullish trend had been detected, even though the price broke above the moving averages.

FIG. 3: EURUSD DAILY CHART WITH “TREND PAINT RENKO FILTER” AND LOCAL HIGHS AND LOWS DERIVED FROM THE RENKO CHART.

Conclusion.

With the second part of our Renko trading series we fulfilled another important requirement for our trading strategy. In the first step all conditions for a long or short entry were clearly defined by combining the moving averages with the local highs and lows. Then we programmed a code which colours the price chart subject to the trend condition. Green colouring signals a bull mode while a red chart signals a bear mode – very simple isn`t it? In our third and last part of the Renko series we will show how the trading strategy generates entry orders, how it can be tested and how well even such a simple strategy performs.

 

PART 3: How to assemble all components to a full trading strategy.

The first and second parts of this special Renko Trading Tips showed a way to define a trend using the Renko highs and lows with moving averages. At the end of part two a bar chart was colour coded according to our computer trend analysis, the colour and the long moving average were saved in a global variable. Using this information we will now generate the actual trading signals. When done, we will have a complete automatic trading strategy that can be back tested and optimized.

Entry and exit.

In the previous Trading Tips issue we showed that the colour of the bar chart defines whether the market is in bull or bear mode. As we have got the colour of the chart in our global variable we can start with two simple orders for the position entry:

  • If the chart is green then open a long position
  • If the chart is red then open a short position

 

That`s just the entry. Additionally we need some kind of exit. One possibility would be to define a black chart as an order to be flat, since it means that there is no trend. But that would not be the best idea for two reasons. When you have a close look at the colour coded chart you will notice that there are some black days within a fully functional trend. The market might just rest for some days, and it would be useless to close out the position with the first black day. Usually the market continues its trend very soon, so constantly getting in and out of position just costs a lot of money. On the other side there might be a fast trend change, and our trend detection is just too slow, so we might even want to get out of a long position although the bar chart still is coloured green.

The proper solution is to define a two-step exit. To get out of a long position the long moving average is used as some kind of trailing stop, while the last local Renko low serves as a chart based stop. The system gets us out if the average or the local low is touched (whatever comes first). The same logic applies for the short side.

PROGRAMMING CODE.

The following code represents the trading strategy. First a variable for the colour of the chart is defined. Then the global colour variable is written into the local one. This seems to be a useless thing, as the global variable will always contain the same value as the local one, but this trick is used to bypass a very specific Tradesignal feature (global variables do not have a value for yesterday). This just means, that you can not ask the question “what colour did the chart have on the bar before” using the global variable. But you can do so using the local one! Therefore the global variable was written into the local one.

After the colour has been saved the entry command is the next part of the code. Translated into plain English it goes like this:

If the chart is green and the chart has not been green on the bar before and the chart has not been green 2 bars before then go long at the end of the current bar.

The term “not green yesterday and the day before” is another programming trick. It reduces the signal frequency in uncertain times; uncertain times when there is no strong trend and our very basic trend detection is switching between green and black on a daily basis. The entry condition for the short entry is just the same as for the long position, only that the chart has to be red. Next in the code comes the exit. As mentioned before two levels for a possible exit are used. The ‘maxlist’ and ‘minlist’ command takes care of which stop level is closer to the current price and therefore used for exit.

Variables:​​ colour;

 

 

colour=trend::colour;

 

if​​ colour=darkgreen​​ 

and​​ colour[1]<>darkgreen​​ 

and​​ colour[2]<>darkgreen​​ 

then buy this bar​​ on​​ close;​​ 

 

if​​ colour=red​​ 

and​​ colour[1]<>red​​ 

and​​ colour[2]<>red​​ 

then short this bar​​ on​​ close;​​ 

 

sell next bar​​ at​​ maxlist(renko::lo,​​ global::longAV)​​ stop;

cover next bar​​ at​​ minlist(renko::hi,​​ global::longAV)​​ stop;

CODE 4: Equilla Code for entry and exit.

Adapting the strategy to your market.

Drag and drop the strategy onto the bar chart, and if everything goes well, you should see an equity line appear as a new sub chart. This equity line gives you the theoretical profit of this specific strategy in your chosen market.

FIG. 4: THE RENKO TRADING STRATEGY PRESENTED IN OUR TRADING TIPS SERIES GENERATED STABLE RESULTS ON A LONGTERM BASIS. IT CAN BE USED FOR ANY MARKET AND CAN BE ADAPTED BY MODIFYING BOTH THE BOX SIZE AND THE LENGTH OF THE MOVING AVERAGES.

If you wish to adapt this strategy to your favourable market, there are two things you can do: First you can change the size of the Renko bricks. Usually a box size of about 0.5% to 2% is chosen. Whether you would like to enter a fixed amount on the properties page of the chart or rather use a percent value – with Tradesignal you can do both. The other thing is the length of the moving average. To find the best moving average for your market you can use the built-in optimizer. How to optimize moving averages without falling into the curve fitting trap will be the topic of the next trading tip.