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.
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.
then buy this bar on close;
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;
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.