Algorithmic Trading Tip – Building Risk Protection Into Your Trading

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.

There is another level to strategy building, one that many traders neglect – 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 get started!


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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
 
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:

Performance Metric

Baseline Result

Net Profit

$40,030

Number of Trades

92

Return on Account

280.7%

Percent Time in Market

34.1%

Max Drawdown(Closed Trade)

-$14,260

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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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:

Performance Metric

Baseline Result

Daily Loss Limit (optimum value = $2500)

Net Profit

$40,030

$47,675

Number of Trades

92

95

Return on Account

280.7%

344.7%

Percent Time in Market

34.1%

32.0%

Max Drawdown(Closed Trade)

-$14,260

-$13,830

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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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).

Performance Metric

Baseline Result

Exit Delay(optimum value 10 bars)

Net Profit

$40,030

$39,445

Number of Trades

92

89

Return on Account

280.7%

256%

Percent Time in Market

34.1%

32.0%

Max Drawdown(Closed Trade)

-$14,260

-$15,400

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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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:

Performance Metric

Baseline Result

No Weekends (Exit at 4PM Friday)

Net Profit

$40,030

$10,585

Number of Trades

92

107

Return on Account

280.7%

82.1%

Percent Time in Market

34.1%

8.2%

Max Drawdown(Closed Trade)

-$14,260

-$12,860

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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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.

Performance Metric

Baseline Result

Kill Switch(optimized ATRMult=3)

Net Profit

$40,030

$44,125

Number of Trades

92

99

Return on Account

280.7%

319.1%

Percent Time in Market

34.1%

29.1%

Max Drawdown(Closed Trade)

-$14,260

-$13,830

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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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
//kdavey@kjtradingsystems.com
//
//*********************************************************
//
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!

-- By Kevin Davey from blog KJ Trading Systems

About the Author Kevin Davey

Kevin Davey is a professional trader and a top performing systems developer. Kevin is the author of “Building Algorithmic Trading Systems: A Trader's Journey From Data Mining to Monte Carlo Simulation to Live Trading” (Wiley Trading, 2014.) . He generated triple digit annual returns 148 percent, 107 percent, and 112 percent in three consecutive World Cup of Futures Trading Championships® using algorithmic trading systems. His web site, www.kjtradingsystems.com, provides trading mentoring, trading signals, and free trading videos and articles. He writes extensively in industry publications such as Futures Magazine and Active Trader and was featured as a “Market Master” in the book The Universal Principles of Successful Trading by Brent Penfold (Wiley, 2010). Active in social media, Kevin has over 15,000 Twitter followers. An aerospace engineer and MBA by background, he has been an independent trader for over 20 years. Kevin continues to trade full time and develop algorithmic trading strategies.

>