Home

Welcome to 2024 and a New Version

The Official Site of TradingSimula-18 and “TrendFollowing System – 2nd Edition: A DIY Project – Batteries Included”

Hello, George Pruitt here!

Summer/Fall 2024:  I have delayed the release my TS-18 [2024] edition for a few more weeks.  Just when I think I am ready to go, I think of a different way to modify the user interface in the system module.  In addition, I wanted to enhance the user’s manual and documentation through a wiki and an online manual that I created with Typora MD editor.  I have absolutely fallen in love with this application.  I have added a beta version of the manual while I compile it at Manual Beta.  I have also written a few more helper Python scripts to help you create those pesky .por portfolio files and a new dataMaster.csv files based on your ascii database.  If you have Pinnacle Data or CSI Data, then most or all of the work is already done for you right out of the box.  New purchasers will receive a deep history of ten futures markets graciously provided my Ed Pavia at Pinnacle Data.  This is the data that I use to develop TS-18.  Of course, you can use CSI and/or Norgate.  You just need to know the filename for each market, the big point value (the amount in dollars to raise the leading digit before the decimal point by one) and the minimum tick move.  For decades, data vendors used the first two characters of the filename as the symbol, and Pinnacle Data defaults to this nomenclature.  With the number of futures markets around the world increasing, some vendors allow you to choose how many characters of the filename to represent the symbol.  CSI allows you to select the first two as an option when exporting a portfolio.  Some vendors use the entire filename as the symbol.  I have updated TS-18 to be universally compatible to the symbol naming convention.  Here is how you choose your database with the latest TS-18 module interface.

#--- Set Your Database Here ----------------------------------------------------
#--- Make sure your dataMasterXXX.csv is set up properly with contract specs
#--- Toggle comment to get your dataBase name - default is Pinnacle Data
#-------------------------------------------------------------------------------
dataBase = 'Pinnacle'
#dataBase = 'CSI'
#dataBase = 'Quandl'
#dataBase = 'Custom'
## R U using stock data? Set dataBase = 'Stocks'
#dataBase = 'Stocks'
## using first chars of fileName for symbol? if not set to 0
useFirstNCharsAsSymbol = 2
Specifying a database for TS-18

Here I am using the default database – Pinnacle.  You can choose CSI or Quandl (a deprecated database that I initially used, and you can still download the old data from the TS-18 webpage) or custom.  If you look in the TradingSimula-18_2024 directory you will find these dataMaster files:

  • dataMasterPinnacle.csv
  • dataMasterCSI.csv
  • dataMasterQuandl.csv
  • dataMasterCustom.csv

The data files are simple comma delimited values files that are what I call a Futures Dictionary and contain the markets filename minus the extension, the big point value, the minimum move and the name of the market.  Here is an example:

AN_REV,1000,0.01,Aus.Dol

ZL_REV,600,0.01,BeanOil

BN_REV,625,0.01,B.Pound

ZU_REV,1000,0.01,Crude

ZC_REV,50,0.25,Corn

CC_REV,10,1,Cocoa

CL_REV,1000,0.01,Crude

CN_REV,1000,0.01,Can.Dol

CT_REV,500,0.01,Cotton

FN_REV,1250,0.005,EuroCur

DX_REV,1000,0.005,DolIndx

ED_REV,2500,0.0025,EuroDol

EM_REV,100,0.1,MidCap

MD_REV,100,0.1,MidCap

I have also played around with the built-in indicators and simple ways of incorporating ChatBot source code right into the TS-18 indicators module.  The release version will have a complete manual and a complete wiki for support.  Any questions or concerns can be emailed to me as well and I usually answer relatively quick.

Winter 2023/2024:  I have added an easier way to interface with the class-based indicators.  I will be releasing this version in beta format very soon.  Data has been cobbled through then end of 2023.  Go to the TradingSimula-18 menu and plug in the password to access this data.

Click Image to go to TradingSimula-18 WIKI!

Check out the latest wiki @ TradingSimula-18 Wiki — a user’s guide for George Pruitt’s python back tester (tiddlyhost.com).

Fall 2023:  A new TradingSimula-18 wiki has been started at:

TradingSimula-18 Wiki — a user’s guide for George Pruitt’s python back tester (tiddlyhost.com)

This wiki is currently under development.  However, there is still a ton of information available.

Summer 2023: Breaking News:  CommodityFutures data updated through May 31, 2023.  Go to the TS-18 download page to get the data.  All charts have been updated through May 31, 2023.  See how these three popular algorithms have suffered through the last 12 months.  Coming in the Fall of 2023 George will release his faster version of TS-18.   This version will have additional features as well.  A few minor adjustments to your code is all it will take to harness the new power.

2024 Update!  I am still, yes still, working and improving TradingSimula-18.  I have been working with Python since 2016 and still learning some of its really cool functions and tools.  As you know I try my best to hide code that the user doesn’t need to concern herself with, and I do this by storing many lines of code in text strings and executing the Python code when necessary.  All the user sees is the name of the string and not the embedded code.  Well, in 2022 I discovered not only could I execute a string of code in-line, but I could also pre-compile that code so execution would be extremely fast.  Soon, I will release this update and a video that demonstrates how to use the new mods.  The great news is the speed-up, but unfortunately, I had to change the basic template a little bit here and there.  You can continue to run your scripts as is or you can adopt the newer version.  Making changes to your existing scripts is really, really easy and I will reveal that in the new video as well.  I still don’t use many external libraries such as pandas, numpy or scipy.  I will in the future, but for now I want the “core” to be “pure” Python.  Most traders are not programmers, and having to install a large environment such as Anaconda or PIP install many libraries is simply over their heads.  I work with old school engineers and new and old traders, and keeping things simple always works out the best.  Also, I have added useEZIndicatorClasses for a simple interface into the class based indicators.  

My Current Python and Programming Tools – updated 2024

  • Pyscripter – please donate a few dollars for this killer IDE!
  • Sublime Text – small fee based powerful editor.
  • NotePad++ – free powerful editor (both Sublime and NotePad++ include REGEX.
  • Explorer++ – power Windows Explorer – put your most used folders into a tabbed environment.
  • Windows 11 File Explorer – pretty neat and a major upgrade.  I now do a lot with this in place of Explorer++
  • Microsoft Power Toys – some really neat features that should be in the operating system already.  I love Always On Top.
  • GreenShot – small fee-based screen capture software.

In early 2022 I wrote, “Before reading the intro I just wanted you to know that I have released a new refactored version of TradingSimula_18.  Refactoring means simplifying the interface.  Instead of wading through 300 lines of code, you can accomplish the same thing from a top-down programming paradigm.    Some other bells and whistles have been added as well.  A beta version of TradingSimula-18 Charting has also been released.  Because of these changes and additions, I have written a second edition to the original Trend Following Systems book.  If you purchased the first edition, take a picture of the first page of the book and send it to me and I will send you a PDF of the new book (george.p.pruitt@gmail.com).  If you want a paper back or hard cover, then I will only charge for the production and shipping and handling.  I don’t have that number yet, but I will soon.    I had been very busy writing my Easing Into EasyLanguage series of books and have finished 2 of the 3 books.  I decided to take break from EasyLanguage and concentrate on Python and TradingSimula_18[2022].  The new edition updates all of the systems through March of 2022 and introduces the new interface.

The New Look – this isn’t the newest look, but it is very close – keep checking back for my latest release.

So, if you have bought the book make sure you sign up for the newsletter or check back here frequently.  Also, I will be releasing some complete trend following modules for TS-18 and EasyLanguage.  I am working on finalizing an order generation module that will produce orders for the next day. [update Winter 2024 – I have almost completed my updates].  The following demonstrates how to program a simple Donchian system (89 day entry and 13 day exit), that incorporates money management and reinvestment of profits.  Trade risk is defined by the difference from the highest high of 89 days and lowest low of 13 days for the long side.  The short side trade risk is defined by the difference between the highest high of 13 days and lowest low of 89 days.  These levels are the predefined long, long exit, short, and short exit trade levels.  If the trade risk is too great, then an average true range calculation is used to determine trade risk.  See if the code makes sense to you.  If you are flat, then you add a buy and sell short order to the daily tradeTicket with appropriate position size.  If you are long then you add an exitLong order to your trade ticket and the same goes for being short, except you use the keyword exitShort.  Once your orders are placed with today’s orderTicket, TradingSimula-18 uses a order processing decision engine to determine which order should be executed.

 

#----------------------------------------------------------------------------------
# Set up algo parameters here - from Covel's book Trend Following
#----------------------------------------------------------------------------------
startTestDate = 20000101 #must be in yyyymmdd
stopTestDate = 99999999 #must be in yyyymmdd
rampUp = 200 # need this minimum of bars to calculate indicators
sysName = 'TF-Covel_3RF' #System Name here
initCapital = 1000000
commission = 50
#----------------------------------------------------------------------------------
#Inputs
longEntryLen = shortEntryLen = 89
longExitLen = shortExitLen = 13
#instantiate class based indicators
useEZindicatorClasses = True
useADX = True
useLaguerre = False
useParabolic = False
useStochastic = False
useRSI = False
useMACD = False
useDominantCycle = False
#Region Include Section
#-------------------------------------------------------------------------------------------------
marketList = getData(isStock=False) # loads data from .csv or .por file and sets attributes
#-------------------------------------------------------------------------------------------------
#Region More Includes
#---------------------------------------------------------------------------------
# Optional - use this area to create user lists and
# lists of indicator classes - include the list in the loop
# if you need to instantiate or initialize
#---------------------------------------------------------------------------------
for curMarket in range(0,numMarkets):
if useADX == True: adxList.append(adxClass()) # instantiating a list of ADX
if useLaguerre == True: LagRSI.append(laguerreRSIClass())
if useParabolic == True: parabolicList.append(parabolicClass())
if useStochastic == True: stochasticList.append(stochClass())
if useRSI == True: rsiList.append(rsiClass())
if useMACD == True: macdList.append(macdClass())
if useDominantCycle == True: domCycleList.append(dominantCycleClass())
if useSuperTrend == True: superTrendList.append(superTrendClass())

#---------------------------------------------------------------------------------
# Set Up Sectors Here - remember you must use the exact symbol for each marketData
# Review process in book if necessary - predfined for Pinnalce and CSI data
#---------------------------------------------------------------------------------
#Region SectorsectorList = list()
for curPortBar in range(barCount,endBarCount+1):
portManager.portDate.append(masterDateList[curPortBar])
if curPortBar % 225 == 0 : print("Working on bar #: ",curPortBar," of ",endBarCount)
for curMarket in range(0,numMarkets):
exec(execCode6)
#---------------------------------------------------------------------------------------------------
# Assign lists based on marketMonitor here - assigning temp lists here is great idea
#--------------------------------------------------------------------------------------------------
curTradesList = marketMonitorList[curMarket].tradesList
curMarketData = marketMonitorList[curMarket].marketData
#---------------------------------------------------------------------------------
# Do not change code below
#---------------------------------------------------------------------------------
if masterDateList[curPortBar] in marketMonitorList[curMarket].marketData.date:
exec(execCode7)
#---------------------------------------------------------------------------------------------------
# Start programming your great trading ideas below here - don't touch stuff above
#---------------------------------------------------------------------------------------------------
# Remember every line of code is executed on every day of every market
# Make sure you want to do this - if not it can slow down processing
# Define Long, Short, ExitLong and ExitShort Levels - mind your indentations
# Indent-->
buyLevel = highest(myHigh,longEntryLen,curBar,1) + myMinMove
shortLevel= lowest(myLow,shortEntryLen,curBar,1) - myMinMove
longExit = lowest(myLow,longExitLen,curBar,1) - myMinMove
shortExit = highest(myHigh,shortExitLen,curBar,1) + myMinMove

# Covel defined the money management rules as:
ATR = sAverage(myTrueRange,15,curBar,1)
posSize1 = .02*dailyPortCombEqu/((buyLevel - longExit)*myBPV)
posSize2 = .02*dailyPortCombEqu/((shortExit - shortLevel)*myBPV)
posSizeATR = .02*dailyPortCombEqu/(2*ATR*myBPV)

posSize1 = max(int(min(posSize1,posSizeATR)),1)
posSize2 = max(int(min(posSize2,posSizeATR)),1)
# if you want to use the money namagement rules comment out the next line
posSize1 = posSize2 = 1

# Long Entry - Okay Let's put in some logic to create a long position
if not(long):
price = buyLevel
tradeName = "TF-Covel-B"
posSize = posSize1
tradeTicket.append([buy,tradeName,posSize,price,stp])
# Long Exit 1
if long and barsSinceEntry > 1:
price = longExit
tradeName = "Lxit"
tradeTicket.append([exitLong,tradeName,curShares,price,stp])
# Short Entry - Okay Let's put in some logic to create a short position
if not(short):
price = shortLevel
tradeName = "TF-Covel-S";
posSize = posSize2
tradeTicket.append([sellShort,tradeName,posSize,price,stp])
# Short Exit
if short and barsSinceEntry > 1:
price = shortExit
tradeName = "Sxit"
tradeTicket.append([exitShort,tradeName,curShares,price,stp])

exec(execTradeTicket)
#Region EOD Calculations
Latest TS-18 Interface

This is the official website for Trend Following and my latest book – “Trend Following Systems: A DIY Project – Batteries Included.”  Here you will find all the resources mentioned in the book – plus a blog.  If you have not purchased the book you can find it at Amazon.com.  This website will be the repository for TradingSimula-18 and all its associated code and the algorithms I have programmed into the platform.  If you’re looking for the source code from the book, click on this link: https://www.trendfollowingsystems.com/tradingsimula-18/

One of the weaknesses of many back testing platforms is the lack of good documentation.  My latest book does a pretty good job explaining TS-18 and Trend Following Systems and different portfolio level manipulations, but I wanted to provide a free user’s guide to help further explain the power of TS-18 and also introduce it to potential users.  Here is a link to the document that I started a few weeks ago – it is an ongoing project so check back frequently.

TS-18 Introduction and User’s Guide

Trend Following 2nd Edition with Refactored TS-18

Welcome to TrendFollowingSystems.com.  I have wanted to create this website for a very long time so that I could share my experiences in trading futures on all kinds of systems, but especially on those that fall under the Trend Following umbrella.  I started this journey back in 1989 when trading was like shooting fish in a barrel.  All you needed was a four-week Donchian and common-sense allocation – the world was your oyster.  The late eighties were an era of trading when “The Prince of the Pit” and his   magnum opus was at its most lofty heights.

It is a cold hard fact that Dennis and many of his “Turtles” made fortunes.  It is also a cold hard fact that many individuals have made fortunes not trading but selling the “Turtle Enigma.”  The sheen of the “core” algorithm and its associated “rules” has dulled considerably since the late 90’s.  Is this a consequence of dissemination or the lack of arbitrage due to heightened market efficiency?  Probably the latter.  How many times have you heard someone describe another’s trading prowess by stating, “He could have tomorrow’s Wall Street Journal and still lose!”  So, what, the rules to the highly secretive algorithm were proffered up in all kinds of different manners:  multi-thousand-dollar lectures, $49 books (including mine), and freely by a real Turtle.  There isn’t any magic to trend following – not then and not now.

Active Trader Magazine

In August of 2003 I was on the cover of Active Trader Magazine as a proponent of Trend Following.  Over the years I have seen trader after trader fail when it came to short term trading.  Swing trading sounds very exciting but has failed to live up to fruition – it also requires many more resources to trade then a simple, yet robust, trend following algorithm.

The “rub” is trying to find a trend following algorithm that won’t bankrupt you before it can take advantage of the “eventual” trendiness of the markets.  I am going to introduce three very popular algorithms that at one time were considered the cream of the crop – profitable, simple, adaptable and easy to trade.  The first algorithm will be based off of Bollinger Bands.  After the Turtle N- day/week algorithm, this was probably the most popular during the 90’s and the first decade in the new millennium.  The next algorithm I will show is the “core” of the “Turtle” a.k.a. Donchian.  And finally Chester Keltner will chime in with his approach.   Remember all of this data is hypothetical.  I used 30+ different commodity markets going back to 1990 for the back test.  $100 was levied per round turn and compounding was not used.  A $2000 stop was employed on each and every trade.  These analyses are for educational purposes only to help demonstrate the power and weaknesses of the more popular trend following algorithms.

NOW UPDATED THRU 12/31/2023 utilizing www.pinnacledata.com continuous contract data.  

 

 

Please read the following disclaimer.  By scrolling down beyond this section you are agreeing that you have read the disclaimer and fully understand what it is stating.  If you don’t agree please simply close this web page by clicking the close box in the upper right of the page.  Thank you!

CFTC-required risk disclosure for hypothetical results:

Hypothetical performance results have many inherent limitations, some of which are described below. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. in fact, there are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program.

One of the limitations of hypothetical performance results is that they are generally prepared with the benefit of hindsight. In addition, hypothetical trading does not involve financial risk, and no hypothetical trading record can completely account for the impact of financial risk in actual trading. For example, the ability to withstand losses or to adhere to a particular trading program in spite of trading losses are material points which can also adversely affect actual trading results. There are numerous other factors related to the markets in general or to the implementation of any specific trading program which cannot be fully accounted for in the preparation of hypothetical performance results and all of which can adversely affect actual trading results.

The Portfolio

Currencies

B.Pound-BN
S.Franc-SN
Aus.Dol-AN
$ Index-DX
EuroCur-FN
Jap.Yen-JN
Can.Dol-CN

Energies and Metals

Crude-ZU
HeatOil-ZH
Nat.Gas-ZN
RBOB-Un-ZB
Gold-ZG
Silver-ZI
Copper-ZK
Platinum-ZP
Palladium-ZA

Grains and Financials

S.Beans-ZS
Wheat-ZW
Corn-ZC
BeanOil-ZL
Soymeal-ZM
R.Rice-ZR
T. Bond-US
10YNote-TY
2YNote-TU
EuroDol-EC

Softs and Meats

Sugar-SB
Coffee-KC
Cocoa-CC
Cotton-CT
Lumber-LB
O.Juice-JO
LCattle-ZT
LHogs-ZZ
Feeder-ZF

2020, 2021 and first half of 2022 Big for Trend Following Systems!  The last 12 months have brought Trend Following back to Earth!

Typical Trend Following results on a 1 contract basis – didn’t come in time for most CTAs at the end of the last decade.  If Trend Followers were able to survive, these 2020, 2021 and part of 2022 would have stabilized returns and perhaps positioned them for a potential large run up.  However, things have fallen apart for trend following since last summer.  The interest rate hikes are probably the most to blame. Our $2000 MM stop probably needs to revisted.

Simple Donchian Performance since Jan. 1st 2010. 2023 saw the trends come to an end and the rate hikes have thrown us into the abyss once again.  The hint of scaling back rates generated some trends in late 2023.

Simple Donchian from 2010

Covid-19 [Delta][Omicron][Vaccines] Rate Hikes [Rate Rumors] 23 Santa Claus Trend Following

The markets have been moving this year.  Softs (mostly lumber) and energies are the big winners.  Financials – a distant third.

Bollinger Band Trend Following Algorithm

Updated thru December 31, 2023!


This concept has been around for a very long time.  John Bollinger has made it famous.  Basically, the signal trigger is on the penetration of +/- a number (x) of standard deviations above/below the moving average that is used in the sample.  A short-term Bollinger band can be used to represent resistance/support levels.  Using a longer-term Bollinger band like we did here (60-days) flips the philosophy around – if the market breaks out then there is a good chance of follow through.  It’s easy to see how the energy sector overwhelmed the portfolio during the genesis of the great recession when crude went from $50 to $150 back to $40 a barrel in a short period of time.  Diversification helped propel the equity curve nearly at a 45-degree angle but did not prevent the 25% plus draw down nor the multi-year flat periods.  Sign up for the blog updates via email and I will send you the Python code (need to buy the book) and/or EasyLanguage source code for these three systems for free!

Donchian Trend Following Algorithm

Richard Donchian is the father of the Donchian Channel; buy when the market exceeds the highest high of the past x days and sell short when the market drops below the lowest low of the past x days.  Liquidation often occurs at the lowest/highest of x/2 days back.  This is the core to the “Turtle” system.  The Turtle system involved a position sizing overlay and a “LTL” filter – only trade after a losing trade if using the shorter term look back period – usually 20 days.  All 55 day breakout were taken.  Many of the Turtles went on to manage “BIG” money utilizing the Turtle algorithm or a derivative of it.  Jerry Parker, arguably the most successful Turtle, of Chesapeake Capital still employs a trend following algorithm trading a world wide basket of market and has done quite well.  If you study his equity curve you will notice some similarities to these.

Keltner Trend Following Algorithm

Chester Keltner, a grain trader from Chicago, is credited with creating this algorithm.  This algorithm introduces the concept of the typical price (H + L + C) / 3.  This price might represent the daily market action better than just using the closing price as the foundation for the rest of the formula.  This algorithm averages the last 80 typical prices and then adds/subracts two average true ranges to create the channels.  Keltner Channels and Bollinger Bands are similar in that they envelop the current market and signal generation occurs at the penetration of the channels/bands.  Performance using 80 days the moving average calculation along with 2 ATR is not as good as the Donchian or Bollinger algos.

The Three Algorithms Compared

Needless to say, there is a high correlation among these trend following algorithms.  There really isn’t any benefit of choosing one over the other – they seem to buy/sell are very similar times and prices.  You could change the parameters to each one and change the entry levels but which one should you eventually go with.  Or should you optimize the parameters on a per market basis?  Speaking from experience this is usually a big no-no.  So what is one to do?

Copyright 2024 Trend Following Systems