# How to program a Renko strategy backtest

Having tested and used a buy-and-hold strategy similar to Clenow since 2020 or so, I had to learn the hard way that it makes a difference to see a 35 % drawdown in a backtest graph, compared to seeing the savings shrinking 35 % in reality in the past 18 months.

Therefore I would like to take the good things from Clenow and to develop a long-only trading strategy, based on Renko principles.

Compared to classical chart models like KST (know sure things), I have the impression that trading with a Renko system is much more unagitated.

Trying to model this in the simplest way in AmiBroker showed me that I have limits in knowing how to apply AFL. Therefore I would like to ask for help in this forum.

My questions are:

• How can be calculated with 2 % Renko bars in AmiBroker? As it looks is there a function â€śRange Barâ€ť, but I could not find any definition or example how to use it in backtests.
• How does the formula â€śClose higher than EMA 10â€ť look like when the EMA10 shall be calculated from Renko bars?
• And: How does the formula â€śClose below EMA10â€ť look like, when calculating with Renko bars?

I would appreciate if somebody could help me for the first first steps forward.

The backtesting framework I would like to use looks like this:

``````//// Formula 36 "Renko Strategy", Revision 1, February 2023
//
// Trade only when S&P 500 > MA 200:
// Switch to S&P symbol to calculate broad-market timing
SetForeign( "A0AET0" ); // S&P 500 in Tai-Pan EOD data
// now calculate, based on S&P 500:
MarketIsUp = C > MA( C, 200 ); // here C represents closing price of S&P 500
MarketIsDown = NOT MarketIsUp ;
// Go back to original data (current symbol):
RestorePriceArrays();

// Definition of lot size
NumPos = 11;
SetOption( "MaxOpenPositions", NumPos );
PositionSize = -100 / NumPos;

// Ranking with highest RSL in past 5 years
// PositionScore = 1000 + (Close / MA (Close, 1280));
PositionScore = 1000 + ((Close / MA (Close, 256)) + (Close / MA (Close, 128)) + (Close / MA (Close, 64)));

// The following 20 lines or so are based on the following recommendations:
// https://forum.amibroker.com/t/how-to-sell-all-titles-after-a-defined-period/23853/6
// Many thanks once more to Beppe, Fxshrat and MacAllen for your help

// Definition of trading periodicity
mth = Month();
dow = DayOfWeek();
mth_mod3 = mth % 3;
hy = mth % 6;

NewWeek = dow < Ref(dow,-1);
NewMonth = mth != Ref(mth,-1);
NewQuarter = mth_mod3 * !Ref(mth_mod3,-1);
NewHalfyear = hy * !Ref(hy,-1);
NewYear = Year() != Ref(Year(), -1);

PeriodStart = NewWeek;
// PeriodStart = NewMonth;
// PeriodStart = NewQuarter;
// PeriodStart = NewHalfyear;
// PeriodStart = NewYear;

// TradingDay = PeriodStart;
TradingDay = BarsSince(PeriodStart) == 1; // Second day in period

Bcond1 = MarketIsUp ;
// Here to define: C > MA (10), but in Renko. How can this be defined? Size of the Renko tiles should be 2 %
// Remove "//" in the following and fill in formula
// Bcond3 = ....................... ;

Buy = Bcond1 AND Bcond2 AND Bcond3;

// Selling conditions
Scond1 = Ref(TradingDay, 1) == 1; // REFERENCE TO FUTURE DATE (not using quotes)
// Here to define: C < MA (10), but in Renko. How can this be defined? Size of the Renko tiles should be 2 %
// Remove "//" in the following and fill in formula
// Scond2 = ....................... ;

Sell = Scond1 AND Scond2;

``````

@RetiTrader, if you search for "Renko" in the forum, you will find previous threads where other users have already discussed similar topics.
Also, if you go to the members' AFL Library and again search for Renko you will find a formula (posted by Mark Huang) that plots a Renko chart and shows how to use the calculated OHLC values in other functions like MA().

Maybe it's not 100% what you need, but surely studying the existing threads and some example code will be a good place to start.

1 Like

Hi @beppe - Thank you for your suggestion and sorry for the late answer.

I found this http://www.amibroker.com/members/library/formula.php?id=521 what seems to be the basis most of the people start with.
What irritates me a little bit is the comment of @tomasz here: RENKO (similar to RANGE BAR) - #8 by cdj. I thought to calculate Renko with the close value of the end of the day would work, but there seems to be something behind the curtain I do not understand yet.

With so much amazing tech available freely now, why don't you just ask ChatGPT? It is really good in answering general questions like yours in a matter of seconds. Here it what it says about creation of Renko charts. And it is ALL GOOD info:

Renko charts are a type of technical chart used in financial analysis that are based on price movements, rather than time. They are built by drawing bricks or boxes, each of which represents a fixed price movement, regardless of the amount of time that has passed.

To create Renko charts accurately, it is necessary to have access to tick data, which includes every single price movement, up or down, for each security in the trading day. This is in contrast to end-of-day (EOD) data, which only provides the closing price of the security at the end of the trading day.

Using tick data is essential because Renko charts are based on price movements and EOD data does not provide information about the price movements that occurred throughout the day. Tick data captures every price movement, regardless of how small, and allows for the construction of Renko charts that accurately reflect the price dynamics of the security.

For example, if a Renko chart is based on a brick size of \$1, it means that every time the price of the security moves up or down by \$1, a new brick is drawn on the chart. This is only possible with tick data, which captures every price movement in real-time.

In summary, creating Renko charts requires tick data because they are based on price movements, and EOD data does not provide the necessary information to accurately construct these charts.

Hi @Tomasz - Thank you for your explanation. What I do not understand is the following: When I work with a trading system, based on EoD 2 % Renko Charts, why do I need tick data to draw the charts?

Did you read previous response at all? What happens if EOD bar candle height is MORE than 2%? What is candle height is say 10%? How would you know what happened INSIDE candle that is 10% high if the only data you have is EOD 10% candle?

Hi @Tomasz - Maybe we are not talking about the same. Today we had with Credit Suisse at the Swiss stock exchange a sharp decline which I use for explanation.

The first chart shows the development as line chart, the second one as Renko with 2% bricks.

What I would like to do is to model this kind of Renko chart in AmiBroker to make a backtesting with this. Buy/sell decisions shall be made by Renko crossing the EMA 10 or 20.

You did not answer the question. The questions were posted to trigger thinking and open your eyes as to "why you need tick data". The lack of answer shows that you are missing the point completely. The discussion only makes sense when one reads what other write. Without understanding how Renko chart is constructed you are lost like a child in a fog. You are trying to use the thing that you don't understand. Re-read (possibly several times) this until it "clicks"

As it was written ChatGPT would explain this again and again (as really I have no patience for such absolute basics). So here it comes:

Renko charts are a type of charting method used in technical analysis that uses price movement to create bricks, rather than time or volume. Each brick on a Renko chart represents a fixed amount of price movement, and the chart is constructed by stacking bricks in a diagonal fashion.

End-of-day data is data that captures the final price of a security at the end of a trading day. While end-of-day data is useful for many purposes, it is not suitable for creating Renko charts because it does not capture the price movements that occur WITHIN the day.

To create Renko charts, intraday data is needed. This data captures the price movements of a security throughout the trading day and allows for the creation of bricks based on price movement. Without intraday data, it is not possible to accurately capture the price movements needed to construct Renko charts.

Therefore, it is not possible to use end-of-day data to create Renko charts. In order to create Renko charts, you would need to use intraday data, which captures the price movements of the security throughout the trading day.

Hi @Thomaz - 2 things: a) I thought the two graphs are selfexplaining and b) it might be I'm really in the fog and can't see enough.
To a) and how I understand Renko charts: Credit Suisse closed last Friday, 10.3.2023, at 2.50 CHF. Today Monday, 13.3.2023 it closed with 2.26 CHF. Defining the Renko brick with 2 %, calculated from the last close, would mean 2 % is 0.0452 CHF. The decline on Monday is 2.50 minus 2.26 = minus 0.24 CHF. 0.24 CHF divided by 0.0452 CHF = 5.3 . The numbers must be rounded down. This means that for today 5 red bricks go into the chart.
To b) Why do I need every intraday tick detail, when I calculate like this and use the chart on a EOD day to day basis? In case I'm not only in the fog but complete blind, please help me.

How do you know from high and low price alone what happened inside EOD bar? You are making assumptions that are not valid. In your example you assume that prices inside one day move monotonically in single direction and that is false assumption.

Hi Thomasz - Thank you. The conversation in this forum seems to confirm what you are explaining: https://www.quora.com/Why-do-Renko-chart-based-automated-trading-systems-work-so-well-when-back-tested-but-not-when-live-trading . It is also a warning not to think one has found the Holy Grail when Renko backtests deliver good results, but the reality behaves different.
Based on this, I will compare a few trades with different chart types and indicators and come back when there are new insights.

The problem with Quora is that everyone can write an answer regardless if he or she has a clue or not. You can have 13-year old answering your questions as a self-appointed 'expert'. People who do have a clue rarely answer on Quora because they have better things to do in life. I would approach any information from "generic" pages like Quora or any social media for that matter with really big grain of salt. As recent study shows "It takes true stories about six times as long to reach 1,500 people as it does for false stories"

If somebody makes a statement (like in the "top answer") that "there is no such thing as failed backtest" he apparently did not do any single proper backtest in life. The purpose of backtest is to make your system fail, to know when it fails and why and with what probability. That is why we do stuff like walk-forward testing, sensitivity tests, survivorship bias removal and monte carlo analysis. But these are the things that Quora 'experts' never heard about. Idiots spread the nonsense 6 times faster than anyone is able to correct it and that is the problem with todays Internet.

It is not true that Renko by itself has a problem. Only Renko used incorrectly. As anything in life the devil is in the details. The violin will play excellently in the hands of skillful player and the same violin will be unbearable to listen in the hand of person who has no clue how to play it.

Renko in itself isn't bad or good. It is just lossy data compression (or rather aggregation) algorithm based on price movement and not on time. It absolutely has nothing to do with how realistic backtest results are. The basic thing for any data aggregation algorithm is to act upon the data when aggregated bar is completed, which means that you should act on completed Renko bar. Usually it means using one bar delay.

And obviously, you have to construct Renko bars correctly (as I explained many times above). If you are doing it wrong (like using EOD data as input), you are feeding the system with garbage. With garbage in you get garbage out.

1 Like

Hi @Tomasz - Thank you. I fully agree with your comments about Quora and your comments and explanations about Renko and backtesting in general.

The beauty of Renko is in my eyes, that this type of chart is much easier to read and understand than others becuase a lot of noise is filtered out.

Of course they need to be constructed correctly, as you write.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.