340INDEXAmiBroker Function Language (AFL) (Continued)Editor, 114auto-completion tool, 124ffunction helper, 124flaunching, 122fwindow, example, 123fEdit Rule pane, parameters (change), 136ferror warning, 125fexpressions, 116–117results, 117–118features, 113–114initiation, 113–118integrated development environment (IDE), 114knowledge, programmer requirements, 115–118operators, 116–117precedence, 117–118parameters, setting, 126fportfolio results, 128power (feature), 114price (feature), 113request (sending), exclamation point(clicking), 137fSend to Analysis window icon, 126fSet Futures mode, 127fsimple moving average crossover, 120speed (feature), 114syntax, 129–1333-D optimization chart, 130ftrade-by-trade report, 128fusage, 227–230variable naming, 116variables, 115–116names, restrictions, 115Wizard, 133–139(AmiBroker keyword)flow control structures, 294–295Analysis phase, 125Analysis window, 129, 131Annual return, performance metric, 91APO. See Absolute price oscillatorAppels, Gerald, 53, 56bApplyStop function, 132Arguments, usage, 161fArithmetic expressions, 116ASCIIdatabase (futures prices), 121data importer, 114ATR. See AveragetruerangeAuto-generated formula, 135, 137Average (VBA function), 160–161Average Directional Index (ADX), 29Average Directional Movement Index (ADX),26–3214-day ADX, calculation, 28–29length, 28trend detector function, 29fAverages, 24Average true range (ATR), 11b, 272ATR Sell MOC, 35b, 46b, 49b, 52b, 56bBuyToCover MOC, 40b, 46b, 49b, 52b, 56b5X ATR profit objective, usage, 165–166lookback, parameter (change), 282multiplier, parameter (change), 2813X ATR stop, usage, 164, 165–1662ATR,usage,69usage, 70–71Averaging methods, performances, 59, 62avgLen, default value, 124avgMP, 119AvgTrueRange, 208BBacktestequity curve, profit (display), 283fparameters, setting, 126fperformance report, 279fBacktest button, 129Backtester settings, example, 262fBacktestingExcel, usage, 145software structure, 149–154flowchart, 150fBandy, Howard, 114Bars held, performance metric, 91BASIC. See Beginner’s All-purpose SymbolicInstruction CodeBBandBot, 124BBandTop, 124Beginner’s All-purpose Symbolic Instruction Code(BASIC), 145, 154Berkely, George, 243Berlinski, David, 1bin increment (binInc) variable, 267binTuple, 267Bollinger algorithmbenchmark, 73optimization, 104tBollinger Bands, 62–68algorithmbest parameter sets, 74tversion 1 (performance), 65tversion 2 (performance), 68tbreakout, 93twww.rasabourse.com
calculation2 standard deviations, usage, 6360 days standard deviation, usage, 63data, Keltner Channel data (comparison), 71fexample, 90bfunction, 196Function Module, 319optimization, 72froutine, defining, 148f60-day, two-SD Bollinger Band, example, 63fsubroutine, 160–161system, example, 9b–10btrend algorithm, 64trend follower function, 63b–64bBollingerBand subroutine, 147Bollinger Benchmark, Keltner Challengers(contrast), 74tBollinger, John, 62Bollinger performance, three-dimensional contourchart, 98fBoolean expression, 116Boolean flags, usage, 15bBOTTOM failure, 39bottoming out, term (removal), 6Building Reliable Trading Systems (Fitschen), 264buy (AmiBroker keyword), 293Buy-and-hold mentality, 26BUY order, 121buyprice (AmiBroker keyword), 293buy (keyword), recognition, 4CCCI. See Commodity Channel IndexCFDT. See Cumulative frequency distribution tablechange (keyword), recognition, 4Choppy Market Indicator (CMI), 243–244Chromosomescrossing, VBA Excel (usage), 238–240dartboardcreation, VBA Excel (usage), 236example, 236dart-throwing blindfolded monkey (simulation),VBA Excel (usage), 236–237finding moms and pops, VBA Excel (usage),238–240fitness of chromosomes (testing), VBA Excel(usage), 232–233genes allocation process, VBA Excel (usage), 240genes passage, 240finitial population setup, VBA Excel (usage), 232mutation, 240–243VBA Excel, usage, 242–243population, 231probability of being hit by dart calculation, VBAExcel (usage), 235replacement function, VBA Excel (usage),237–238reproduction, 238–240selection, 233–238slice size, 234fitness conversion, VBA Excel (usage), 235class (object), 176ClassicShell, 169class rsiClass(object):, 317–318class stochClass(object):, 316–317Cluster analysis. See Walk-forward optimizationCMI. See Choppy Market IndicatorCode, arguments (presence), 161fCode Wizard. See AmiBroker Function LanguageCoincident indicator performance, 54tCombination lock (workings), finite statementmachine modeling, 17fComment text, usage, 157fCommitment of Traders Report (COT), 111commName, 183Commodity Channel Index (CCI), 48–53algorithmcoincident indicator performance, 54texample, 221–222performance, 51ttrades, generation, 50fOB/OS system description, 49b–50bprofit objective, usage, 327protective stop, usage, 327system, usage, 53ftrend following system, 52bp-code, 52b20-day CCI, calculation, 48Computer language, syntax (understanding), 2Conditional execution, 294–295Connors/Alvarez, time-based exit (usage),327–328Consecutive bar exact sequence paradigm,12, 21Consecutive bar sequence, 21–23COT. See Commitment of Traders Reportcover (AmiBroker keyword), 293Cover arrays, 121–122coverprice (AmiBroker keyword), 293Crossover rate, 247Crude oil, 60-day, two-SD Bollinger Band(example), 63fCumulative daily equity/drawdown, plotting(example), 153f341INDEXwww.rasabourse.com
- Page 1 and 2:
THE ULTIMATEALGORITHMICTRADING SYST
- Page 3 and 4:
THE ULTIMATEALGORITHMICTRADING SYST
- Page 5 and 6:
CONTENTSAbout the authorIntroductio
- Page 7 and 8:
Reproduction 238Mutation 240Using G
- Page 9 and 10:
ABOUT THE AUTHORIt was March of 198
- Page 11 and 12:
Well that was 27 years ago and I di
- Page 13 and 14:
xivINTRODUCTION TO THE ULTIMATE ALG
- Page 15 and 16:
xviINTRODUCTION TO THE ULTIMATE ALG
- Page 17 and 18:
CHAPTER 1Introductionto TradingAlgo
- Page 19 and 20:
However, at this introductory stage
- Page 21 and 22:
completely above the tableau. If th
- Page 23 and 24:
Don’t get bogged down trying to u
- Page 25 and 26:
checking account was down the $10K,
- Page 27 and 28:
Short Liquidation Condition—What
- Page 29 and 30:
One BarStrengthTwo BarStrengthThree
- Page 31 and 32:
and inexperienced trading system pr
- Page 33 and 34:
Input = 6StartInput = 4Input <> 6In
- Page 35 and 36:
The diagram in Figure 1.4 looks cle
- Page 37 and 38:
observed. If the latter criterion i
- Page 39 and 40:
Start or NewBarIs C >AVG(C,200)YesN
- Page 41 and 42:
CHAPTER 2Stochastics andAverages an
- Page 43 and 44:
The basic theory behind the ADX is
- Page 45 and 46:
4. Divide the 14-day smoothed plus
- Page 47 and 48:
if myADX < 35 thenif MarketPosition
- Page 49 and 50:
TABLE 2.1Performance of Directional
- Page 51 and 52:
FIGURE 2.4Source: TradeStationExamp
- Page 53 and 54:
Start orNew BarIs RSI < 30YesBuy Ma
- Page 55 and 56:
RSI DivergenceMarket Continuing to
- Page 57 and 58:
If marketPosition =-1 and close > e
- Page 59 and 60:
TABLE 2.3Performance of RSI Failure
- Page 61 and 62:
Start orNew BarIs Slow %K CrossingA
- Page 63 and 64:
TABLE 2.4Performance of Stochastic
- Page 65 and 66:
it is boundless extended readings a
- Page 67 and 68:
TABLE 2.5Performance of CCI algorit
- Page 69 and 70:
FIGURE 2.11Source: TradeStationThe
- Page 71 and 72:
We will discuss moving averages in
- Page 73 and 74:
MACDAvg = XAverage( MyMACD,9)MACDDi
- Page 75 and 76:
FIGURE 2.13Source: TradeStationThre
- Page 77 and 78:
LC0_E0B −25000 −41790 398 −62
- Page 79 and 80:
FIGURE 2.14Source: TradeStationA 60
- Page 81 and 82:
TABLE 2.8 Performance of Bollinger
- Page 83 and 84:
If filterTrade = false thenIf close
- Page 85 and 86:
Keltner ChannelChester Keltner brou
- Page 87 and 88:
FIGURE 2.15Source: TradeStationKelt
- Page 89 and 90:
35000300002500020000150001000050000
- Page 91 and 92:
TABLE 2.12Best Parameter Sets of Ke
- Page 93 and 94:
CHAPTER 3Complete TradingAlgorithms
- Page 95 and 96:
Box 3.1 Turtle System #1Buy one tic
- Page 97 and 98:
TABLE 3.1Turtle System 1 without LT
- Page 99 and 100:
TABLE 3.3Turtle System 1 with LTLF
- Page 101 and 102:
TABLE 3.4Tandem Performance of Turt
- Page 103 and 104:
Pause the Battle—Let’s Talk Ris
- Page 105 and 106:
Box 3.3 Battle Royale—And the Com
- Page 107 and 108:
TABLE 3.5Single Moving Average (SMA
- Page 109 and 110:
TABLE 3.8Donchian Channel Breakout
- Page 111 and 112:
we have, because who has the time t
- Page 113 and 114:
%Winners ShortLen InterLen StopDoll
- Page 115 and 116:
on a peak. This demonstrates a lack
- Page 117 and 118:
The correlation coefficients range
- Page 119 and 120:
TABLE 3.13The Best Results for the
- Page 121 and 122:
TABLE 3.17Results for the Donchian
- Page 123 and 124:
FIGURE 3.5AmiBroker’s walk-forwar
- Page 125 and 126:
direction of the 200-day moving ave
- Page 127 and 128:
range day and initially puts on two
- Page 129 and 130:
CHAPTER 4Introduction toAmiBroker
- Page 131 and 132:
Things All Programmers Need to Know
- Page 133 and 134:
expressions deal with a string of c
- Page 135 and 136:
AFL uses functions DateNum(), DateT
- Page 137 and 138:
to Short and Cover as well. If you
- Page 139 and 140:
FIGURE 4.2The AmiBroker Editor wind
- Page 141 and 142:
to the user. Instead of having to r
- Page 143 and 144:
This is where you can change the va
- Page 145 and 146:
shortMav = MA(C,avgLen1);longMav =
- Page 147 and 148:
code. This is a very difficult thin
- Page 149 and 150:
the order of the arrays. I admit th
- Page 151 and 152:
FIGURE 4.17The AFL Code Wizard ‘
- Page 153 and 154:
■■■This time click on is grea
- Page 155 and 156:
This should look very similar to th
- Page 157 and 158:
before a single line of code is typ
- Page 159 and 160:
COND3 = C > MA(C,100);COND1 = cente
- Page 161 and 162:
’********************************
- Page 163 and 164:
FIGURE 5.1trading.Once you define t
- Page 165 and 166:
GetDataGET DATACOMPONENTLoad Data i
- Page 167 and 168:
152USING MICROSOFT EXCEL TO BACKTES
- Page 169 and 170:
performance of the trading system.
- Page 171 and 172:
156 FIGURE 5.9 The Visual Basic Edi
- Page 173 and 174:
FIGURE 5.12This error message appea
- Page 175 and 176:
End IfIf marketPosition = -1 ThenCa
- Page 177 and 178:
■■moc—Market On Close order.
- Page 179 and 180:
Simple Moving Average Crossover usi
- Page 181 and 182:
Call Trade(ExitShort, "S-ATR Prof",
- Page 183 and 184:
168USING PYTHON TO BACKTEST YOUR AL
- Page 185 and 186:
It works well on both Unix and Wind
- Page 187 and 188:
function modules and some are a lit
- Page 189 and 190:
inclusive, the number of iterations
- Page 191 and 192:
176This indicator is programmed as
- Page 193 and 194:
if prices[curBar - offset] < prices
- Page 195 and 196:
All these files deal with opening a
- Page 197 and 198:
entryPrice,fileList,entryPrice,entr
- Page 199 and 200:
Python has a ton of reusable code a
- Page 201 and 202:
186USING PYTHON TO BACKTEST YOUR AL
- Page 203 and 204:
portfolioClass. These classes are n
- Page 205 and 206:
percent wins, number of trades, and
- Page 207 and 208:
>>> c = a + b>>> cAfter you hit ent
- Page 209 and 210:
you don’t need to know exactly ho
- Page 211 and 212:
Shorting occurs when the low of the
- Page 213 and 214:
That was the long entry logic only
- Page 215 and 216:
FIGURE 6.4brackets.A Python run-tim
- Page 217 and 218:
prevAvg2 and today’s avg1 must be
- Page 219 and 220:
■ TradeStation IDE204AN INTRODUCT
- Page 221 and 222:
206AN INTRODUCTION TO EASYLANGUAGEt
- Page 223 and 224:
FIGURE 7.5The algorithm with a sing
- Page 225 and 226:
the Vars statement and initialize t
- Page 227 and 228:
TABLE 7.1EasyLanguage Keywords and
- Page 229 and 230:
214AN INTRODUCTION TO EASYLANGUAGEF
- Page 231 and 232:
standard deviations. In our example
- Page 233 and 234:
218AN INTRODUCTION TO EASYLANGUAGEt
- Page 235 and 236:
into a project makes it easier to a
- Page 237 and 238:
If marketPosition =-1 thenbeginend;
- Page 239 and 240:
or program any trading idea. Practi
- Page 241 and 242:
CHAPTER 8Genetic Optimization,Walk
- Page 243 and 244:
superfast processors, searching a l
- Page 245 and 246:
This equation involves four unknown
- Page 247 and 248:
For generation = 1 To 100 ' total g
- Page 249 and 250:
Converting Fitness in Terms of Slic
- Page 251 and 252:
'the 6 darts landedRandomizeFor l =
- Page 253 and 254:
roulette(i) = Rnd(1#)If roulette(i)
- Page 255 and 256:
selection and reproduction may even
- Page 257 and 258:
This is just one possible solution.
- Page 259 and 260:
history of each market. This test w
- Page 261 and 262:
Crossover RateThe rate that determi
- Page 263 and 264:
TradeStation’s and AmiBroker’s
- Page 265 and 266:
TABLE 8.3In-Sample Testing TA2Le Se
- Page 267 and 268:
Here are the various calculations t
- Page 269 and 270:
1. movAvgLen { 50 to 150 by 10 incr
- Page 271 and 272:
TABLE 8.6The Out-of-Sample (OOS) Re
- Page 273 and 274:
your algorithm are each written on
- Page 275 and 276:
That’s it! These seven lines of c
- Page 277 and 278:
[Equity]350003000025000200001500010
- Page 279 and 280:
Calculating Start Trade Drawdown Wi
- Page 281 and 282:
A loop is used to flow through each
- Page 283 and 284:
The maximum drawdown of this algori
- Page 285 and 286:
■ Fixed Fractional272PORTFOLIO AN
- Page 287 and 288:
FIGURE 9.2Add a strategy to your st
- Page 289 and 290:
276FIGURE 9.6The UGTATS markets and
- Page 291 and 292:
278FIGURE 9.9 How to adjust the set
- Page 293 and 294:
FIGURE 9.12 The Trade Analysis wind
- Page 295 and 296:
282PORTFOLIO ANALYSISFIGURE 9.15thi
- Page 297 and 298:
FIGURE 9.18 Profit and drawdown are
- Page 299 and 300: FIGURE 9.20 To set the portfolio st
- Page 301 and 302: FIGURE 9.24Source: TradeStationThe
- Page 303 and 304: count makes sense; trades are turne
- Page 305 and 306: APPENDIX AAmiBrokerHere is a brief
- Page 307 and 308: switchbreak (part of the switch sta
- Page 309 and 310: Here is the source code from Chapte
- Page 311 and 312: PctSize = PositionRisk * MarginDepo
- Page 313 and 314: ■ KeywordsprevMarketPositionmarke
- Page 315 and 316: upSumAvg = upSum / lengthdnSumAvg =
- Page 317 and 318: Sub BollingerBand(dataList, length,
- Page 319 and 320: 308EXCEL SYSTEM BACKTESTERIf (kVal
- Page 321 and 322: ■ Keywords and Identifierscurrent
- Page 323 and 324: 312PYTHON SYSTEM BACKTESTERdef calc
- Page 325 and 326: sysMark =self.systemMarkets[i]avgLo
- Page 327 and 328: class stochClass(object):class stoc
- Page 329 and 330: 318PYTHON SYSTEM BACKTESTERfor i in
- Page 331 and 332: ■ Python-Specific Keywordsandasas
- Page 333 and 334: Monte Carlo Analysis# Monte Carlo A
- Page 335 and 336: FIGURE D.1324TRADESTATION AND EASYL
- Page 337 and 338: Simple RSI with Profit Objective an
- Page 339 and 340: If condition1 and condition2 then b
- Page 341 and 342: 330TRADESTATION AND EASYLANGUAGEIf(
- Page 343 and 344: if lastTradeLoser thenbeginif curre
- Page 345 and 346: Value1 = swingHighBar(1,h,pivotHiSt
- Page 347 and 348: ■■■■■■■Statistically
- Page 349: INDEXNote: Page references followed
- Page 353 and 354: ES. See Exhaustive searchESB. See E
- Page 355 and 356: Mini Russell day trading system, na
- Page 357 and 358: PPO. See Percentage price oscillato
- Page 359 and 360: Time-based market order (MOC), exit