Building Winning Trading Systems (cid:2) with TradeStation R Foundedin1807,JohnWiley&Sonsistheoldestindependentpublishingcompanyinthe UnitedStates.WithofficesinNorthAmerica,Europe,AustraliaandAsia,Wileyisglobally committed to developing and marketing print and electronic products and services for ourcustomers’professionalandpersonalknowledgeandunderstanding. The Wiley Trading series features books by traders who have survived the mar- ket’s ever changing temperament and have prospered—some by reinventing systems, others by getting back to basics. Whether a novice trader, professional or somewhere in-between,thesebookswillprovidetheadviceandstrategiesneededtoprospertoday andwellintothefuture. For a list of available titles, please visit our Web site at www.WileyFinance.com. Building Winning Trading Systems (cid:2) with TradeStation R Second Edition GEORGE PRUITT JOHN R. HILL JohnWiley&Sons,Inc. Copyright (cid:2)C 2012 by George Pruitt and John R. Hill. All rights reserved. Published by John Wiley & Sons, Inc., Hoboken, New Jersey. Published simultaneously in Canada. No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning, or otherwise, except as permitted un- der Section 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, Inc., 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600, or on the Web at www.copyright.com. Requests to the Publisher for permission should be addressed to the Permissions Depart- ment, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: While the publisher and author have used their best efforts in prepar- ing this book, they make no representations or warranties with respect to the accuracy or completeness of the contents of this book and specifically disclaim any implied warranties of merchantability or fitness for a par- ticular purpose. No warranty may be created or extended by sales representatives or written sales materials. The advice and strategies contained herein may not be suitable for your situation. You should consult with a professional where appropriate. Neither the publisher nor author shall be liable for any loss of profit or any other commercial damages, including but not limited to special, incidental, consequential, or other damages. TradeStation(cid:2) R and EasyLanguage (cid:2)R are registered trademarks of TradeStation Technologies, Inc., an affiliate of TradeStation, the use of which has been licensed to TradeStation. For general information on our other products and services or for technical support, please contact our Cus- tomer Care Department within the United States at (800) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Wileyalsopublishesitsbooksinavarietyofelectronicformats.Somecontentthatappearsinprintmaynotbe available in electronic books. For more information about Wiley products, visit our web site at www.wiley.com. LibraryofCongressCataloging-in-PublicationData: Pruitt,George,1967– BuildingwinningtradingsystemswithTradeStation[electronicresource]/GeorgePruittandJohnR.Hill.– 2nded. 1onlineresource.–(Wileytradingseries) Includesindex. DescriptionbasedonprintversionrecordandCIPdataprovidedbypublisher;resourcenotviewed. ISBN 978-1-118-26431-7 (mobipocket) – ISBN 978-1-118-23972-8 (epub) – ISBN 978-1-118-22643-8 (pdf) – ISBN978-1-118-16827-1(cloth)(print) 1.Investments–Dataprocessing. 2.Stocks–Dataprocessing. I.Hill, JohnR.,1926– II.Title. HG4515.95 332.64(cid:3)2028553–dc23 2012017829 PrintedintheUnitedStatesofAmerica 10 9 8 7 6 5 4 3 2 1 Idedicatethisbooktoallofthestrugglingtraders;Ihopeitprovidesinsightand guidancetotheirefforts. J.H. (cid:2) (cid:2) (cid:2) IdedicatethisbooktoMary,Cliff,Butch,andMarilynfortheireternalcourageand support.Eventhoughtheymaynotallstillbewithus,theirmemoriescarryon.I wouldalsoliketothankmysuccessfulandlovingwife,Leslie,andmywonderful children,BrandonandEmily. G.P. Contents Foreword xi Preface xvii Acknowledgments xix CHAPTER 1 Fundamentals—What Is EasyLanguage? 1 VariablesandDataTypes 2 OperatorsandExpressions 4 TradeStation2000ivsTradeStation9.0 7 Conclusions 32 CHAPTER 2 EasyLanguage Program Structure 33 StructuredProgramming 33 ProgramHeader 34 CalculationModule:MyRSIsystem 35 Conclusions 40 CHAPTER 3 Program Control Structures 41 ConditionalBranchingwithIf-Then 41 ConditionalBranchingwithIf-Then-Else 45 RepetitiveControlStructures 50 Conclusions 53 CHAPTER 4 TradeStation Analysis Techniques 55 Indicators 55 PaintBarandShowMeStudies 62 Functions 68 vii viii CONTENTS Strategies 72 Conclusions 77 CHAPTER 5 Measuring Trading System Performance and System Optimization 79 TradeStation’sSummaryReport 80 TradeAnalysis 90 OptimizationOldSchoolStyle 95 Conclusions 126 CHAPTER 6 Trading Strategies That Work (or the Big Damn Chapter on Trading Strategies) 127 TheKingKeltnerTradingStrategy 128 TheBollingerBanditTradingStrategy 131 TheThermostatTradingStrategy 134 TheDynamicBreakOutIIStrategy 141 TheSuperComboDayTradingStrategy 147 TheGhostTraderTradingStrategy 165 TheMoneyManagerTradingStrategy 168 BonusTradingStrategies 171 Conclusions 174 CHAPTER 7 Debugging and Output 175 LogicalversusSyntaxErrors 176 DebuggingwiththePrintStatementandthePrintLog 176 DebuggingwiththeBuilt-InDebugger 178 TableCreator 184 Conclusions 190 CHAPTER 8 TradeStation as a Research Tool 191 CommitmentofTradersReport 191 Conclusions 210 CHAPTER 9 Using TradeStation’s Percent Change Charts to Track Relative Performance 211 WorkingwithPercentChangeCharts 213 Conclusions 217 Contents ix CHAPTER 10 Options: Introduction and Strategies 219 PartA:GettingStartedwithOptionsTrading 219 PartB:Real-LifeOptionsStrategiesandTrades 242 Conclusions 250 CHAPTER 11 Interviews with Developers 251 APPENDIX A TradeStation 2000i Source Code of Select Programs 295 BollingerBandit 295 DynamicBreakOutIIbyGeorgePruitt 296 DBSIIFadebyGeorgePruitt 297 KingKeltnerProgrambyGeorgePruitt 298 MyAdxSys 299 MyMomRsi 300 MyMovAvgSys 301 MyTrailPrcntStop 302 SeasonalSoybean 303 SuperCombobyGeorgePruitt 304 ThermostatbyGeorgePruitt 307 TheGhostTraderbyGeorgePruitt 309 TheMoneyManagerbyGeorgePruitt 311 APPENDIX B Reserved Words Quick Reference 313 About the Website 389 Index 391