0-day and 40-day smoothing, or even vary the frequency of datausing 30-minute, I-hour, and daily bars. In most cases, you can write your own formulas tocreate customized indicators. If you experiment with these software features, you mightfind that they provide the ability to create a trading strategy that matches the time frameand risk profile that you want. For example, a long-term trend can be found with a stan-dard moving average, weighted average, exponential smoothing, N-day breakout, or linearregression. All of these techniques are already available. You may want to combine thatwith a band to avoid whipsaws. That is also easily done. [f you want to alter your timing sothat you enter on a pullback after a trend signal, then you can add a stochastic or RSI toyour rules. Before you begin specialized programming, there is a lot to be learned by usingthese standard tools. It is not at all clear that you can create a trend that is any better thanthe ones provided in your system. It may be that the choice of trend period is much moreimportant than the trend technique.
Choosing Hardware
In an era of remarkable advances in technology, the hardware costs no longer seem an obsta-cle. As each new, faster chip is introduced, the previous model computers are reduced inprice. This process seems to be happening at least once each year, The cost of a computerwith a maximum configuration is small compared with your objectives, and not much greaterthan one trading loss. Because hardware has a shorter shelf life than only a few years ago,buying the biggest and best equipment is the only way to extend the life of your purchase.
‘The process of testing your strategies by optimization is a computationally intensivemethod for the computer. You’ll want to have the fastest processor. In addition, testingmay still take one or more uninterrupted hours of data crunching; therefore, you'll wantto have a large RAM to allow that process to go on in the background while you use thecomputer to do some other tasks. Institutional users will find it more practical to have oneor more machines dedicated to testing. This will allow the calculations to continue at a pre-dictable pace, rather than being interrupted by demands from other programs.
Programming the System
Computer programming talent is no longer rare, but in high demand. In addition, under- °
standing a trading strategy is a special talent that requires training. Fortunately, the mostarcane parts of system development are already part of any trading development softwareyou buy; therefore, it is only necessary to code the actual strategy, rather than how toretrieve and store prices from the exchange data feed.
The prevailing philosophy about software development is to try to use as much third-party software as possible. If you need to see the results of a TradeStation optimization,save the results to a spreadsheet, then sort, organize, analyze, and graph the results usingyour favorite spreadsheet. You can compare one set of tests with another if you save themall in the same format. For the more popular platforms, such as TradeStation and Meta-Stock, there are a number of user’s groups, support groups, and newsletters that can be ofgreat help. Some companies provide alternate statistiGal measurements for your tests,while others have an add-in portfolio program. It is a good idea to check to see if these ser-vices satisfy your needs before attacking the programming yourself.
Selecting a Programmer ;If you are not going to program the computer yourself, try to find someone with experiencein a language similar to the one you'll be using. It would be helpful if the programmer hadsome knowledge of trading, which might avoid errors caused by misunderstanding con-
bl AA etn a
USE AND ABUSE ©, « HE COMPUTER 559
 
cepts, but that is not likely to happen. Given a choice, a scientific background is better thanbusiness programming experience.
Getting a programmer to say how much it will cost or how long it will take to solve aproblem is going to be difficult—they just don’t know. Programmers are incurable opti-mists, always thinking that the problem will be done at any moment. Even competent man-agers of programmers have difficulty in scheduling a project, based on the uncertainty ofthe debugging, or checking-out process. If it is necessary to contract the work or hire a pro-grammer, try to get a fixed-price quote and avoid the problems that will occur later.
Define the Steps
To keep the work on schedule, you will need to know what you want to do in advance. Youcan take a chart and mark the places where you believe the system will buy and sell. It isimportant that you have ‘an actual example of what is expected so that you can verify theprogrammed results against the example.
‘Write down all the rules in outline form. You must be able to be precise about everyrule. The computer cannot deal with ambiguities. It is very likely that a programmer canwork directly from your rules to create the final strategy. This is also an opportunity to besure that your rules are clear and complete. Using your rules, select a price series and markthe trading signals that will be used to verify the program output. Check the results care-fully. If one trade doesn’t match your expectations, don’t stop until you find the reason.
Looking into the Past
We have already thoroughly discussed the advantages of using as much data as possible—the results reflect a broader variety of market conditions and are, therefore, more repre-sentative. There is often a concern that older data does not represent current conditions.While there may be some truth in that, there is usually more to be gained with a system thatcan survive those years and still perform well in current markets. Unless there has been astructural change that makes the old data invalid, you should always favor longer tests andmore data. Even if you are convinced that the older years represent a period of low volatil-ity that will never be seen again, your system should, at the very least, not post losses forthat period. -
Paper Trading
With all good intentions, when you develop a new strategy you plan to hold the mostrecent data aside for out-of-sample testing. Somehow, before you're done, that data hasbeen used a number of times. Therefore, as careful as you have tried to be, it is possiblethat you have overfitted the dara by fine tuning the rules and parameters.
The only alternative is some period of paper trading. By monitoring the program daily,you can see how ir is performing under real market conditions. Before doing that, how-ever, you should write down the system expectations, for example, the size and frequencyof the profits and losses. It is always a relief when the system posts its first profit, but it isthe overall profile that is most important. When paper trading, assume that your fill is theworst price of the 5-minute period immediately following an intraday signal, or the high-est price of the closing range if your trades come at the end of the day. A touch of realitycan start you thinking and save a lot of money. Don't start trading a new system withoutmonitoring its performance first.
Dealing with the Unexpected
By the time a computer and database have been acquired and installed, you have pro-grammed or had a programmer implement your ideas, debugged and tested the programs, 
 
 
 
 
560 PRACTICAL CONSIDERATIONSand finally analyzed the results, there has been a substantial investment made. Hard workhas resulted in proving one of four things:
1. The system is profitable
2. The system is not profitable.
3. The system cannot be implemented effectively.
4, The whole process is too expensive.
If you've gotten to the end and your result is not satisfactory, you might want to reex-amine the process that you used. Trading strategies should be built slowly; each piece mustbe proved to be sound before you go on to the next step. You should never have gotten tothe end without knowing that the final product was going to be profitable. If the perfor-mance was deteriorating as you added new rules and features, you should have stoppedand reconsidered these features and modified each step to be more robust.
You may also find that your rules were too subjective, that you substituted a rule thatwas not well thought out, because you were not able to clearly define one part of yourstrategy. Knowing that you have been subjective about a trading decision is a valuable dis-covery. Many speculators believe that they are very clinical about their trading policies; theyknow exactly what will be done in every circumstance and, therefore, think that theirapproach can be well defined in writing. But computerization cannot be done successfullyif there are any “maybes,” “wait and see,” or any other exceptions.
One common problem is that the system does not work using either the rules or thevariables imposed by the program. If moving average periods ranging from 20 through 50were first used unsuccessfully, it is likely that you would test intervals of less than 20. If
~ stop-loss points were too big or too small Gudging by the size of frequency of the losses),you'll try other sizes. Systems do not always work as expected and perhaps only a slightchange to the mules is necessary. Negative results are important feedback. They can helpcreate a better strategy before it is too late. After all, if the answers were known in advance,this would all be unnecessary. If the results are good, but different from what wasexpected, you should take the time to understand why. Don’t accept the results withoutcareful review. This is an opportunity to either increase your understanding of how themarket works, or find that you have been making a mistake all along.
‘A common result is that the system works in some markets but not in others. This canbe the product of using fixed values rather than a rule. For example, a stop-loss of 4 tickswould make sense for Eurodollars trading at 4% yield, but not the S&P at 1100. Try tolocate the problem and make the rules more adaptable to changing conditions. Once thisis done, if the problem persists, you must face the issue of robustness.
Expectations
In some work, defining your expectations can bias the process and give poor results. Forthe development of a trading system, you must first have a sound idea before you start.Along with this idea is whether it works best in the short or long term, the frequency ofprofitable trades, and even the size of the expécted profits and losses. By defining yourexpectations you can apply special rules and techniques that seem consistent with the phi-losophy of the method. These expectations of the profit profile are particularly importantto keep you focused throughout the development and testing of the strategy. If you expectto trade one each day and capture about 50% of the trading range, then signals that occuronly once each week should immediately cause you to look for an error. If profits are toosmall or losses too big, then you can carefully study how the rules apply to a series of pricesand understand whether you have omitted some rules, applied the rules incorrectly, orhave made a mistake in your thinking. Without setting down clear expectations in advance,you have no benchmark to help you through the development process.
 
it
 
 
USE AND ABUSE OF 1 HE COMPUTER581
A Winner in Disguise
One important twist on performance should not be overlooked: A consistently bad per-former can become a consistent winner by doing just the opposite. Finding a profitablerend system in the range of shorter time intervals may seem to be a hopeless effort. Onthe other hand, systematic losses mean that the price movement fails to trend, and everyay signal and sell signal is actually an overbought and oversold condition, predictive ofBrice change. This can happen in markets that are heavily traded using systems; whatat first to be a trend change i i i '
appear ge is a temporary distortion due to massive buy and sellConsistent losses do not always mean that the reverse trade will work. The net lossesmay be less than the total transaction costs; therefore, the opposite action will show even
rger losses. The successful reverse system is one ich the net losses far exceed thelai The fi -m is one in which the net l fa d theSt
Simple or Complex?
It is not necessary to create or acquire a system that is exceptionally complex to be suc-cessful. Simple systems, such as a dual moving average crossover, can be profitable as wellThe difference between the performance of a simple system and a well-developed, com.plex metho#! is the risk/reward ratio and the magnitude of the equity swings. Pee ComSimple systems will catch the trends and take as much profit from the big moves as themore sophisticated approaches. It is the other patterns that make distinctions. Added fea.tures should reduce the losses and modify the trading patterns during nontrending peri-ods. This may be accomplished by identifying a trading range, using positions of varyinysize, oF by the inclusion of economic data. Sometimes, more complex systems are justimore complex _pithout improving results. In that case, use the simple system, but retain
Just Because It Doesn’t Work in Practice Doesn’t Mean It Won’t Work in TheoryYou thought that you followed all the rules by
1, Precisely defining the system -2. Using enough test data
3. Evaluating performance by forward extrapolation
4, Investing enough to survive the worst losing streak
5. Trading a diversified portfolio
6. Following every signal
And still you lost all your money. . .. What happened?
Most likely you skipped some part of the well-planned development process. Carefulreassessment will usually show that some corners were cut. For example, new tradersoften only test their ideas in general by spot checking a few selected markets during years
at seem to have interesting or typical movement. They assume that these shortcuts donot affect the results of the system. The advantage of computerized testing is that af years
sted easily—the procedure necessary to produce a r i
can be tested = ry to pI ‘obust system that works inww There is always the temptation to force a system to work if it failed because of one or
Oo arge losses. An analyst can find something unique about these losing trades and cre-ate a rule that eliminates just those items. Some traders may just assume that ciccum-stances would have caused them to pass the trade rather than buy or sell in an obviously
verse market. This type of tampering doesn’t work and the reason for many of theseproblems is explained in the next section on price shocks. 
 
 
$62 PRACTICAL CONSIDERATIONSSuppose you are not guilty of any of these infractions, that the system was developedwithout making exceptions, and all the rules were followed. Then, the most commonproblem is to misjudge the volatility of the market or some systematic change that hasPccurred. You might see that the program was more profitable in the earlier years, and thatthe average profit has been declining and the average loss rising. This might be due toincreased participation and more market noise. As this occurs, it is necessary to increasethe period of calculation to compensate for the noise. For example, in the early 1980s, theenergy markets were very smooth, and a 3-day moving average generated good profits. Asvolume increased, the market appeared more erratic, and a 10- to 20-day moving averagewould have been needed. In the early 1990s, the trend speed would have increase to 30 to40 days, all due to changing market noise. When there is higher noise, it takes longer toidentify the trend. Even when you sit still, the market will continue to change.
Start Slowly
‘After paper trading, to begin trading with an exceptionally small portfolio, one that can befost 10 times over, will not hurt at the beginning, There must be 2 chance to see if the sys-tem performs the way it appeared in testing. This will be the first opportunity to find outthe cost of execution. The slippage may be the factor that separates profits from losses. Youmay find that, during quiet periods, when the market is moving sideways, there is smallslippage but no profits; during fast market, when you expect the largest profits, the slip-page also increases. ‘The size and frequency of the losses should be checked as well as theequity cycle. When everything passes inspection, the investment can be increased slowly.Patience and thoroughness are important ingredients for success.
Once the system has been checked out, it is even safer to turn. the day-to-day execu-tions over to someone else. It may be the only certain way to follow the rules precisely. Tryto stay detached and objective, put monitor the results carefully to be sure there are no sur-prises. Even a large profit may be an early warning ‘ofa problem. Large losses often follow
large profits.
PRICE SHOCKS
Price shocks represent the most significant obstacle in the effort to close the gap betweentest results and actual trading, or expectations and reality. A price shock is, by circum-stance, an unexpected event. Exceptionally volatile price moves are caused by actual newsthat differs from expectations, such as the Fed raising rates by 1% when only 4% was antic-ipated; or, it may be a significant, unexpected political event, such as the abduction of Gor-bachev in 1991. The key word to remember is “unexpected.”
If an event was expected, then there would be no price change. The market wouldhave already moved to the anticipated level. Therefore, we cannot expect fo profit from aprice shock by clever planning, but only by chance. “We should never assume that we wouldbe on the right side of a large, unexpected move in more than 50% of those events. Unfor-tunately, when we back-test a trading system using historic data, we tend not to identifyspecific price shocks and treat them as normal, predictable events. We choose systems thatperform best over a set of parameters, without regard.to specific trades that may have beenthe result of shocks. We judge results by higher profits, lower risk, or a combination of sta-tistical values. The results chosen as the best performance often have been the greatestbeneficiary of these unpredictable price shocks.
Making Money with Hindsight
We should already be aware of the problems of back-testing, While there are no otheralter-valves for validating a proposed trading strategy, it is necessary to look at the problems
{
 
 
PRICE SHOCKS ~563
more carefully 0 see a solution. No market is more evident chan crude oil during the Gulf; in the previous chapter (see Figures 22-1, 22-21990, through the end of the War in F i prices were driven by news Bat no, ebruary 1991, oil prices were driven b tall news is a surprise. In the a; s erop Sroange jeice or cofee ve. gricultural markets, a crop freeze i juiall mews i a surprise, tn the a , a crop freeze in orange juice or coffee isge in weather. Before a freeze canGen ansciparce by a occur, the temperature mustperature must be sustained to cause damage. Thi hicauses processors to protect th i oe sor funares Inncauses processors (0 p emselves by buying forward contracts or futures. In turn,vot Because {rag had been moving troops near the Kuwait border, their intentions were; ; however, diplomacy failed. The threat of an oil suj i. a pply disruption caprices to slowly rise. Many systematic traders and commercials would have been long onugust 7, 1990, when Iraq invaded Kuwait. meen
Identifying Price Shocks
- vt predict orinee. eee pce shocks, and they seriously impact our historic tests, then we mustso that we can correct for their effects. In the end, thiswe need to look at the individual trades, ‘guiness let of pice shocks of| , compare them against a list of priwhich we are aware, and decide which se ee inanoraan, of the profits were realistic. E iwe must decide which risk was understat safe way of changing thised. There may not be a safe war iy of changing thi
final process. It may always be necessary to manually review the results for credibility
Some analysts may find it i iSome analysts m ay fin comforting to think that the computer may not be able to do
 
FIGURE 22-1 A far-reaching price shock. A vivid reminder of price shocks occurred on
August 16, 1991, and a;5 > gain 3 days later when Russian premier Gorb: 51 achev was abd:then released, Most financial markets were affected simultaneously, as were the snersy andmarkets, In the case of the currency markets, many traders profited from the first shock,red on a Sunday, then gave it all back on the following Wednesday. ,
i DM U75Daily2G CH61.350 000 O=61.420 H=b1 S10 L=61.190
Gorbachev is abducted
‘on Sunday, August 16.Market plunges on open
‘of August 19, then recovers‘on Wednesday, August 21,when crisis ends.
(hi,ni
Prices gapioweronMonday —> |
i fieN
‘Crisis ends onWednesday
 
SepSource: Chart created with TradeStation® by Omega Research, Inc. 
 
 
euiiiaie rasa citpdhen air
 
 
564 PRACTICAL CONSIDERATIONS
FIGURE 22-2, Amore common shock.The election of conservatives in Britain in January1992 was a surprise, but the effect was relatively local. '
are(02/2882 C=160,500 -.640, O=160.920 He161.200 L=160.160,
A ‘we i i ie
January 9, 1992 ”
Yd
Ayal ein pe\ |
|\an
4Ihe \ a ul
Lt
Aareea Prices greats an uptrend .wey in anticipation of election
vesute
ov Dec 2
 
Source: Chart created with TradeStation® by Omega Research, Inc.
‘The process of identifying price shocks can be speeded up with a small amount ofautomation. A price shock will be defined as a day with a true range greater than the aver-age true range by a multiplier, called the shock factor. This would be coded as
shock = 0; ,
truerange = high - low;
if high - closefl}> truerange then truerange = high - closeL1];if close[1] - low > truérange then truerange = close{1] - low;volatility = @average(truerange(1],vperiod);
if truerange > volatility*shockfactor then shock = truerange;Having coded the identification of a price shock, we can write a record to a file or print logto create a list of all price shocks, the date they occurred, and the size of the initial shock.It might also be useful to count the number of periods until prices return to a relativelynormal level. It may be unrealistic to assume that the volatility resulting from a price shockwill completely disappear; therefore, the point at which some degree of normal mightbegin could be when volatility declines to one-half the level of the initial price shock. This
would be found using the code
if truerange < shock/2 then shock = 0;.g both the beginning and end of a price shock, we canstudy the effects of price shotks on testing performance. A simple test was performed.inwhich an optimized trend system was inspected for periods of price shocks, where a shockwas defined as a price move of three times normal volatility. The profits and losses fromthese periods was removed from the net performance over a 10-year period, with theresults shown ir Table 22-1. The reduction in. profits was more than 50% when priceShocks were eliminated. This means that the selection of parameters heavily favored profits that were generated by large, probably unpredictable, price jumps.
With this simple method of identifyin
 
 
ene dent MLM nehn l ee
GAMBLING TECHNIQUE—THE THEORY OF RUNS 565
FIGURE 22-3 The invasion of Kuwait by I iIraq. News of massing armies and troop movement:near the Kuwait border helped the market anticipate the August 7, 1990, price jump ino,sinning, tr is bs iar the b eginning, many raders were on the right side of the market, although the move was
             
ee i2092 C=44.290 +030 On44 320 He44.410 Gist
38.000i U.S. retaliationwas stroriger than [96.000
expected
 
i ae aye”
fal cases.ie I ye
   
“<— !1aq's invasion ofKuwait came whilePrices were in an uptrend
    
!ee
 
Source: Chart created with TradeStation® by Omega Research, Inc.
How can we use these results if we cannot see the price shock until after it's happened?The only way is to correct the optimization process so that the parameter selectins i noton which calculation period is best tuned to get the most profit from these events. If
you remove the profits or losses during the initial price shock from the historic test resultsa shown in Table 22-1, the optimization would then show the best performers, net of priceshocks. Because price shocks are unpredictable, selecting from a shock-adjusted resultOuld yield a better trading system. Some traders might also prefer to use the identificationofa price shock period to change the current trading strategy to one of crisis management.
GAMBLING TECHNIQUE—THE THEORY OF RUNS
The application of Gambling Theory to high-leveraged or short-term trading satisfies twoportant conditions. First, it presumes no statistical advantage in the occurrence of profits
 
TABLE 22-1 Results of Removing Price Shocks from10-Year Historic Performance
Trend Adjusted for PercentStem Shocks ChangeCrude oit 17.12 7.88 =US.Treasury bonds 9.85. 421 SeDeutschemark 14.92 5.97 60%British pound 20.56 10.85 — 4T%SAP 560 3.50 425 va
  
 
566 PRACTICAL CONSIDERATIONS56
and losses but concerns itSelf with the probable patterns. Each trade could be treated as anccurrence of red or black—up or down price moves or profits. Second, Gambling Theory
Scresses money management under adverse conditions. A successful professional gambler
i both be highly disciplined and conserve capital. This section willand an active trader must bo ghly conserve capital This secur »
ler’s approach to money management an 7toowe ee seeumptionis made that each trade is unrelated to the previous trade or thateach successive price has an equal chance of going up or down, the situation closelyresembles roulette. In Monte Carlo, the roulette whee! has 37 compartments: 18 black, 1red, and 1 white, assuring a loss of 2.7% in the same way that transaction costs are a hand-icap to trading. Continuously betting on only red or black will break even, less 2.7%, overlong betting periods. The only way to change the odds is by money management vary-ing the size of the bets. Although the variables in trading are more complex, we will loo“ ore post well-known method for winning in a gambling siruation is based on theprobability of successive wins, the Theory of Runs, On each spin of the wheel, the likeliPood of the same color (red or black) reaccurring is 50%, or 4 (ignoring the white slot). Todefine a run of 3 reds, it is necessary to show a black on each side, thar is,
Black-Red-Red-Red-Black
otherwise, the run may not be complete. If each color had a 50% ch:probability of a run of 3 is
ii Ldn ta (3) -Baa 22 \2
ance of occurring, the
One run of 3 can be expected for every 32 spins of the wheel (called coups). Extending that
to runs of n consecutive reds gives (4) p 1 p ° athe approximate number of trading days in a year (if you consider daily closing pricesrather than intraday trades), there are the following possibilities for runs of red:
 
Run of ProBobilty Expected Number Total -Length of Occurrence of Occurrences Appearances of Red .A 32 32, Ns 16 323 hn 8 244 ha 4 165 hou 2 106 ‘he Il 6
Total appearances: 120
ected to occur. Notice, however, that the total appear-‘These 8 appearances could increase any of the runsJihood of a run greater than 6 is cal-ities greater than 6, oF
Arun of greater than 6 is not expances of red is only 120, short by 8. afrom 1 through 6, or become a run of 7 or 8. The like!culated using a geometric progression to get the sum of all probabi(A"*?, where 256 2127:
 
P= (Yt (AM eo + CN -(a
=(A) 256
 
+2, For 256 coups, which is both a power of two and
{i
 
 
 
GAMBLING TECHNIQUE—THE THEORY OF RUNS, 567
 
There is a single chance that there will be a run greater than 6 in 256 tries. The aver-age length of a run greater than 6 turns out to be 8, based on the decreasing probability ofoccurrences of longer runs. The average length of all runs greater than ” will be n + 2. Thatmakes the table of runs complete, with the number of occurrences of red equal to 128.
Martingales and Anti-Martingales
The classic application of the Theory of Runs is called Martingales. In the simple versionof this approach, an initial bet is doubled each time a loss occurs; whenever there is a win,the betting begins again at the initial size. To demonstrate how this works, it is necessaryto use a table of uniform random numbers (which can be found in Appendix 1). Thesenumbers vary from 0 through 9. Let all those numbers beginning with digits 0 through 4be assigned to red and 5 through 9 to black. Figure 22-4, read left to right, where opensquares are red and solid squares are black, shows the first 257 assignments according toAppendix 1. Assuming that we bet on black, lasses will depend on the longest run of red.We must decide the size of the initial bet in advance, which should be as large as possibleand still withstand the longest run of red that is likely to occur. By using the results fromthe analysis of the length of runs, we find that for every 256 coups, it is likely that only onerun greater than 6 will occur, and that run would most probably be 8 in length. The prob-ability of a run of 9 is (4)", or 1 in 1,024. In 256 coups, the odds are about 3 to 1 against arun of 9 occurring.
Having decided that capitalization must withstand a run of 8, we calculate that a bet of$1 doubled 8 times is $128. Divide the maximum amount of money to be risked by 128 andthe result is the size of the initial bet. Each $1,000 divided by 128 gives 7.8125, which mustbe rounded down to $7; therefore, on the eighth consecutive occurrence of red, the betwill be $897. Counting the occurrences of runs on the simulated roulette table (Table22-2), it is interesting to see that a run of 8, but not 7, appears
The results are within expectations, and no runs greater than 8 occurred in either redor black. For the purposes of this example, the betting would then proceed as shown inFigure 22-5, using an initial bet of $1. The numbers in the squares represent winning bets.
 
 
FIGURE 22-4 Sequence of random numbers representing occurrences of red and black.
 
COUPS GENERATED FROM RANDOM NUMBERS
        
   
  
    
 
 
6789 31915com weoso coosOoms omooo goooa o@ocag woocoms smoao eooeeo Oesae aaammo ooo omo |oom woo aano00 Om” osoDoo oso omooo com aOso wmomg BBOSem Come caon Capos Qoaga5 Bowoo ousoa oeoeo eeozom ooOmBeo omo
- Doo cooos ocaaq oe
  
 
PRACTICAL CONSIDERATIONS568
————