How to turn off your Strategy when it exceeds a Risk Limit

Managing your risk is the most important task for all traders. In this short article I would like to show you how to turn off your strategy in a backtest when a specific risk limit is exceeded. For example, if the current position`s loss is higher than 10 000 EUR, then the position will be closed and no further signals will be taken. The trading strategy will stay turned off.

Equilla Code for Risk Limit

Similar to the previous article on how to create a trend filter, I again use the SetTradingStatus function to create the Equilla code. Let us go through the script in detail:

  • In line 2/3 we define an input for our risk limit. It enables us to control the absolute amount for any instrument or strategy
  • Lines 5 and 6 contain one variable which is needed to colour the background of the chart once the risk limit was hit
  • Line 9 contains the if .. then … statement which compares the open P&L of the strategy with our risk limit
  • If the open P&L exceeds our risk limit, then all new orders will be blocked (line 13),
  • the current position is closed (line14) at the next bar and
  • the background of the chart turns red (line 15)

Equilla Code for Risk Limit

Practical example: Strategy is turned off after hitting Risk Limit

Let us take a look at the following chart which demonstrates how the risk limit code works in practice. The figure below shows the German baseload contract Cal19 with a dummy strategy which trades one contract for each long signal and exits after a few bars. I added the risk limit module we have programmed above and defined a maximum risk of 10k.

Trading Strategy triggers risk limit

After the strategy open P&L exceeded that level, the position was closed and all trading has been stopped. It will stay turned off so it can cause no further damage to the capital. Of course, you could use the code above for other purposes too, for example to create an alert when a specific risk level was exceeded or to switch from strategy A to strategy B etc.

Tradesignal® is a registered trademark of Tradesignal GmbH. Unauthorized use or misuse is strictly prohibited. Data by Thomson Reuters Eikon.

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to this Blog