Algorithmic Trading Tip – Building Risk Protection Into Your Trading
Is Algo Trading Good Or Bad? A Deeper Look
Updated January 2023
Algorithmic trading, or algo trading, has become increasingly popular in the financial markets in recent years. But is it really a good idea? In this article, we'll look at the pros and cons of algo trading to determine if it's ultimately a good or bad investment.
90% of traders out there build strategies the wrong way. How do I know that? It shows up in the statistics – most traders lose!
When most traders build a strategy, they have one goal in mind – maximizing profits. That’s not necessarily terrible all by itself – after all, you need profits to make it worthwhile.
More enlightened traders realize that the risk (drawdown) is a key measurement of a good strategy, and incorporate that into their strategy building. Most people would not like an algorithmic strategy that made $50K per year if it also had $100K drawdowns. Don’t you agree?
Hundreds of traders around the globe use the Strategy Factory® process, and that is exactly what they do with that process: find strategies with a good balance between profits and drawdowns.
Algor trading is a powerful tool to maximize your profits, but it also comes with risks that need to be managed. This guide will show you how to keep your risk under control and use algorithmic trading strategies to protect your investments.
Before I get into algorithmic trading risk management and protection techniques that have worked for me over the years, I'm going to start with some basics of algo trading and risk management.
Algorithmic trading, or algo trading, has become increasingly popular in the financial markets in recent years. But is it really a good idea? In this article, we'll look at the pros and cons of algo trading to determine if it's ultimately a good or bad investment.
90% of traders out there build strategies the wrong way. How do I know that? It shows up in the statistics – most traders lose!
When most traders build a strategy, they have one goal in mind – maximizing profits. That’s not necessarily terrible all by itself – after all, you need profits to make it worthwhile.
More enlightened traders realize that the risk (drawdown) is a key measurement of a good strategy, and incorporate that into their strategy building. Most people would not like an algorithmic strategy that made $50K per year if it also had $100K drawdowns. Don’t you agree?
Hundreds of traders around the globe use the Strategy Factory® process, and that is exactly what they do with that process: find strategies with a good balance between profits and drawdowns.
Algor trading is a powerful tool to maximize your profits, but it also comes with risks that need to be managed. This guide will show you how to keep your risk under control and use algorithmic trading strategies to protect your investments.
Before I get into algorithmic trading risk management and protection techniques that have worked for me over the years, I'm going to start with some basics of algo trading and risk management.
What is Algo Trading?
Algorithmic trading (or algo trading) is the use of computer-based strategies to buy and sell financial securities. I mainly trade futures with my algo systems, but others trade forex, stocks and even crypto. Algo programs are designed to identify profitable market opportunities and quickly execute trades without the need for human intervention. Algo trading relies on simple or sophisticated algorithms to analyze and interpret large amounts of data, identify trends, and make decisions based on these trends.
Advantages of Algo Trading
Algo trading offers a number of advantages:
1. Increased speed and accuracy (fat finger avoidance)
2. Reduce (but not eliminate) emotion
3. Ability to historically test strategies before going live
4. Reduced costs and transaction fees (depends on market though)
5. Enhanced liquidity
6. Improved risk management capabilities
7. Greater order size limits
8. Lower execution risk
With its ability to analyze vast amounts of data quickly and accurately, algo trading can help traders make more informed decisions in a fraction of the time that manual trading would require. In addition, algo trading can minimize the impact of human emotion which may cause traders to make poor decisions.
1. Increased speed and accuracy (fat finger avoidance)
2. Reduce (but not eliminate) emotion
3. Ability to historically test strategies before going live
4. Reduced costs and transaction fees (depends on market though)
5. Enhanced liquidity
6. Improved risk management capabilities
7. Greater order size limits
8. Lower execution risk
With its ability to analyze vast amounts of data quickly and accurately, algo trading can help traders make more informed decisions in a fraction of the time that manual trading would require. In addition, algo trading can minimize the impact of human emotion which may cause traders to make poor decisions.
Disadvantages of Algo Trading
There are potentially downsides to algo trading as well.
1. Can be expensive, since it requires the use of specialized computer systems and software programs to create, test, and implement strategies.
2. Additionally, although algo trading may lead to improved profits due to increased accuracy, consistency and speed of execution, it also carries a greater risk of losses due to unforeseen market anomalies or changes in the price level from unexpected events.
3. if a trader isn’t experienced with algorithmic trading or has inadequate technology or coding skills, they could face an even higher risk of loss.
4. Does not eliminate emotion (a common misconception)
1. Can be expensive, since it requires the use of specialized computer systems and software programs to create, test, and implement strategies.
2. Additionally, although algo trading may lead to improved profits due to increased accuracy, consistency and speed of execution, it also carries a greater risk of losses due to unforeseen market anomalies or changes in the price level from unexpected events.
3. if a trader isn’t experienced with algorithmic trading or has inadequate technology or coding skills, they could face an even higher risk of loss.
4. Does not eliminate emotion (a common misconception)
The Bottom Line: Is Algorithmic Trading Good or Bad?
While algorithmic trading can provide some benefits, there are also potential drawbacks to consider. Although the technology has been designed to minimize market manipulation and protect investors from losses, it is still not completely foolproof.
Careful consideration should be given to the type of strategy used and its implications on the investment portfolio, market conditions, and regulatory compliance. It is recommended that investors seek professional advice before experimenting with algorithmic trading systems.
Careful consideration should be given to the type of strategy used and its implications on the investment portfolio, market conditions, and regulatory compliance. It is recommended that investors seek professional advice before experimenting with algorithmic trading systems.
Algorithmic trading (or algo trading) is the use of computer-based strategies to buy and sell financial securities. I mainly trade futures with my algo systems, but others trade forex, stocks and even crypto. Algo programs are designed to identify profitable market opportunities and quickly execute trades without the need for human intervention. Algo trading relies on simple or sophisticated algorithms to analyze and interpret large amounts of data, identify trends, and make decisions based on these trends.
One key with algo trading, especially in the leveraged futures market, is that it is risky. And that is what the rest of this article is about - how to reduce the risk in algo trading systems.
This is another level to strategy building, one that many traders neglect with their algo trading – risk protection. The need for this became apparent to many people during the coronavirus scare of 2020. Very high volatility, quick and violent price swings, fast trends and quick pullbacks characterized many markets, not just equities.
Just look at a few markets from late February 2020:
This is another level to strategy building, one that many traders neglect with their algo trading – risk protection. The need for this became apparent to many people during the coronavirus scare of 2020. Very high volatility, quick and violent price swings, fast trends and quick pullbacks characterized many markets, not just equities.
Just look at a few markets from late February 2020:
During crazy times like this, maybe just surviving becomes the primary goal, rather than making money.
That is what this article is all about – techniques to reduce risk, on a strategy level. I’ll discuss and give examples of:
- Daily Loss Limiters
- Being Out of Trades on Weekends
- A High Volatility Kill Switch
- Equity Curve Trading
- And Much More!
I’ll be discussing the concepts, showing you some examples, providing code and generally giving you the tools and knowledge to incorporate these “risk managers” into your trading strategies.
With that, let's first discuss some basic risk management keys. After that, I'll provide some specific strategy and code ideas you can implement. So let’s get started!
Define Your Risk Parameters
Knowing your risk parameters is key when it comes to algorithmic trading. Before jumping into any trades, you must identify and define what constitutes as acceptable or unacceptable levels of risk.
This helps to establish clear criteria on how much capital you are willing to part with in each transaction and ensure that loss-limiting measures, such as stop losses, are effectively enforced. By setting strict risk parameters, it becomes easier to take steps toward minimizing the potential for losses.
This helps to establish clear criteria on how much capital you are willing to part with in each transaction and ensure that loss-limiting measures, such as stop losses, are effectively enforced. By setting strict risk parameters, it becomes easier to take steps toward minimizing the potential for losses.
Choose Appropriate Trading Strategies
When it comes to algorithmic trading, it’s important to understand the strategies you are using and whether they are suitable for your risk appetite. Scalping, day trading or swing trading – these strategies come with different levels of risk. Choosing a strategy that best suits your risk appetite can help you manage your losses and maximize profits while keeping risk under control.
Be sure to review each strategy carefully before implementing them in order to ensure that they meet your individual needs. Additionally, being aware of the common pitfalls associated with algorithmic trading will also provide valuable insights into minimizing risks associated with these strategies.
Be sure to review each strategy carefully before implementing them in order to ensure that they meet your individual needs. Additionally, being aware of the common pitfalls associated with algorithmic trading will also provide valuable insights into minimizing risks associated with these strategies.
Implement and Monitor your Trading Rules Consistently
An important aspect of algorithmic trading risk management is establishing and following a set of rules for your trading strategy. These rules should include parameters such as when to enter or exit a trade, which instruments to trade, how much risk to take and how much volatility can be tolerated.
Once the rules have been established, it’s important to ensure that they are being consistently applied to every trade – this will help minimize the risks associated with algorithmic trading.
Additionally, regularly monitoring trades for compliance with these rules can provide additional insight into any potential areas where risk needs to be managed more effectively.
Once the rules have been established, it’s important to ensure that they are being consistently applied to every trade – this will help minimize the risks associated with algorithmic trading.
Additionally, regularly monitoring trades for compliance with these rules can provide additional insight into any potential areas where risk needs to be managed more effectively.
Create a Realistic Backtesting Plan to Assess Performance
Before implementing an algorithmic trading strategy, it’s important to ensure that the rules associated with the strategy are properly backtested. Backtesting is a process of testing out a trading strategy on historical data in order to assess any potential risks associated with the strategy. I use an approach called "walkforward backtesting."
It’s important to create a realistic backtesting plan that takes into account key variables such as market conditions and volatility throughout the testing period. Additionally, it’s important to look for patterns in the data that can identify areas where risk must be managed more effectively. Once your backtest is complete, use information gained from this process to adjust your strategies accordingly.
It’s important to create a realistic backtesting plan that takes into account key variables such as market conditions and volatility throughout the testing period. Additionally, it’s important to look for patterns in the data that can identify areas where risk must be managed more effectively. Once your backtest is complete, use information gained from this process to adjust your strategies accordingly.
Adjust Strategies When Necessary
One of the most important things to remember when it comes to algorithmic trading is that strategies must be adjusted when necessary. Markets are constantly changing and adapting, so successful traders will assess and reassess their strategies on a regular basis.
By frequently monitoring performance and adjusting strategies as needed, traders will insert an extra level of protection in order to safeguard against potential losses due to changing market conditions.
The adjustments may be minor or completely different depending on the strategy in use, but the key is being able to quickly recognize a need for change and having the discipline to make those changes in a timely manner.
By frequently monitoring performance and adjusting strategies as needed, traders will insert an extra level of protection in order to safeguard against potential losses due to changing market conditions.
The adjustments may be minor or completely different depending on the strategy in use, but the key is being able to quickly recognize a need for change and having the discipline to make those changes in a timely manner.
Algo Risk Management & Protection - DETAILED EXAMPLES
Now with the basics out of the way, let's dig deep into specific risk protection and risk management approaches.
Baseline Strategy
For this study, I created a simple pullback type strategy, and applied it to 120 minute Crude Oil bars over the last 5 years.
NOTE: This strategy is for study purposes only. I am not saying this is a good strategy to trade.
Baseline Strategy
For this study, I created a simple pullback type strategy, and applied it to 120 minute Crude Oil bars over the last 5 years.
NOTE: This strategy is for study purposes only. I am not saying this is a good strategy to trade.
Although this strategy makes a decent amount of money of the 5 year period, it has significant and prolonged drawdowns. These will be useful to see if any of the risk protection measures can improve the strategy.
The strategy itself requires a long term uptrend, and a shorter term downtrend, in order to enter a long position. Vice versa for short positions.
It also includes an ATR based stop, with a ceiling of $3000 per contract. This type of stop was examined in an earlier article series on stop losses.
All the code below is in Tradestation format, but here are simple “plain English” instructions.
Plain English Rules
If the close crosses above the close “lookback” bars ago, and the close crosses below the close .5 “lookback” bars ago, go long. Vice versa for short trades.
The stop should be a multiple of Average True Range, with a maximum amount of $3000 per contract.
For this study, lookback was set to 10, and the ATR multiplier was set to 2.
NOTE: This strategy is for study purposes only. I am not saying this is a good strategy to trade.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - STRATEGY #1 - Baseline Strategy
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2);
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
Some important statistics for the baseline strategy:
The strategy itself requires a long term uptrend, and a shorter term downtrend, in order to enter a long position. Vice versa for short positions.
It also includes an ATR based stop, with a ceiling of $3000 per contract. This type of stop was examined in an earlier article series on stop losses.
All the code below is in Tradestation format, but here are simple “plain English” instructions.
Plain English Rules
If the close crosses above the close “lookback” bars ago, and the close crosses below the close .5 “lookback” bars ago, go long. Vice versa for short trades.
The stop should be a multiple of Average True Range, with a maximum amount of $3000 per contract.
For this study, lookback was set to 10, and the ATR multiplier was set to 2.
NOTE: This strategy is for study purposes only. I am not saying this is a good strategy to trade.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - STRATEGY #1 - Baseline Strategy
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2);
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
Some important statistics for the baseline strategy:
Risk Protection #1 – Daily Loss Limiter
All traders like to avoid losing days, right? But experienced traders know that is not possible. So, the next best thing is to limit the loss on really bad days. This can be a psychological life saver, and possibly an account saver.
The version created for this study calculates the loss since midnight (chart time), and exits all trades and prevents new trades if the loss exceeds a certain amount. This works well for X minute based bars.
Plain English Rules
Every day, calculate the total open plus closed equity for the strategy at the last bar before midnight. If during the next day, the current total equity minus the “midnight” equity is less than “equitylosslimit” exit all current positions and do not take any new trades.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey – Risk Protection #1 – Daily Loss Limiter
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),EquityLossLimit(1000);
var:EndDayEquity(0),CanTrade(True),CurrentEquity(0);
CurrentEquity=NetProfit+OpenPositionProfit;
If date<>date[1] then begin
EndDayEquity=CurrentEquity[1];
end;
CanTrade=True;
If NetProfit+OpenPositionProfit-EndDayEquity<-EquityLossLimit then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("DLL-L Exit") next bar at market;
BuyToCover ("DLL-S Exit") next bar at market;
end;
If you use daily bars, you can use a stoploss statement instead:
Sell next bar at close – xxx stop; //xxx is the price where daily loss limit would be hit
Results
To see the impact this Daily Loss limit had, I varied the daily loss limit from $500 to $10,000. At small daily losses, the performance of the strategy is definitely worse that the baseline profit of $40K. This makes sense, since with small loss limits, the market volatility will frequently lead to turning the system off.
From around $2000-$4000, the daily loss limit somewhat improves the performance, although not tremendously.
Above $4000, the daily loss limit is never activated.
So, the optimum result for the Daily Loss Limit is shown below:
Above $4000, the daily loss limit is never activated.
So, the optimum result for the Daily Loss Limit is shown below:
Looking at the results, you might conclude that the Daily Loss Limiter is good to have. But BEWARE! This is an optimized result. The $2500 limit is likely NOT to be the best daily limit going forward.
Recommendation
If you want to use a Daily Loss Limit, decide on the value to use BEFORE you run the backtest. Don’t necessarily expect a performance improvement, but instead use it because you like the psychological comfort of limiting your daily loss. Any performance improvement should be considered a bonus.
Risk Protection #2 – Wait A While After Losing Trade
Have you ever had a strategy that seemed to get “stuck” in a rut of losing trade after losing trade? Perhaps it was a counter trend strategy, constantly trying to go short in a bull market. I’ve definitely had strategies like that.
One way to minimize the damage (again, psychological and financial) is to put a delay on any signal after a loss. For example, once a losing trade is closed, wait 5 bars before taking another trade. This should give you some protection from the “catching a falling knife” syndrome – trying to trade against a trend.
Plain English Rules
After a losing trade, wait NextTradeDelay bars before taking the next trade.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #2 - Delayed Signal After Loss
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),NextTradeDelay(1);
var:CanTrade(True);
CanTrade=True;
If (positionprofit(1)<0 and barssinceexit(1)<NextTradeDelay) then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
Results
For this particular strategy, putting a delay on the signal after a loss does not improve things at all. In fact, it almost always makes performance worse, especially if the delay is significant (10 or more bars).
Recommendation
This type of risk protection is really suited for strategies where there is a potential for many consecutive losses. A counter trend strategy would be a good example. As with any of these risk protection techniques, it is best to incorporate the rule in the strategy BEFORE you backtest. Adding the rule after you see initial results is basically cheating the backtest.
I would feel comfortable using this approach on a strategy that I knew was designed to trade counter to the major trend.
Risk Protection #3 – No Open Trades Over Weekends
Imagine one of your algo strategies trades Crude Oil. On Friday March 6, 2020, near the close of the day you go long, at a price around the settlement price of 41.57. Even though oil fell about 5 dollars a barrel that day, you feel good because all kinds of bullish events can happen to oil over weekends.
Except this weekend is different. Coronavirus becomes much more newsworthy, and Russia and Saudi Arabia get into some kind of bizarre reverse price war over oil. On Sunday night, oil collapses and opens at 32.87, a drop of more than 20%, or $8,700 per contract.
You tell yourself “no more weekend” trades for me!
Plain English Rules
Close all positions at 4 PM Eastern on Friday. Do not allow any new trades, either.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #3 - No Weekends
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),FridayStoptime(1600);
var:CanTrade(True);
CanTrade=True;
If dayofweek(date)=5 and time>=1600 then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("Friday-L Exit") next bar at market;
BuyToCover ("FridayL-S Exit") next bar at market;
end;
This will get you out of the market Friday afternoon, unless Friday is a shortened holiday session. This can feel tremendous psychologically (imagine not having to worry about positions over the weekend!), but does it really help financially?
Results
Yikes!
Exiting all trades before a weekend has a really bad impact on Crude Oil:
The max drawdown is less, and the system is in the market a lot less (which by itself is a good thing), but you also have to give up almost 75% of profits. Clearly, for this strategy/market, the “no weekend” trading idea is a financial loser.
Recommendation
This is a neat idea (who would not want stress free weekends?), but the benefit may be more psychological than financial. In fact, as we see with this strategy, it might be terrible financially.
But, as with all ideas, I recommend you test it, adding it to your strategy from the start. Don’t create a strategy and then try to tack this on, since you’ll only accept it if performance improves (which is cheating!).
Instead, if you like the idea, try it for a while. If you find yourself unable to create good strategies, then this weekend requirement might be the reason, and you might want to eliminate it.
Risk Protection #4 – If You Can’t Stand The Heat, Get Out Of The Kitchen
Volatility is a double edged sword. As traders, we need volatility to profit from price movement. So some volatility is a good thing. But too much volatility is a bad thing. It can mess up our algos, and trade us in and out of trades in an endless whipsaw.
In March 2020 I created a YouTube video about Market Turmoil.
I created code that would temporarily turn off strategies. Many traders who watched the video were amazed at how well it worked.
One trader showed me this before and after:
So, at the very least, this high volatility kill switch is worth trying. Let’s see how it works on the Crude Oil strategy.
Plain English Rules
Close all open trades, and do not allow any new trades, if the true range of the just closed bar is greater than ATRmult times the average true range over the last 5 bars.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #4 - High Volatility "Kill" Switch
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),ATRMult(1600);
var:CanTrade(True);
//switch criteria
CANTRADE=TRUE;
If TrueRange>ATRMult*AvgTrueRange(5) then CANTRADE=FALSE;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("Vol-L Exit") next bar at market;
BuyToCover ("Vol-S Exit") next bar at market;
end;
Results
I optimized for different ATR multipliers, and the best case was better than the baseline case.
But if the ATR multiplier is too small (meaning the kill switch is more active), performance can quickly deteriorate. So, like anything else you optimize, it’s a fine line between success and failure.
Recommendations
As with many of the other ideas presented so far, I’d treat the “kill” switch as a psychological enhancer, rather than a monetary performance enhancer.
You might not make more profitable, but you will be on the sidelines during periods of crazy volatility. That might be enough reason to use it.
Summary
So far, I have looked at 4 unique ideas that can reduce the risk of an algo trading systems:
1. Daily Loss Limiter
2. Delay After Losing Trade
3. No Weekend Positions
4. High volatility “Kill” Switch
These 4 ideas can be used alone, or together, depending on your objectives. Don’t expect them to improve profit performance, but they may help improve your risk adjusted performance. Plus, they will help you psychologically, and that alone might make them worth doing.
As with any of the code shown in this article, the keys are:
A. Incorporate technique in the strategy, before testing
B. Make sure to properly test and build the strategy (the Strategy Factory process is ideal for this)
C. Optimize these as little as possible. Try to select parameter values you feel comfortable with, rather than optimizing.
Part 2 – Equity Curve Trading As A Risk Management Tool
A few years ago, I got an e-mail from a very excited CTA (Commodity Trading Advisor, a professional money manager and trader of futures). He had seen an article I had written, and was super pumped about equity curve trading.
For those of you not familiar with equity curve trading, you use a moving average (or other technical measure) of the trading system’s equity curve to turn it on or off (to trade or not trade). For example, you might use a 25 period moving average of the curve to turn the strategy on and off. Sometimes it works, sometimes it doesn’t.
Some examples of the good, bad and ugly are shown below.
A few years back, I wrote a few articles on this subject for Modern Trader Magazine (now out of business).
You can read Part 1 here, and Part 2 here. My conclusion is that equity curve trading generally did not work, and it can be easily manipulated into making you think it works.
Seriously, take some time and read those articles. They are worth the read. I’ll wait…
Now, back to the story. This CTA had a US bond strategy he was really excited about, and he claimed when he added Equity Curve Trading to the mix, his strategy GREATLY improved. So great in fact, that he thought he would “honor” me by letting me be the first to invest with his new strategy.
Lucky me! LOL…
Of course, I probably knew something was wrong (I’m always skeptical), so I asked him for his spreadsheet where he did the equity curve calculations. Here is what he gave me.
It is kind of hard to tell from the figure, but if you look at his calculations, he is deciding to take the trade AFTER the moving average has been calculated (which includes the trade he is deciding on). In other words, he can see into the future!
No wonder his equity curve trading approach looked so good!!!!
I corrected his mistake, and then the equity curve trading result was worse than the “always on” case.
I showed the CTA the correct result, he agreed his method was wrong, YET still claimed his approach was better profit wise. I guess you can’t fix stupid…
Anyhow, setting up equity curve trading incorrectly is just one pitfall.
A second pitfall is if you try enough different moving average lengths, or if you try enough different equity curve trading approaches, you’ll find one the works – one that really improves things. Just remember, by doing this you are optimizing!
As a result, I don’t recommend equity curve trading, but if you want to try, I would test it on a completed strategy, try one value for a moving average (don’t optimize) and then leave plenty of out of sample data to verify your result.
Just for kicks, I tried out a 10 bar moving average equity curve trading approach for 5 random strategies I currently trade (I stopped trading #5 a while back). To be fair, I only applied equity curve trading to the period after strategy development (true out of sample performance). Results are below…
2 strategies are clearly better NOT using equity curve trading ( “always on” is much better). 1 strategy is basically the same either way. And 2 strategies (#4 and #5) are better profit wise with “always on,” but drawdowns do decrease with equity curve trading.
In this limited sample, maybe equity curve trading is useful for reducing drawdowns, and might be a good idea if you can handle the reduced profit.
Your best bet is to try it yourself, and let me know what you think. I have created a spreadsheet for you to help with equity curve trading, and it is available in the Part 3 Resource Pack.
I have also summarized Parts 1 and 2 in this YouTube video:
Part 3 – Resource Package
In parts 1 and 2, I covered quite a bit to help your strategies with risk protection.
Part 1:
Daily Loss Limiter
Delay After Losing Trade
No Weekend Trading
Volatility Kill Switch
Part 2:
Equity Curve Trading
Now it is time for you to get to work!
Click the "Access here" link below - Tradestation users can easily download the workspaces I used, along with all the code I used for this study.
If you don’t use Tradestation, maybe you should consider it. It would make your life easier if you want to further my research, and students of my Strategy Factory workshop can actually get the workshop for free with a Tradestation Rebate program I have.
I’ve also included an equity curve trading spreadsheet. Feel free to modify, just make sure to double check your modifications – it is easy to make a mistake and “peak” at future data!
Part 4 – Bonus Material
In Part 1 of this article, I provided 4 effective ways to code risk protection into your strategies. These techniques resonated with a lot of folks, and the consensus is “we want more!” (By the way, if you like this article, please feel free to share it - a lot of you have already).
So, I decided to add in 4 more risk protection techniques. These are all variations of the original 4:
I discuss each one of these new techniques below, followed by Tradestation code and workspace.
Risk Protection #5 (also known as #1A) – Monthly Loss Limiter
Maybe the Daily Loss Limiter is just a little too restrictive for you. Instead, you’d like to turn off the strategy if a certain amount of loss occurs in a month.
This technique will “kill” any strategy for the rest of the month when the monthly loss limit is hit.
Plain English Rules
Every bar, first check if today is a new month. If it is, calculate the total open plus closed equity for the strategy at the last bar before midnight. If during the next month, the current total equity minus the “start of month” equity is less than “equitylosslimit” exit all current positions and do not take any new trades until the new month starts.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #1A - Monthly Loss Limiter
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),EquityLossLimit(3000);
var:EndMonthEquity(0),CanTrade(True),CurrentEquity(0);
CurrentEquity=NetProfit+OpenPositionProfit;
If month(date)<>Month(date[1]) then begin
EndmonthEquity=CurrentEquity[1];
end;
CanTrade=True;
If NetProfit+OpenPositionProfit-EndMonthEquity<-EquityLossLimit then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("DLL-L Exit") next bar at market;
BuyToCover ("DLL-S Exit") next bar at market;
end;
If you use daily bars, you can use a stoploss statement instead:
Sell next bar at close – xxx stop; //xxx is the price where monthly loss limit would be hit
Results
To see the impact this Monthly Loss limit had, I varied the loss limit from $100 to $5,000. For this particular strategy, monthly loss limit does not have a huge impact above $1500. Below that amount, having this limiter can be a real KILLER! Yes, you limit the monthly loss, but at the expense of no profit!
Consider that when someone says limiting monthly loss is a great idea. It might have the opposite effect!
Risk Protection #5 (also known as #1A) – Monthly Loss Limiter
Maybe the Daily Loss Limiter is just a little too restrictive for you. Instead, you’d like to turn off the strategy if a certain amount of loss occurs in a month.
This technique will “kill” any strategy for the rest of the month when the monthly loss limit is hit.
Plain English Rules
Every bar, first check if today is a new month. If it is, calculate the total open plus closed equity for the strategy at the last bar before midnight. If during the next month, the current total equity minus the “start of month” equity is less than “equitylosslimit” exit all current positions and do not take any new trades until the new month starts.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #1A - Monthly Loss Limiter
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),EquityLossLimit(3000);
var:EndMonthEquity(0),CanTrade(True),CurrentEquity(0);
CurrentEquity=NetProfit+OpenPositionProfit;
If month(date)<>Month(date[1]) then begin
EndmonthEquity=CurrentEquity[1];
end;
CanTrade=True;
If NetProfit+OpenPositionProfit-EndMonthEquity<-EquityLossLimit then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("DLL-L Exit") next bar at market;
BuyToCover ("DLL-S Exit") next bar at market;
end;
If you use daily bars, you can use a stoploss statement instead:
Sell next bar at close – xxx stop; //xxx is the price where monthly loss limit would be hit
Results
To see the impact this Monthly Loss limit had, I varied the loss limit from $100 to $5,000. For this particular strategy, monthly loss limit does not have a huge impact above $1500. Below that amount, having this limiter can be a real KILLER! Yes, you limit the monthly loss, but at the expense of no profit!
Consider that when someone says limiting monthly loss is a great idea. It might have the opposite effect!
Looking at the results, you might conclude that the Monthly Loss Limiter is good to have. But BEWARE! This is an optimized result. The $1700 limit is likely NOT to be the best monthly limit going forward.
Recommendation
If you want to use a Monthly Loss Limit, decide on the value to use BEFORE you run the backtest. Don’t necessarily expect a performance improvement, but instead use it because you like the psychological comfort of limiting your monthly loss. Any performance improvement should be considered a bonus.
Risk Protection #6 (also known as #2A) – Turn Off After X Consecutive Losers
You hate losing trades. I get it – so do I. So, this risk protection turns off a strategy after 4 consecutive losers. And after it hits those 4 losers, that strategy is off forever.
Obviously, there are a few variations that I will leave to you to implement. Maybe the number of consecutive losers is not 4, but rather 2 or 3 or 5 or 10. You should be able to program it. Also, you can have the strategy off for a certain number of bars since the last exit before turning it back on (hint: use barssinceexit keyword, I have it in Tradestation code, commented out)
Plain English Rules
After 4 consecutive losing trades, turn the strategy off – forever!
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #2A - Kill Strat After 4 Consecutive Losers
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2);
var:CanTrade(True);
CanTrade=True;
If (positionprofit(1)<0 and positionprofit(2)<0 and positionprofit(3)<0 and positionprofit(4)<0) then CanTrade=False;
//If BarsSinceExit(1)>20 then CANTRADE=True; //limit "off" time to 20 bars
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
Results
For this particular strategy, putting a kill switch in after 4 consecutive losses does not improve profit, but it did reduce drawdown.
Recommendation
This type of risk protection is really suited for strategies where there is a potential for many consecutive losses. A counter trend strategy would be a good example. As with any of these risk protection techniques, it is best to incorporate the rule in the strategy BEFORE you backtest. Adding the rule after you see initial results is basically cheating the backtest.
I would feel comfortable using this approach on a strategy that I knew was designed to trade counter to the major trend. It would help keep the strategy from entering loser after loser.
Risk Protection #7 (also known as #3A) – No New Overnight Trades
Earlier I looked at not having trades open on weekends. Well, maybe you are OK with weekend positions, and even overnight positions, but you just do not want to enter new trades in the less liquid overnight hours (you are OK with exiting trades overnight though).
The theory here is the overnight signals are less reliable, and prone to more slippage.
Plain English Rules
Don’t enter any new trades after 1600 and before 700 (chart time).
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #3A - No New Trades Overnight
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),Stoptime(1600),StartTime(700);
var:CanTrade(True);
CanTrade=True;
If time>=StopTime or time <=StartTime then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
end;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
Results
Yikes!
This type of risk protection is really suited for strategies where there is a potential for many consecutive losses. A counter trend strategy would be a good example. As with any of these risk protection techniques, it is best to incorporate the rule in the strategy BEFORE you backtest. Adding the rule after you see initial results is basically cheating the backtest.
I would feel comfortable using this approach on a strategy that I knew was designed to trade counter to the major trend. It would help keep the strategy from entering loser after loser.
Risk Protection #7 (also known as #3A) – No New Overnight Trades
Earlier I looked at not having trades open on weekends. Well, maybe you are OK with weekend positions, and even overnight positions, but you just do not want to enter new trades in the less liquid overnight hours (you are OK with exiting trades overnight though).
The theory here is the overnight signals are less reliable, and prone to more slippage.
Plain English Rules
Don’t enter any new trades after 1600 and before 700 (chart time).
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #3A - No New Trades Overnight
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),Stoptime(1600),StartTime(700);
var:CanTrade(True);
CanTrade=True;
If time>=StopTime or time <=StartTime then CanTrade=False;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
end;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
Results
Yikes!
The max drawdown is less, and the system is in the market a lot less (which by itself is a good thing), but you also have to give up almost 75% of profits. Clearly, for this strategy/market, the “no new trades overnight” trading idea is a financial loser.
Recommendation
This is a neat idea (who would not want stress reduced overnights?), but the benefit may be more psychological than financial. In fact, as we see with this strategy, it might be terrible financially.
But, as with all ideas, I recommend you test it, adding it to your strategy from the start. Don’t create a strategy and then try to tack this on, since you’ll only accept it if performance improves (which is cheating!).
Instead, if you like the idea, try it for a while. If you find yourself unable to create good strategies, then this overnight requirement might be the reason, and you might want to eliminate it.
Risk Protection #8 (also known as #4A) – Low Volatility Kill Switch
Volatility is a double edged sword. As traders, we need volatility to profit from price movement. So some volatility is a good thing. No volatility is a bad thing. But too much volatility is a bad thing, too. Low volatility can mess up our algos, and trade us in and out of trades in an endless whipsaw – or never take any trades at all.
As fate would have it, in my first book I included to Euro strategies. I had traded them live for a while, and they were pretty good. But then in late 2014, shortly after the book’s release, Euro volatility tanked:
This effectively “killed” those systems for a year or so – neither had been tested on such a low vol environment.
So, I created code that would temporarily turn off strategies with low volatility.
Plain English Rules
Close all open trades, and do not allow any new trades, if the true range of the just closed bar is less than ATRmult times the average true range over the last 5 bars.
Tradestation Code
//*********************************************************
//
//www.kjtradingsystems.com
//Risk Protection Study
//Kevin Davey - Risk Protection #4A - Low Volatility Kill Switch
//[email protected]
//
//*********************************************************
//
input: lookback(10),stopATR(2),ATRMult(1);
var:CanTrade(True);
//switch criteria
CANTRADE=TRUE;
If TrueRange<ATRMult*AvgTrueRange(5) then CANTRADE=FALSE;
If CanTrade=True then begin
If close crosses above close[lookback] and close crosses below close[.5*lookback] then buy next bar at market;
If close crosses below close[lookback] and close crosses above close[.5*lookback] then sellshort next bar at market;
var:NewStop(3000);
NewStop=StopATR*AvgTrueRange(14)*BigPointValue;
If NewStop>3000 then NewStop=3000;
If StopATR<>0 then SetStopLoss(NewStop);
end;
If CanTrade=False then begin
Sell ("Vol-L Exit") next bar at market;
BuyToCover ("Vol-S Exit") next bar at market;
end;
Results
I optimized for different ATR multipliers, and the best case is the baseline case (meaning no switch is best).
Recommendations
As with many of the other ideas presented so far, I’d treat the “kill” switch as a psychological enhancer, rather than a monetary performance enhancer. You might not make more profitable, but you will be on the sidelines during really slow times. That might be enough reason to use it.
Summary
In Part 4, I have looked at 4 unique ideas that can reduce the risk of an algo trading systems:
1A. Monthly Loss Limiter (variation of Daily Loss Limiter)
2A. Kill After 4 Consecutive Losses (variation of Delay After Losing Trade)
3A. No New Trades Overnight (variation of No Weekend Positions)
4A. Low Volatility Kill Switch (variation of High volatility “Kill” Switch)
These 4 ideas can be used alone, or together, depending on your objectives. Don’t expect them to improve profit performance, but they may help improve your risk adjusted performance. Plus, they will help you psychologically, and that alone might make them worth doing.
As with any of the code shown in this article, the keys are:
A. Incorporate technique in the strategy, before testing
B. Make sure to properly test and build the strategy (the Strategy Factory process is ideal for this)
C. Optimize these as little as possible. Try to select parameter values you feel comfortable with, rather than optimizing.
Good Luck, thanks for reading, and let me know how these work out for you!
As with many of the other ideas presented so far, I’d treat the “kill” switch as a psychological enhancer, rather than a monetary performance enhancer. You might not make more profitable, but you will be on the sidelines during really slow times. That might be enough reason to use it.
Summary
In Part 4, I have looked at 4 unique ideas that can reduce the risk of an algo trading systems:
1A. Monthly Loss Limiter (variation of Daily Loss Limiter)
2A. Kill After 4 Consecutive Losses (variation of Delay After Losing Trade)
3A. No New Trades Overnight (variation of No Weekend Positions)
4A. Low Volatility Kill Switch (variation of High volatility “Kill” Switch)
These 4 ideas can be used alone, or together, depending on your objectives. Don’t expect them to improve profit performance, but they may help improve your risk adjusted performance. Plus, they will help you psychologically, and that alone might make them worth doing.
As with any of the code shown in this article, the keys are:
A. Incorporate technique in the strategy, before testing
B. Make sure to properly test and build the strategy (the Strategy Factory process is ideal for this)
C. Optimize these as little as possible. Try to select parameter values you feel comfortable with, rather than optimizing.
Good Luck, thanks for reading, and let me know how these work out for you!
If you enjoyed this article, please share it!
About The Author: Kevin Davey is an award winning private futures, forex and commodities trader. He has been trading for nearly 30 years. Three consecutive years, Kevin achieved over 100% annual returns in a real time, real money, year long trading contest, finishing in first or second place each of those years.
Kevin is the author of 5 best selling trading books, including the highly acclaimed book "Building Algorithmic Trading Systems: A Trader's Journey From Data Mining to Monte Carlo Simulation to Live Trading" (Wiley 2014).
Copyright, Kevin Davey and KJ Trading Systems. All Rights Reserved. Reprint of above article is permitted, as long as the About The Author information is included.
Kevin is the author of 5 best selling trading books, including the highly acclaimed book "Building Algorithmic Trading Systems: A Trader's Journey From Data Mining to Monte Carlo Simulation to Live Trading" (Wiley 2014).
Copyright, Kevin Davey and KJ Trading Systems. All Rights Reserved. Reprint of above article is permitted, as long as the About The Author information is included.