Some traders believe that a stop loss is always necessary in any systematic trading strategy, primarily as a risk management measure. Other traders believe that a stop loss can do more harm than good, and a well diversified trading portfolio should not need stop losses. Both sides are right and wrong at the same time, but this is a more complicated conversation that goes beyond the scope of this post. Zorro Trader offers a multitude of stop loss options.
For the novice algorithmic trader, we believe a stop loss is necessary, especially when one uses lagging indicators with long formation periods. Moving averages are a good example. A bad trade would end eventually based on your own crossover exit signal, but a stop loss should get you out of the loosing position sooner. Adding a stop loss in Zorro Trader is extremely easy:
function run() { BarPeriod = 1440; Stop = 0.03*priceClose(); vars price = series(priceClose()); vars price_smooth = series(SMA(price, 25)); vars sma = series(SMA(price, 50)); if(crossOver(price_smooth, sma)) enterLong(); if(crossUnder(price_smooth, sma)) enterShort(); plot("Price Smooth", price_smooth, LINE, ORANGE); plot("SMA", sma, LINE, BLUE); }
One line of code does it all! We initialize the internal Stop
variable of Zorro Trader with a value calculated from the closing price. As an internal variable, it does not require a type. We are willing to take the risk of the market moving against us by a maximum of 3%. Once that happens, the trade is exited at the next bar. There will be slippage, but we should loose only around 3% on every bad trade (and not much more). Unless, of course, a major event or crisis happens, and the market crashes. As millions of stops get triggered the slippage becomes huge etc.
Performance of the Zorro Trader strategy with a simple stop loss
Test WithStopLoss MSFT, Zorro 2.444 Simulated account AssetsFix Bar period 24 hours (avg 2087 min) Total processed 1953 bars Test period 2017-04-28..2022-05-06 (1265 bars) Lookback period 80 bars (23 weeks) Montecarlo cycles 200 Simulation mode Realistic (slippage 5.0 sec) Avg bar 324.8 pips range Spread 10.0 pips (roll 0.00/0.00) Commission 0.02 Contracts per lot 1.0 Gross win/loss 170$-82.59$, +8698.5p, lr 110$ Average profit 17.32$/year, 1.44$/month, 0.0666$/day Max drawdown -23.32$ 26.8% (MAE -39.56$ 45.5%) Total down time 39% (TAE 51%) Max down time 44 weeks from Sep 2019 Max open margin 330$ Max open risk 10.03$ Trade volume 3878$ (772$/year) Transaction costs -1.90$ spr, -1.57$ slp, 0$ rol, -0.38$ com Capital required 348$ Number of trades 19 (4/year) Percent winning 36.8% Max win/loss 36.67$ / -9.89$ Avg trade profit 4.58$ 457.8p (+2422.6p / -688.3p) Avg trade slippage -0.0826$ -8.3p (+18.6p / -23.9p) Avg trade bars 38 (+90 / -8) Max trade bars 140 (40 weeks) Time in market 57% Max open trades 1 Max loss streak 3 (uncorrelated 7) Annual return 5% Profit factor 2.05 (PRR 0.99) Sharpe ratio 0.43 (Sortino 0.42) Kelly criterion 3.76 Annualized StdDev 11.50% R2 coefficient 0.866 Ulcer index 12.5% Scholz tax 23 EUR Year Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Total 2017 1 1 -0 2 2 1 -4 0 0 +3 2019 0 2 2 4 -2 3 1 1 -1 -1 0 0 +7 2020 0 0 -1 1 1 6 0 6 -4 -3 3 2 +12 2021 3 0 -1 -2 -1 -1 4 5 -6 1 -0 -3 -1 2022 2 3 -3 4 -2 +4 Confidence level AR DDMax Capital 10% 5% 12 340$ 20% 5% 14 341$ 30% 5% 16 342$ 40% 5% 18 344$ 50% 5% 20 346$ 60% 5% 22 347$ 70% 5% 26 350$ 80% 5% 29 353$ 90% 5% 36 358$ 95% 5% 43 363$ 100% 5% 56 374$ Portfolio analysis OptF ProF Win/Loss Wgt% MSFT .999 2.05 7/12 100.0 MSFT:L .999 4.52 5/4 122.6 MSFT:S .000 0.62 2/8 -22.6
Conclusion
This is a very nice result and we are clearly improving our systematic trading strategy. Our Annual Return went up to 5% with the stop loss, from 3% without the stop loss. The Sharpe Ratio is also much better, as it more than doubled from 0.2 to 0.43. It is still fairly low, but it appears the stop loss dramatically decreased the risk of our strategy.
We observe that at least in this situation, this simple stop loss does what it’s supposed to do, and does it rather well. Zorro Trader has much more sophisticated stop loss methodologies, like dynamic stops, trailing stops, trade management functions, and many other advanced tools. You can learn more on these topics from the video courses in the members area.
by Algo Mike
Experienced algorithmic and quantitative trading professional.