Category Archives: Algorithmic Trading Commentary

Dr. ChatGPT, or How I Learned to Stop Worrying and Love AI.

Embracing AI: The Journey from Skepticism to Synergy with ChatGPT.

Using TradeStation XML output, Python and ChatGPT to create a commercial level Portfolio Optimizer.

As a young and curious child my parents would buy me RadioShack Science Fair Kits, chemistry sets, a microscope and rockets.  I learned enough chemistry to make rotten egg gas.  I grew protozoa to delve into the microscopic world.  I scared my mom and wowed my cousins with the Estes Der Big Red rocket.  But it wasn’t until one Christmas morning I opened the Digital Computer Kit.  Or course you had to put it together before you could even use it – just like the model rockets.  Hey, you got an education assembling this stuff.  Here is a picture of a glorified circuit board.

My first computer.

This really wasn’t a computer, but more of an education in circuit design, but you could get it to solve simple problems “Crossing the River”, decimal to binary, calculating the cube root and 97 other small projects.  These problems were solved by following the various wiring diagrams.  I loved how the small panels would light up with the right answers, but grew frustrated because I couldn’t get beyond the preprogrammed wiring schema.  I had all these problems I wanted to solve but could not figure out the wiring.  Of course, there were real computers out there such as the HAL 9000.  Just kidding.  I would go to the local Radio Shack and stare at the all the computers.  Hoping one day I would have one sitting on my desk.  My Dad was an aircraft electrician (avionics) in the U.S. Navy with a specialty in Inertial Navigation Systems.  He would always want to talk about switches, gyros, some dude named Georg Ohm and oscilloscopes.  I had my mind stuck in space, you know “3-D Space Battle” – the Apple II game, to listen or to learn from his vast knowledge.    A couple of years later and a paper route I had a proper 16K computer, the TI-99-4A.  During this time, I dreamed of a supercomputer that could answer all my questions and solve all my problems.  I thought the internet was the manifestation of this dream, but in fact it was the Large Language Models such as ChatGPT.

Friend or Foe

From a programmer’s perspective AI can be scary, because you might just find yourself out of a job.  From this experiment, I think we are a few years away from this possibility.  Quantum computing, whenever it arrives, might be a viable replacement, but for now I think we are okay.

The Tools You Will Need

You will need a full installation of Python along with Numpy and Pandas installed on your computer if you want ChatGPT to do some serious coding for you.  Python and its associated libraries are simply awesome.   And Chat loves to use these tools to solve a problem.  I pay $20 a month for Chat so I don’t know if you could get the same code as I did if you have the free version.  You should try before signing up.

The Project:  A Portfolio Optimizer using an Exhaustive Search Engine

About ten years ago, I collaborated with Mike Chalek to develop a parser that analyzes the XML files TradeStation generates when saving strategy performance data. Trading a trend-following system often requires significant capital to manage a large portfolio effectively. However, many smaller traders operate with limited resources and opt to trade a subset of the full portfolio.

This approach introduces a critical challenge: determining which markets to include in the subset to produce the most efficient equity curve. For instance, suppose you have the capital to trade only four markets out of a possible portfolio of twenty. How do you decide which four to include? Do you choose the markets with the highest individual profits? Or do you select the ones that provide the best profit-to-drawdown ratio?

For smaller traders, the latter approach—prioritizing the profit-to-drawdown ratio—is typically the smarter choice. This metric accounts for both returns and risk, making it essential for those who need to manage capital conservatively. By focusing on risk-adjusted performance, you can achieve a more stable equity curve and better protect your account from significant drawdowns.

I enhanced Mike’s parser by integrating an exhaustive search engine capable of evaluating every combination of N markets taken n at a time. This approach allowed for a complete analysis of all possible subsets within a portfolio. However, as the size of the portfolio increased, the number of combinations grew exponentially, making the computations increasingly intensive. For example, in a portfolio of 20 markets, sampling 4 markets at a time results in 4,845 unique combinations to evaluate.

Calculating the number of combinations.

Using the formula above you get 4,845 combinations.  If you estimate each combination to take once second, then you are talking about 21 minutes.  N/2 will produce the most combinations.  Sampling 10 out of 20 will take 51.32 hours.

  • 1 out of 20: 20 combinations
  • 2 out of 20: 190 combinations
  • 3 out of 20: 1,140 combinations
  • 4 out of 20: 4,845 combinations
  • 5 out of 20: 15,504 combinations
  • 6 out of 20: 38,760 combinations
  • 7 out of 20: 77,520 combinations
  • 8 out of 20: 125,970 combinations
  • 9 out of 20: 167,960 combinations
  • 10 out of 20: 184,756 combinations
  • 11 out of 20: 167,960 combinations

The exhaustive method is not the best way to go when trying to find the optimal portfolios across a broad search space.  This is where a genetic optimizer comes in handy.  I played around with that too.  However, for this experiment I stuck with a portfolio of eleven markets.  I used the Andromeda-like strategy that I published in my latest installment of my Easing Into EasyLanguage series.

Here is the output of the project when sampling four markets out of a total of eleven.  All this was produced with Python and its libraries and ChatGPT.

Tabular Format

The best 4-Market portfolio out of 11 possibilities.

Graphic Format

ChatGPT, Python, Matplotlib, oh my!

Step 1 – Creating an XML Parser script

You can save your strategy performance report in RINA XML format.  The ability to save in this format seems to come and go, but my latest version of TradeStation provides this capability.  The XML files are ASCII files that contain every bar of data, market and strategy properties and trades.  However, they are extremely large as each piece of data has prefix and suffix tag.

<StrategyPerformance>
<Market>
<Name>SPY</Name>
<Bars>
<Bar>
<Date>2024-12-01</Date>
<Open>450.25</Open>
<High>455.30</High>
<Low>449.85</Low>
<Close>452.10</Close>
</Bar>
<Bar>
<Date>2024-12-02</Date>
<Open>452.15</Open>
<High>458.40</High>
<Low>451.50</Low>
<Close>457.75</Close>
</Bar>
</Bars>
</Market>
<Trades>
<Trade>
<Type>Buy</Type>
<Date>2024-12-01</Date>
<Price>450.50</Price>
<Quantity>100</Quantity>
</Trade>
<Trade>
<Type>Sell</Type>
<Date>2024-12-02</Date>
<Price>457.50</Price>
<Quantity>100</Quantity>
</Trade>
</Trades>
<PerformanceMetrics>
<NetProfit>700.00</NetProfit>
<Drawdown>50.00</Drawdown>
<ProfitFactor>2.5</ProfitFactor>
</PerformanceMetrics>
</StrategyPerformance>
Small example of XML file

​Imagine the size of the XML when working with one or even five-minute bars.  

Getting ChatGPT to create an XML parser for the specific TradeStation output

  • The first thing I did was save the performance, in XML format, from a workspace in TradeStation that used an Andromeda-like strategy on eleven different daily bar charts.
  • I asked Chat to analyze the XML file that I attached to a new chat.  I started a new chart for this project.  I discovered the chat session is also known as a “workflow”.  This term emphasizes:
    • Collaboration: We work as a team to tackle challenges.
    • Iteration: We revisit and improve upon earlier steps as needed.
    • Focus: Each session builds upon the previous ones to move closer to a defined goal.
  • Once it understood the mapping of the XML, I asked Chat to extract the bar data and output it to a csv file.  And it did it without a hitch.  When I say it did it, I mean it created a Python script that I loaded into my PyScripter IDE and executed.
  • I then asked for an output of the trade-by-trade report, and it did it without a hitch.  Notice these tasks do not require much in the way of reasoning.

Getting ChatGPT to combine the bar and trade data to produce a daily equity stream.

This is where Python and its number crunching libraries came in handy.  Chat pulled in the following libraries:

  • xml.etree
  • pandas
  • tkinter
  • datetime

I love Python, but the level of abstraction with its libraries can make you dizzy.  It is not important to fully understand the panda’s data frame to utilize it.   Heck, I didn’t really know how it mapped and extracted the data from the XML file.  I prompted chat with the following:

[My prompts are bold and italicized.]

With the bar data and the trade data and the bigpointvlaue, can you create an equity curve that shows a combination of open trade equity and closed trade equity?  Remember the top part of the xml file contains bar data and the lower part contains all the trade data.

It produced a script that hung up.  I informed chat that the script hung up and that the script wasn’t working.  It found the error and fixed it.  Think about what Chat was doing. It was able to align the data so that open trades produced open trade equity and closed out trades produced closed trade equity.  Well, initially it had a small problem.    It knew what Buy and Sell meant, and the math involved with calculating the two forms of equity, open and closed.  I didn’t inform Chat of any of this.  But the equity data did not look exactly right.  It looked like the closed trade equity was being calculated improperly.

Is the Script checking for LExit and SExit to calculate when a trade closes out?

Once it figured out that the equity stream must contain open and closed trade equity and learned the terms, LExit and SExit, a new script was created that nearly replicated the equity curve from the TradeStation report.  When Chat starts creating lengthy scripts it will open a side bar window call the “Canvas” and put the script in there.  This makes it easier to copy and paste the code.  I eventually noticed that the equity curve did not include commission and slippage charges.

Please extract the slippage and commission values and deduct this amount from each trade.

At this point the workflow remembered the mapping of the XML file and was able incorporate these two values into the trade processing.  I wanted the user to be able to select multiple XML files and have the script process these files and produce the three output files, bar_data, trade_data, and equity_data.    I did have to explain that the execution costs must be applied to all the entries and exits.

I would like the user to select multiple xml files and create the data and trade and equity files incorporating the system name and market name and their naming scheme.

A new library was imported, TKinter and a file open dialog was used for the user to select all the XML files they wanted to process.  These few chores required very little interaction between Chat and me.  I thought, wow this is going to be a breeze.  I moved onto the next phase of the project by asking Chat the following:

Can you create a script that will use Tkinter to open the equity files from the prior script and allow the user to choose N out of the total files selected to create all the combined equity curves using an exhaustive search method.

I knew this was a BIG ASK!  But it swallowed this big pill without a hitch.  Maybe us programmers will be replaced sooner than later.  I wanted to fine tune the script.

Can you keep track of maximum draw down for each combination and then sort the combinations by the profit to draw down ratio. For the best combination can you create a csv file with the daily returns so i can plot them in Excel.

On a quick scan of the results, I did not initially notice that the maximum draw-down metric was not right.  So, I pushed on the fine tuning.

This works great. In the output files can we delete the path name to the csv files. For the output I would just like to have the system name and the symbol for each combination.

Script created.

I had the following error message. NameError: name ‘all_combinations’ is not defined. I also asked Chat if it can you add “Date” to the header for the combination daily files?

Many times, Chat will just recreate the part of the code that needs to be modified.  This makes copying and pasting difficult, because you have to make sure you find the right location in the code to replace.  I always ask Chat to recreate the entire script with the latest changes.  

Hey Chat, the following error message was created:  system, symbol = filename.replace(“.csv”, “”).split(“_”) ValueError: too many values to unpack (expected 2)

The error was fixed, but I finally noticed the maximum draw down calculations were not right.

I don’t think the maximum draw down metric is being calculated properly. “Andromeda-Like_@SB, Andromeda-Like_@EC, Andromeda-Like_@S, Andromeda-Like_@JY”,
PL:  92141.8499999999,
DD:  92985.59999999992,
Ratio:  0.990926014350609,144.
The draw down metric is similar to the total profit metric.
Script created.

The draw down is still not calculated properly. I think there is an error in your reasoning. I calculate draw down by iterating through the equity curve and keeping track of peaks and subsequent troughs. The largest distance between the peaks and its associated trough is the max draw down.

Script created but looked a little primitive.  So, I asked.

Is this the most efficient method?

Well, I should have kept my mouth shut.  I felt like the Python libraries would be able to do this much quicker with list comprehension or with some other magic.   And Chat agreed with me.  Script created.

The draw down is still incorrect.

Script created.

It was still wrong and instead of going back and using the original draw down script I tried to nudge Chat into the right direction.

The equity curve will have multiple peaks and multiple troughs. You will need to keep track of all of the peaks and troughs and then find the maximum distance between the sets of peaks and troughs.

Script created and was still wrong.  This is where you start going down a rabbit hole.  Chat will produce debugging script to try and figure out where the error resides.  But this is very time consuming, so I kept pushing Chat to do it right.

Each peak must be tied to its respective trough. Each distance between each respective peak and drawdown can then be measured for the largest value.

Script is wrong.

This still not working. I don’t think you are calculating the difference between peaks and subsequent troughs properly.

Script is wrong.

This is still not working. We should be able to do this in a single pass. Iterate through the daily values and track the highest level at that point in the series and then the subsequent deepest trough. Store the first difference. Continue iterating looking for a new peak and the subsequent deepest trough. Compare this value to the prior and take the largest of the two. Store this value and continue iterating.

Script from original request is generated.  Finally got back to the starting point.  What a waste of time.  I will be more careful with my suggestions.  However, the script is still wrong – arrgh!  I decide to run the debugger on the draw down function and the code is right, but the data is wrong.

The problem lies in the equity series. It should contain the combined equity for the combinations. There should be a master date and each combination populates the master date. If there is a missing date in the combinations, then the master date should copy the prior combinations combined value.

Warning message:  se obj.ffill() or obj.bfill() instead.  df_aligned = df.reindex(master_date_index).fillna(method=”ffill”).fillna(0)

Chat created some deprecated code.   This was an easy fix, I just had to replace one line of code.  However, every iteration following this still had the same damn deprecated code.

Error or warning: FutureWarning: Series.getitem treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use ser.iloc[pos] peak = equity_series[0] # Initialize the first value as the peak

Script updated.

Can we drop the “_equity_curve” from the name of the system and symbol in the Perfomance metrics file. Will excel accept the combination names as a single column or will each symbol have its own column because of the comma. I would like for each combination in the Performance_Metrics file to occupy just one column.

Script created and this is what it should look like.  Notice it was remembering the wrong maximum draw down values I fed it earlier.  Don’t worry it was right in the script.

Combination Total Profit Max Drawdown Profit-to-Drawdown Ratio Combination Number
“Andromeda-Like_@SB, Andromeda-Like_@EC” 92141.85 92985.60 0.99 1
“Andromeda-Like_@S, Andromeda-Like_@JY” 82450.55 70530.45 1.17 2

Conclusion

I could have done the same thing ChatGPT did for me, but I wouldn’t have used the Numpy or Pandas libraries simply because I’m not familiar with them. These libraries make the exhaustive search manageable and incredibly efficient. They handle tasks much faster than pure Python alone.

To get ChatGPT to generate the code you need, being a programmer is essential. You’ll need to guide it through debugging, steer it in the right direction, and test the scripts it produces. It’s a back-and-forth process—running the script, identifying warnings or errors, and pointing out incorrect outputs. Sometimes, your programming insights and suggestions might inadvertently lead ChatGPT down a rabbit hole. Features that worked in earlier versions may stop working in subsequent iterations as modifications are applied to address earlier issues.

ChatGPT can also slow down at times, and its Canvas tool has a line limit, which can result in incomplete scripts. As a programmer, it’s easy to spot these issues—you’ll need to inform ChatGPT, and it will adjust by splitting the script into parts, some appearing in the Canvas and the rest in the chat window.

The collaboration between ChatGPT and me was powerful enough to replicate, in just one day, software that Mike Chalek and I spent weeks developing a decade ago. The original version had a cleaner GUI, but it was significantly slower compared to what we’ve achieved here.

If you’re a programmer, have Python installed with its libraries, and work with ChatGPT, the possibilities are endless. But there’s no magic—success requires thoughtful feedback and precise prompting.

Email me if you would like to have the Python scripts that accomplish the following tasks.  If you are not familiar with pandas or xml processing, the code, even being Python savvy, will look a little foreign.  No worries – it just works.

  1. XML Parser – creates data, trades and equity files in .csv format.
  2. TradeStationExhaustiveCombos – creates all the combos when sampling n out of N markets.
  3. The simple Tkinter GUI and Matplotlib graphing tool to plot the combos.

There is a total of three scripts.  Remember you will need to have Python, pandas, matplotlib already installed on your computer.  If you have any questions on how to install these just let me know.

Build your Technical/Trading Library for less than $150

Great books that are dirt cheap!

These books cover a wide range of technical analysis and trading topics.  I have read and/or utilized ideas from these books for developing trading ideas and in help writing my own books.  I wanted to see what I could get for less than $13 a book.  I was pleasantly surprised at what I could get at Thriftbooks.com for this price or lower.  If you go a little higher in price, you will get some really great deals too.  Yes, these books are old, and I am sure I have left out some great names, but the bang for the buck is ridiculous.

Note – I captured the Add to Cart button in the IMAGES – IT DOES NOT WORK.  I wanted to show the various editions of each book.  Go to www.thriftbooks.com and search for the title or author and you should be able to find these books just like I did.  Also check out amazon.com

The Gallacher, Taleb, McKay, Schwager, and Livermore (Lefevre) books are fun reads that give an honest view of trading in general.  Elders’ book just needs to be any trader’s library.

The Edwards and Magee, Sklarew and Darvas books are classics.

Sunny Harris’ book is great for beginners.

The Stridsman and Rotella books are concrete methods to systematic trading.

Kaufman and McCormick/Katz are great reference books.

The Conway book has great EasyLanguage examples.

You can learn a lot from Schwager’s first book.

Learn optimization from Robert Pardo and money management from Fred Gehm’s classic.

If you go up in price a little bit, you will get Ralph Vince, Larry Williams, John Carter, Rober Carver, Andreas Clenow, and Ernie Chan.  If you are just starting out, you must have a trading library, and this would be a great start for the first shelf.

 

Should you use a profit taking algorithm in your Trend Following system?

If letting profits run is key to the success of a trend following approach, is there a way to take profit without diminishing returns?

Most trend following approaches win less than 40% of the time.   So, the big profitable trades are what saves the day for this type of trading approach.  However, it is pure pain to simply sit there and watch a large profit erode, just because the criteria to exit the trade takes many days to be met.

Three methods to take a profit on a Trend Following algorithm

  1.  Simple profit objective – take a profit at a multiple of market risk.
  2.  Trail a stop (% of ATR) after a profit level (% of ATR) is achieved.
  3. Trail a stop (Donchian Channel) after a profit level (% of ATR) is achieved.

Use an input switch to determine which exit to incorporate

Inputs: initCapital(200000),rskAmt(.02),
useMoneyManagement(False),exitLen(13),
maxTradeLoss$(2500),
// the following allows the user to pick
// which exit to use
// 1: pure profit objective
// exit1ProfATRMult allows use to select
// amount of profit in terms of ATR
// 2: trailing stop 1 - the user can choose
// the treshhold amount in terms of ATR
// to be reached before trailing begins
// 3: trailing stop 2 - the user can chose
// the threshold amount in terms of ATR
// to be reached before tailing begins
whichExit(1),
exit1ProfATRMult(3),
exit2ThreshATRMult(2),exit2TrailATRMult(1),
exit3ThreshATRMult(2),exit3ChanDays(5);
Exit switch and the parameters needed for each switch.

The switch determines which exit to use later in the code.  Using inputs to allow the user to change via the interface also allows us to use an optimizer to search for the best combination of inputs.  I used MultiCharts Portfolio Trader to optimize across a basket of 21 diverse markets.  Here are the values I used for each exit switch.

MR = Market risk was defined as 2 X avgTrueRange(15).

  • Pure profit objective -Multiple from 2 to 10 in increments of 0.25.  Take profit at entryPrice + or – Profit Multiple X MR
  • Trailing stop using MR – Profit Thresh Multiple from 2 to 4 in increments of 0.1.  Trailing Stop Multiple from 1 to 4 in increments of 0.1.
  • Trailing stop using MR and Donchian Channel – Profit Thresh Multiple from 2 to 4 in increments of 0.1.  Donchian length from 3 to 10 days.

Complete strategy code incorporating exit switch.  This code is from Michael Covel’s 2005 Trend Following book (Covel, Michael. Trend Following: How Great Traders Make Millions in Up or Down Markets. FT Press, 2005.)  This strategy is highlighted in my latest installment in my Easing into EasyLanguage series – Trend Following edition.


vars:buyLevel(0),shortLevel(0),longExit(0),shortExit(0);

Inputs: initCapital(200000),rskAmt(.02),
useMoneyManagement(False),exitLen(13),
maxTradeLoss$(2500),whichExit(1),
exit1ProfATRMult(3),
exit2ThreshATRMult(2),exit2TrailATRMult(1),
exit3ThreshATRMult(2),exit3ChanDays(5);

Vars: marketRisk(0), workingCapital(0),
marketRisk1(0),marketRisk2(0),
numContracts1(0),numContracts2(0);

//Reinvest profits? - uncomment the first line and comment out the second
//workingCapital = Portfolio_Equity-Portfolio_OpenPositionProfit;
workingCapital = initCapital;


buyLevel = highest(High,89) + minMove/priceScale;
shortLevel = lowest(Low,89) - minMove/priceScale;
longExit = lowest(Low,exitLen) - minMove/priceScale;
shortExit = highest(High,exitLen) + minMove/priceScale;

marketRisk = avgTrueRange(15)*2*BigPointValue;
marketRisk1 =(buyLevel - longExit)*BigPointValue;
marketRisk2 =(shortExit - shortLevel)*BigPointValue;
marketRisk1 = minList(marketRisk,marketRisk1);
marketRisk2 = minList(marketRisk,marketRisk2);

numContracts1 = (workingCapital * rskAmt) /marketRisk1;
numContracts2 = (workingCapital * rskAmt) /marketRisk2;

if not(useMoneyManagement) then
begin
numContracts1 = 1;
numContracts2 =1;
end;

numContracts1 = maxList(numContracts1,intPortion(numContracts1)); {Round down to the nearest whole number}
numContracts2 = MaxList(numContracts2,intPortion(numContracts1));


if c < buyLevel then buy numContracts1 contracts next bar at buyLevel stop;
if c > shortLevel then Sellshort numContracts2 contracts next bar at shortLevel stop;

buytocover next bar at shortExit stop;
Sell next bar at longExit stop;

vars: marketRiskPoints(0);
marketRiskPoints = marketRisk/bigPointValue;
if marketPosition = 1 then
begin
if whichExit = 1 then
sell("Lxit-1") next bar at entryPrice + exit1ProfATRMult * marketRiskPoints limit;
if whichExit = 2 then
if maxcontractprofit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue then
sell("Lxit-2") next bar at entryPrice + maxContractProfit/bigPointValue - exit2TrailATRMult*marketRiskPoints stop;
if whichExit = 3 then
if maxcontractprofit > (exit3ThreshATRMult * marketRiskPoints ) * bigPointValue then
sell("Lxit-3") next bar at lowest(l,exit3ChanDays) stop;
end;

if marketPosition = -1 then
begin
if whichExit = 1 then
buyToCover("Sxit-1") next bar at entryPrice - exit1ProfATRMult * marketRiskPoints limit;
if whichExit = 2 then
if maxcontractprofit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue then
buyToCover("Sxit-2") next bar at entryPrice - maxContractProfit/bigPointValue + exit2TrailATRMult*marketRiskPoints stop;
if whichExit = 3 then
if maxcontractprofit > (exit3ThreshATRMult * marketRiskPoints ) * bigPointValue then
buyToCover("Sxit-3") next bar at highest(h,exit3ChanDays) stop;
end;

setStopLoss(maxTradeLoss$);

Here’s the fun code from the complete listing.

vars: marketRiskPoints(0);
marketRiskPoints = marketRisk/bigPointValue;
if marketPosition = 1 then
begin
if whichExit = 1 then
sell("Lxit-1") next bar at entryPrice + exit1ProfATRMult * marketRiskPoints limit;
if whichExit = 2 then
if maxContractProfit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue then
sell("Lxit-2") next bar at entryPrice + maxContractProfit/bigPointValue - exit2TrailATRMult*marketRiskPoints stop;
if whichExit = 3 then
if maxContractProfit > (exit3ThreshATRMult * marketRiskPoints ) * bigPointValue then
sell("Lxit-3") next bar at lowest(l,exit3ChanDays) stop;
end;

if marketPosition = -1 then
begin
if whichExit = 1 then
buyToCover("Sxit-1") next bar at entryPrice - exit1ProfATRMult * marketRiskPoints limit;
if whichExit = 2 then
if maxContractProfit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue then
buyToCover("Sxit-2") next bar at entryPrice - maxContractProfit/bigPointValue + exit2TrailATRMult*marketRiskPoints stop;
if whichExit = 3 then
if maxContractProfit > (exit3ThreshATRMult * marketRiskPoints ) * bigPointValue then
buyToCover("Sxit-3") next bar at highest(h,exit3ChanDays) stop;
end;

The first exit is rather simple – just get out on a limit order at a nice profit level.  The second and third exit mechanisms are a little more complicated.  The key variable in the code is the maxContractProfit keyword.  This value stores the highest level, from a long side perspective, reached during the life of the trade.  If max profit exceeds the exit2ThreshATRMult, then trail the apex by exit2TrailATRMult.  Let’s take a look at the math from a long side trade.

if maxContractProfit > (exit2ThreshATRMult * marketRiskPoints ) * bigPointValue

Since maxContractProfit is in dollar you must convert the exit2ThreshATRMult X marketRiskPoints into dollars as well.  If you review the full code listing you will see that I convert the dollar value, marketRisk, into points and store the value in marketRiskPoints.  The conversion to dollars is accomplished by multiplying the product by bigPointValue.

sell("Lxit-2") next bar at
entryPrice + maxContractProfit / bigPointValue - exit2TrailATRMult * marketRiskPoints stop;

I know this looks complicated, so let’s break it down.  Once I exceed a certain profit level, I calculate a trailing stop at the entryPrice plus the apex in price during the trade (maxContractProfit / bigPointValue) minus the exit2TrailATRMult X marketRiskPoints. If the price of the market keeps rising, so will the trailing stop.  That last statement is not necessarily true, since the trailing stop is based on market volatility in terms of the ATR.  If the market rises a slight amount, and the ATR increases more dramatically, then the trailing stop could actually move down.  This might be what you want.  Give the market more room in a noisier market.  What could you do to ratchet this stop?  Mind your dollars and your points in your calculations.

The third exit uses the same profit trigger, but simply installs an exit based on a shorter term Donchian channel.  This is a trailing stop too, but it utilizes a chart point to help define the exit price.

Results of the three exits

Exit 1 – Pure Profit Objective

Take a profit on a limit order once profit reaches a multiple of market risk aka 2 X ATR(15).

Pure profit object. Profit in terms of ATR or perceived market risk.

The profit objective that proved to be the best was using a multiple of 7.  A multiple of 10 basically negates the profit objective.   With this system several profit objective multiples seemed to work.

Exit – 2 – Profit Threshold and Trailing Stop in terms of ATR or market risk

Trail a stop a multiple of ATR after a multiple of ATR in profit is reached.

Trailing Stop using ATR
3-D view of parameters
3D view of parameter pairs

This strategy liked 3 multiples of ATR of profit before trailing and applying a multiple of 1.3 ATR as a stop.

Like I said in the video, watch out for 1.3 as you trailing amount multiple as it seems to be on a mountain ridge.

Exit – 3 – Profit Threshold in terms of ATR or market risk and a Donchain Channel trailing stop

Trail a stop using a Donchian Channel after a multiple of ATR in profit is reached.  Here was a profit level is reached, incorporate a tailing stop at the lowest low or the highest high of N days back.

Using Donchian Channel as trailing stop.
3-D view of parameters
3D view of parameters for Exit 3.

Conclusion

The core strategy is just an 89-day Donchian Channel for entry and a 13-Day Donchian Channel for exit.  The existing exit is a trailing exit and after I wrote this lengthy post, I started to think that a different strategy might be more appropriate.  However, as you can see from the contour charts, using a trailing stop that is closer than a 13-day Donchian might be more productive.   From this analysis you would be led to believe the ATR based profit and exit triggers (Exit #2) is superior.  But this may not be the case for all strategies.  I will leave this up to you to decide.  Here is the benchmark performance analysis with just the core logic.

Core logic results.

If you like this type of explanation and code, make sure you check at my latest book at amazon.com.  Easing into EasyLanguage – Trend Following Edition.

Prune Your Trend Following Algorithm

Multiple trading decisions based on “logic” may not add to the bottom line

In this post, I will present a trend following system that uses four exit techniques.  These techniques are based on experience and also logic.  The problem with using multiple exit techniques is that it is difficult to see the synergy that is generated from all the moving parts.  Pruning your algorithm may help cut down on invisible redundancy and opportunities to over curve fit.  The trading strategy I will be presenting will use a very popular entry technique overlaid with trade risk compression.

Entry logic

Long:

Criteria #1:  Penetration of the closing price above an 85 day (closing prices) and 1.5X standard deviation-based Bollinger Band.

Criteria #2:  The mid-band or moving average must be increasing for the past three consecutive days.

Criteria #3: The trade risk (1.5X standard deviation) must be less than 3 X average true range for the past twenty days and also must be less than $4,500.

Risk is initially defined by the standard deviation of the market but is then compared to $4,500. If the trade risk is less than $4,500, then a trade is entered. I am allowing the market movement to define risk, but I am putting a ceiling on it if necessary.

Short:

Criteria #1:  Penetration of the closing price below an 85 day (closing prices) and 1.5X standard deviation-based Bollinger Band.

Criteria #2:  The mid-band or moving average must be decreasing for the past three consecutive days.

Criteria #3:  Same as criteria #3 on the long side

Exit Logic

Exit #1:  Like any Bollinger Band strategy, the mid band or moving average is the initial exit point.  This exit must be included in this particular strategy, because it allows exits at profitable levels and works synergistically with the entry technique.

Exit #2:  Fixed $ stop loss ($3,000)

Exit #3:  The mid-band must be decreasing for three consecutive days and today’s close must be below the entry price.

Exit #4:  Todays true range must be greater than 3X average true range for the past twenty days, and today’s close is below yesterday’s, and yesterday’s close must be below the prior days.

Here is the logic of exits #2 through exit #4.  With longer term trend following system, risk can increase quickly during a trade and capping the maximum loss to $3,000 can help in extreme situations.  If the mid-band starts to move down for three consecutive days and the trade is underwater, then the trade probably should be aborted.  If you have a very wide bar and the market has closed twice against the trade, there is a good chance the trade should be aborted.

Short exits use the same logic but in reverse.  The close must close below the midband, or a $3,000 maximum loss, or three bars where each moving average is greater than the one before, or a wide bar and two consecutive up closes.

Here is the logic in PowerLanguage/EasyLanguage that includes the which exit seletor.

[LegacyColorValue = true]; 
Inputs: maxEntryRisk$(4500),maxNATRLossMult(3),maxTradeLoss$(3000),
indicLen(85),numStdDevs(1.5),highVolMult(3),whichExit(7);

Vars: upperBand(0), lowerBand(0),slopeUp(False),slopeDn(False),
largeAtr(0),sma(0),
initialRisk(0),tradeRisk(0),
longLoss(0),shortLoss(0),permString("");

upperBand = bollingerBand(close,indicLen,numStdDevs);
lowerBand = bollingerBand(close,indicLen,-numStdDevs);
largeATR = highVolMult*(AvgTrueRange(20));

sma = average(close,indicLen);

slopeUp = sma>sma[1] and sma[1]>sma[2] and sma[2]>sma[3];
slopeDn = sma<sma[1] and sma[1]<sma[2] and sma[2]<sma[3];

initialRisk = AvgTrueRange(20);
largeATR = highVolMult * initialRisk;
tradeRisk = (upperBand - sma);
// 3 objects in our permutations
// exit 1, exit 2, exit 3
// perm # exit #
// 1 1
// 2 1,2
// 3 1,3
// 4 2
// 5 2,3
// 6 3
// 7 1,2,3

if whichExit = 1 then permString = "1";
if whichExit = 2 then permString = "1,2";
if whichExit = 3 then permString = "1,3";
if whichExit = 4 then permString = "2";
if whichExit = 5 then permString = "2,3";
if whichExit = 6 then permString = "3";
if whichExit = 7 then permString = "1,2,3";



{Long Entry:}
If (MarketPosition = 0) and
Close crosses above upperBand and slopeUp and
(tradeRisk < initialRisk*maxNATRLossMult and tradeRisk<maxEntryRisk$/bigPointValue) then
begin
Buy ("LE") Next Bar at Market;
End;


{Short Entry:}

If (MarketPosition = 0) and slopeDn and
Close crosses below lowerBand and
(tradeRisk < initialRisk*maxNATRLossMult and tradeRisk<maxEntryRisk$/bigPointValue) then
begin
Sell Short ("SE") Next Bar at Market;
End;


{Long Exits:}

if marketPosition = 1 Then
Begin
longLoss = initialRisk * maxNATRLossMult;
longLoss = minList(longLoss,maxTradeLoss$/bigPointValue);

If Close < sma then
Sell ("LX Stop") Next Bar at Market;;

if inStr(permString,"1") > 0 then
sell("LX MaxL") next bar at entryPrice - longLoss stop;

if inStr(permString,"2") > 0 then
If sma < sma[1] and sma[1] < sma[2] and sma[2] < sma[3] and close < entryPrice then
Sell ("LX MA") Next Bar at Market;
if inStr(permString,"3") > 0 then
If TrueRange > largeATR and close < close[1] and close[1] < close[2] then
Sell ("LX ATR") Next Bar at Market;
end;

{Short Exit:}

If (MarketPosition = -1) Then
Begin

shortLoss = initialRisk * maxNATRLossMult;
shortLoss = minList(shortLoss,maxTradeLoss$/bigPointValue);
if Close > sma then
Buy to Cover ("SX Stop") Next Bar at Market;

if inStr(permString,"1") > 0 then
buyToCover("SX MaxL") next bar at entryPrice + shortLoss stop;

if inStr(permString,"2") > 0 then
If sma > sma[1] and sma[1] > sma[2] and sma[2] > sma[3] and close > entryPrice then
Buy to Cover ("SX MA") Next Bar at Market;
if inStr(permString,"3") > 0 then
If TrueRange > largeAtr and close > close[1] and close[1] > close[2] then
Buy to Cover ("SX ATR") Next Bar at Market;
end;
Trend following with exit selector

Please note that I modified the code from my original by forcing the close to cross above or below the Bollinger Bands.  There is a slight chance that one of the exits could get you out of a trade outside of the bands, and this could potentially cause and automatic re-entry in the same direction at the same price.  Forcing a crossing, makes sure the market is currently within the bands’ boundaries.

This code has an input that will allow the user to select which combination of exits to use.

Since we have three exits, and we want to evaluate all the combinations of each exit separately, taken two of the exits and finally all the exits, we will need to rely on a combinatorial table.    In long form, here are the combinations:

3 objects in our combinations of exit 1, exit 2, exit 3

  • one  – 1
  • two  – 1,2
  • three  –  1,3
  • four –  2
  • five  – 2,3
  • six –  3
  • seven  –  1,2,3

There are a total of seven different combinations. Given the small set, we can effectively hard-code this using string manipulation to create a combinatorial table. For larger sets, you may find my post on the Pattern Smasher beneficial. A robust programming language like Easy/PowerLanguage offers extensive libraries for string manipulation. The inStr string function, for instance, identifies the starting position of a substring within a larger string. When keyed to the whichExit input, I can dynamically recreate the various combinations using string values.

  1. if whichExit = 1 then permString = “1”
  2. if whichExit = 2 then permString= “1,2”
  3. if whichExit = 3 then permString = “1,2,3”
  4.  etc…

As I optimize from one to seven, permString will dynamically change its value, representing different rows in the table. For my exit logic, I simply check if the enumerated string value corresponding to each exit is present within the string.

	if inStr(permString,"1") > 0 then
sell("LX MaxL") next bar at entryPrice - longLoss stop;
if inStr(permString,"2") > 0 then
If sma < sma[1] and sma[1] < sma[2] and sma[2] < sma[3] and close < entryPrice then
Sell ("LX MA") Next Bar at Market;
if inStr(permString,"3") > 0 then
If TrueRange > largeATR and close < close[1] and close[1] < close[2] then
Sell ("LX ATR") Next Bar at Market;
Using inStr to see if the current whichExit input applies

When permString = “1,2,3” then all exits are used.  If permString = “1,2”, then only the first two exits are utilized.  Now all we need to do is optimize whichExit from 1 to 7.  Let’s see what happens:

Combination of all three exits

The best combination of exits was “3”.  Remember 3 is the permString  that = “1,3” – this combination includes the money management loss exit, and the wide bar against position exit.  It only slightly improved overall profitability instead of using all the exits – combo #7.  In reality, just using the max loss stop wouldn’t be a bad way to go either.  Occam uses his razor to shave away unnecessary complexities again!

If you like this code, you should check out the Summer Special at my digital store. I showcase over ten more trend-following algorithms with different entry and exit logic constructs.  These other algorithms are derived from the best Trend Following “Masters” of the twentieth century.  IMHO!

Here is a video you can watch that goes over the core of this trading strategy.

 

Is your Big Point Value right?

Thinking of using futures data from a vendor such as CSI, Pinnacle, Norgate…?

You would be surprised how many quants still use Excel or they own homegrown back-testing software.  Determining trade execution is simple.  On a stop order, all you need to do is see if today’s bar is higher than the prior bars calculated trade signal – right.  And if it is then a buy stop order is executed and the calculated signal price.  Store the entry price and when the exit occurs do the math to calculate the profit or loss.  Before you can do this, you must know two very important contract specs on the futures data you are testing:

  1. big point value – I will explain how to calculate this a little later
  2. minimum tick move

That’s it.  You don’t need to know anything beyond this to properly calculate trade signals and trade P and L.  As long as you store this information for each futures/commodity market you are testing, then you will be good to go.  Many testing platforms store more information such as contract size, trading hours, expiration date and several other contract specs.  You don’t need to know this information if you all you are interested is proper signal placement and accurate trade accounting.  Once you set the big point value and minimum tick move you are good to go, right?  Yes, if you stick with the same data vendor.  I kid you not.  Data vendors often quote the same exact market with different decimal places.  If you look up a sugar quote at the CME website, you will see it quoted like 0.1908.  If you look it up on TradeStation it is quoted as 19.08.  It’s the same size contract 112,000 pounds, but if you use the big point value at the CME, it will not produce accurate calculations on the TradeStation quote.  You can’t use the contract size of 112,000 pounds to help with the math either.  You have to delve into how each data vendor quotes their data and this will impact the big point move and minimum tick move.  Most vendors are gracious enough to provide a futures dictionary with these specs.  But it is wise to know how to do this by hand as well.

If you had to take a test, could you calculate the profit or loss from a trade in soybeans, in sugar or in euro currency?

Are you kidding me this is super simple.  Just program the strategy in TradeStation or Amibroker or Multicharts or TradingSimula-18.  I took the NFA Series 3 test more than two decades ago, and this type of question was on the test.  The following information was given:

  • contract size – 5000 bushels
  • minimum tick or move – 1/4th of a cent or penny
  • long entry price 8.32’2 and sell exit price 8.48’6 (per bushel)

The entry and exit price may look a little funny.  The entry price is eight dollars and 32 1/4 cents.   Many still quote soybeans in 1/8ths.  So, 2 X 1/8th = 1/4th.  For fun let’s calculate the notional value of the entry and exit prices.  The notional value of a soybean contract at the entry price is $8.3225 * 5000 = $41,612.50.  As you know futures are highly leveraged and you can control this quantity of soybeans for a small percentage of the notional value (margin.)  Now the exit price is $8.4875 (6*1/8th = 3/4th of a cent) and the notional value of the contract at exit is $8.4875 * 5000 = $42,437.5.  The result of the trade was $42,437.50 – $41,612.50 = $825.  Or you could simply multiple the difference between entry and exit by 5000.  This would $0.165 * 5000.  This makes perfect sense, but as a broker it was difficult to keep the contract size of a market and its minimum tick move in your memory.  Well, if you did it long enough it wasn’t that difficult.  You can reduce the math down to one easy to remember value and quickly do the math in your head.  The concept of the big point move allows for this.  If you download your data from Pinnacle or CSI the price of soybeans is usually quoted like this:  848.75.  This would be eight hundred and 48.75 cents.  The big point move is the amount of dollars required to lift (or drop) the first digit to the left of the decimal by one.  The first digit to the left of the decimal in beans is a penny or one cent.  A one cent move in beans is 5000 * $0.01 or $50.  Going back to our trade example 848.75 – 832.25 = 16.5 – multiply this by $50 you get $825.  You can also derive the minimum move dollar value too.  If the minimum move is 1/4th of a cent, then you can multiply 5000 * $.0025 and this yields $12.5.

Why is this important to know?

You should know this if you are trading the market, period.  Also, if you are a quant and are using some back testing software that requires you to set up the database outside the purview of the back-tester, then these values must be known, and must also be accurate.  Since TradeStation integrates its own data, you don’t have to worry about this.  But if you want to use a database from Pinnacle, BarChart, CSI or Norgate, then you have to take the time to set this up, right off the bat.  I feel like the leading data vendors, provide accurate data.  But there are differences from one vendor to another.  Not all data vendors use the same number of decimal places in their market quotes, so you must be able to determine the big point value and minimum move from the data.   You can do all the math to determine profit and loss from the big point value.  Here is a snapshot of a few markets in the TS-18 dataMasterPinnacle and the TS-18 dataMasterCSI text files. Like I said, all vendors will provide this information for you, so you can set your database properly.  Some back-testing platforms require more contract specs, but TS-18 just needs this information to carry out accurate calculations.  Here TS-18 wants to know the symbol, big point value, minimum tick move, and market name.

Pinnacle Data
AN,1000,0.01,Aus.Dol
ZL,600,0.01,BeanOil
BN,625,0.01,B.Pound
ZU,1000,0.01,Crude
ZC,50,0.25,Corn
CC,10,1,Cocoa
CL,1000,0.01,Crude
CN,1000,0.01,Can.Dol
CT,500,0.01,Cotton
FN,1250,0.005,EuroCur


CSI Data
AD,100000,0.0001,Aus.Dol
BO,600,0.01,BeanOil
BP,62500,0.0001,B.Pound
CL,1000,0.01,Crude
C2,50,0.25,Corn
C_,50,0.25,Corn
CC,10,1,Cocoa
CD,100000,0.0001,Can.Dol
CL,1000,0.01,Crude
CT,500,0.01,Cotton
CU,125000,0.00005,EuroCur
EC,125000,0.00005,EuroCur

Other than the symbol names the values for each symbol are very similar.  Most data vendors, including CSI quote the Euro currency like this:

1.08735 and a move to 1.08740 = 0.00005 *$125,000 = $6.25

But Pinnacle data quotes it like this:

108.735 and a move to 108.740 = 0.005 * $1,250 = $6.25

The size of the contract isn’t different here.  It is the quote that is different.  The big point value is tied to the contract size and the format of the quote.  This is why knowing the big point value is so important.  If you don’t set up the contract specifications correctly, then you will receive inaccurate results.

One more test in sugar – from the CME website

  • contract size – 112,000 pounds
  • minimum tick or move – $0.0001
  • long entry price $0.1910 and sell exit price $0.1980 (per pound)
  • big point value = $112,000
  • $0.0070 * 112,000 = $784

From TradeStation

  • contract size – 112,000 pounds
  • minimum tick or move – $0.01
  • long entry price $19.10 and sell exit price $19.80 (per pound??)
  • big point value = $1,120
  • $0.70 * 1,120 = $784

Most fractional quotes are delivered in decimal format and the also very important minimum tick move.

The interest rate futures have minimum tick moves ranging from 1/256ths to 1/32nds.  Most vendors will give you a quote like 120.03125 for the bonds.  If you test in TradersStudio or Excel or any other platform where the data is not integrated and are using CSI (or any other vendor), then you must force your calculated prices to fall on an even tick.  Assume you do a calculation to buy a bond future at 120.022365895.  If you don’t take the minimum tick move into considerations, you might be filled at this theoretical price.  In reality you should be filled on an even tick at 120.03125.  This is worse but realistic fill. You could create what you think is a really awesome strategy where you are shaving off the price on every trade – getting a better fill on every trade.

Thinking of purchasing and using back-testing software or Excel and data from a data vendor?

Become your own quant and do this.  You will learn a lot about algorithm testing and development.  But first things first.  Get your database set up according to your data vendor.  Once this chore is complete, testing becomes smooth sailing.  I provide the databases for Pinnacle and CSI with TS-18. Other software provides these as well, and a way to create your own databases.

Check out my interview in Traders’ Magazine [Germany]

INTERVIEW WITH THE GERMANY BASED TRADERS´ Magazine 05.2024 (May 2024 Issue)

traders-mag.com

Note from George – Original text was written in German.  The text below is translated without modification.

George Pruitt was Director of Research at Futures Truth for 30 years.

During this time he checked the performance of more than 1000 trading strategies that were commercially available. He had contact with many prominent people in the algorithmic trading industry. He has also advised domestic and foreign customers and published a total of eight books. We talk to George Pruitt about his experiences during more than three decades of trading system development.

Traders’ media Gmbh – Eisenbahnstraße 53
97084 Würzbug

info@traders-mag.com

TRADERS´: YOU BEGAN WORKING FOR FUTURES TRUTH IN 1989, WHILE YOU WERE STUDENT. HOW DID THAT HAPPEN?

Pruitt: I was in my final year of college and looking for an internship. I saw an ad for Futures Truth in the newspaper. They were looking for a part-time programmer. After the interview with founder John Hill and programmer John Fisher, I got the job.

TRADERS´: FUTURES TRUTH HAS BEEN AN INSTITUTION IN THE INDUSTRY FOR A LONG TIME. WHAT DID THE PROVIDERS OF TRADING STRATEGIES THINK ABOUT THE PERFORMANCE OF THEIR APPROACHES BEING SUBJECT TO EXTERNAL VALIDATION AND THEREFORE MADE TRANSPARENT?

Pruitt: Many system providers used the results published in the magazine as a springboard to become leaders in the heyday of the trading systems industry.

Other providers were not so happy about their results being made available to the public. Particularly in the early days of system trading, only a few traders had the computing power, data or software to check the claims about the strategies made in the providers’ advertisements. Sometimes the results shown were not accurate at all. Futures Truth used a rigorous backtesting methodology, using tick data when necessary to create authentic track records. These sometimes contradicted the advertising material of the providers, who were of course not that enthusiastic about them.

TRADERS: WHAT SURPRISED YOU THE MOST WHILE TESTING ALL THESE STRATEGIES OVER THE YEARS?

Pruitt: I was surprised that some very expensive trading systems were not worth the price the customer paid for them. In fact, price had very little to do with success. One reason for this was that many strategy providers were not traders in the true sense, but rather engineers or scientists.

TRADERS’: IN THE 1990’S YOU TESTIFIED TO YOUR FEDERAL GOVERNMENT ON THE SUBJECT OF ALGORITHMIC TRADING. WHAT WAS IT ABOUT THEN?

Pruitt: In this particular case, I was asked to essentially answer the following question: “Can an algo that has low trading success have periods of success – and could it in the future-be more successful at all?” Of course, any trading system, good or bad, can have profit and loss margins. However, in my experience at the time, an algo with a negative expected value usually didn’t last long after a winning streak.

TRADERS: YOU SAID “ACCORDING TO MY EXPERIENCE AT THE TIME”. HAS YOUR OPINION LATER CHANGED?

Pruitt: Back then, markets were relatively inefficient. One might expect a solid backtest to be pretty indicative of future performance. In the meantime, however, the markets have evolved. Don’t get me wrong: all we can lean on is the backtest, and it will always stay that way. But I don’t think it’s as meaningful today as it was in the 1990s.

TRADERS: DO YOU REMEMBER A SUPERIOR SYSTEM THAT GOT INTO TROUBLE?

Pruitt: One example was Keith Fitschen and his “aberration” system. It was a breakout system based on Bollinger bands with a period length of 80 days and two standard deviations. The exit was at the moving average (middle band). In my opinion, it was one of the most successful trading systems of all time. From 2010 to 2020, however, the strategy went through a difficult phase. Keith believed that markets have become much more efficient. With his “Paradigm Shift” system, he basically turned the trading rules around, although not exactly. This resulted in it having a really poor performance in the backtest, but succeeding after that. But only temporarily. The success of the reverse approach did not last.

The graphic shows a comparison of Keith Fitschen’s original aberration system and his practically reversed paradigm shift strategy, each applied to crude oil. For a while, it seemed like the market had undergone a paradigm shift. But then the new strategy also disappointed.

This is what the capital curve of a typical trend-following strategy looks like across a portfolio of different futures contracts. There were big movements in 2008, 2010 and 2014. After that, it became more difficult

TRADERS: YOU ARE AN EXPERT IN THE DEVELOPMENT OF TRADING SYSTEMS. WHAT ABOUT YOUR PERSONAL TRADING?

I was two years into working at Futures Truth. It took this long to complete the CompuTrac-M conversion. Futures Truth was started by John Hill who also owned Hill Financial Group and Commodity Research. At this time the managed futures business was booming and I was asked to sit for the Series 3 exam and to help start trading Fisher and Hills algorithms. John Hill, in my opinion, was the greatest market technician of his time. He had several books on bar patterns and he exposed me to discretionary trading. I couldn’t see the same things he did on a chart. However, Fisher had canned many of John’s concepts and programmed them into Fortran. I am a programmer and a computer scientist first and foremost and could see how the ideas, expressed by code, could work and they did for many years. I am an algorithmic trader and will always be one. I never traded futures for my personal accounts due to the conflict of interests. I spend most of my time trading stocks and working on my first love – programming.

TRADERS: WHAT WAS IT LIKE BACK THEN? YOUR APPROACH TO STOCK TRADING?

Pruitt: It was the dot-com era. We simply bought everything and sold it again a little later, which had a certain dynamism. In doing so, we also saw the signs of the times and held back a lot before the end of the bubble.

Shown is the capital curve of a short-term mean reversion strategy on the Nasdaq E-mini future. It buys pullbacks and trades in the direction of the long-term moving average. However, the drawdowns can be significant. For example, there was a 30 percent setback from trade 98 to 107.

TRADERS: YOU LED THE BACK-OFFICE TEAM OF A $180 MILLION HEDGE FUND IN THE 1990S AND DEVELOPED THE CORE ALGORITHMS OF ANOTHER HEDGE FUND IN THE 2000S. HOW DID YOU MANAGE THE GREAT SUCCESS AND LATER DISILLUSIONMENT WITH TREND-FOLLOWING STRATEGIES?

Pruitt: In the early 2000s, trend-following strategies became more and more popular. Back then, the managers of funds of funds didn’t even look at you if you were trading discretionarily, with options or anything else to follow trends. I, too, had included trend following in our programs and had some success with it. But at some point the zenith was passed. After the last major movements in raw materials and the stock market in the early 2010s, many hedge funds and commodity trading advisors (CTAs) had to give up. A two-percent fixed fee and a 20 percent performance fee are great when you’re making money, but it’s very hard when you’re not. The High Watermark became an obstacle that was difficult to overcome. At the same time, small hedge funds and CTAs in particular had to spend far too much money in relative terms to comply with the now stricter regulations.

TRADERS: NEVERTHELESS, TREND FOLLOWING IS STILL ONE OF THE MOST WELL-KNOWN TRADING STRATEGIES TODAY. WHY IS THAT?

Pruitt: For one thing, timing isn’t that important. And on the other hand, you do what the commandments of trading tell us: be selective when you enter, let the profits run, give the market room to its noise, and limit the losses. Most markets lend themselves well to trend following. And many of these systems have few parameters, so that over-optimization is hardly possible. This is also important.

TRADERS: WHAT DOES YOUR OWN TRADING APPROACH LOOK LIKE TODAY?

Pruitt: I trade a small portfolio of stocks on the daily chart. In doing so, I rely on both breakouts and mean reversion. I overlay levels on a 5-minute chart using Camarilla pivot points, for example, in order to systematically find entry levels. I derive the corresponding levels from the daily chart. The decisive factors here are indications that speak for a breakout or even a countercyclical trade. In these places, the risk can also be kept low. I also rely on the pyramiding of positions. However, my portfolio only contains stocks that I know and that I would hold for the long term.

TRADERS: IT IS SAID THAT AMONG DISCRETIONARY TRADERS ARE BOTH THE BEST AND THE WORST OF ALL. HOW MANY SUCCESSFUL DISCRETIONARY TRADERS THERE ARE IN THEIR EXPERIENCE?

Pruitt: Discretionary traders make a lot of money – but also lose it. For me, that’s not the way to go. I’ve met a lot of discretionary traders. But not many have been successful in the long run. Most eventually turn to algorithms – either as complete trading systems or as tools.

TRADERS: IT IS ALSO SAID THAT DISCRETIONARY TRADERS ALSO FOLLOW A SYSTEM. THE ONLY DIFFERENCE IS THAT THEY HAVE NOT YET SUFFICIENTLY SPECIFIED THEIR (UNCONSCIOUS) RULES. WOULD YOU AGREE WITH THAT?

Pruitt: Absolutely. We have a pattern in our head that we follow. You can’t just trade based on a gut feeling and be successful with it.

TRADERS: SYSTEMATIC TRADING HAS, BUT THERE ARE ALSO DOWNSIDES. WHAT ARE THEY?

Pruitt: It’s very challenging in a number of ways. Of course, if you’re winning non-stop with a system, it’s great. But what if ten losses occur in a row? At this point, at the latest, you start to doubt. To a certain extent, you have to enter the market with a blunt instrument and hope that your diligence in system development will pay off in the end. Remember, no matter what type of trader you are, your worst drawdown is yet to come. That’s why I believe that a multi-strategy approach works best. The hope, of course, is that diversification will improve earnings. In the end we were trading five different systems on almost the same portfolio.

TRADERS: THE MARKETS ARE CONSTANTLY CHANGING. IN 2001 YOU WROTE ABOUT IT, WHICH, FROM THEIR POINT OF VIEW, ARE THE BEST SYSTEMS FOR SHORT-TERM TRADING. HOW HAS THIS DEVELOPED OVER THE LAST TWO DECADES?

Pruitt: The best short-term swing systems in 2001 were based on breaking out of the opening range. The traders made a lot of money with this very simple approach. Toby Crabel wrote one of the best books about it. With the disappearance of the pits, the opening range was diluted. That said, I believe it still works for stocks and stock indices. Together with system developer Murray Ruggiero, we developed the Dynamic Open approach. The opening of the trading day is not based on time, but on a constant increase in volume. This also worked for a while, but unfortunately not permanently. Currently, the best short-term systems are based on mean reversion approaches.

TRADERS: CAN YOU GIVE US AN EXAMPLE?

Pruitt: You can use short-term Bollinger Bands, the Relative Strength Index, or anything else that shows a move away from the average. Buying pullbacks can be difficult because you don’t know where to end up in the downcycle.

 

TRADERS: SPEAKING OF MARKETS THAT CHANGE OVER TIME, HOW LONG DO YOU THINK IS THE IDEAL PERIOD FOR BACKTESTING?

Pruitt: The markets have undergone a change in strategy. It used to be that the more data, the better. But now I think that old data is affecting the validity of the results. A test period of ten to 15 years is more than sufficient these days.

TRADERS: ONE OF THE CHALLENGES OF BACKTESTING IS TO HAVE ENOUGH HIGH-QUALITY DATA IN THE FIRST PLACE. WHAT DO YOU WORK WITH? IS IT POSSIBLE TO ACHIEVE GOOD RESULTS EVEN WITH FREE DATA?

TO ACHIEVE THE BEST POSSIBLE RESULTS?

Pruitt: You can work with free data. This means that a positive expected value can be derived from it. But I would never trade it. Yahoo Finance and Quandl offer some free data, and good daily data is also relatively cheap. I’m using Pinnacle Data for commodities. They are very reasonably priced and very good. The same goes for CSI Data. I also test with Trade Station and their data. The integration of data, testing and trading in one package like TradeStation or MultiCharts is the main reason why I wrote my book series on EasyLanguage. Despite its limitations, it is probably the best programming language for beginners.

This capital curve looks too good to be true. That’s why caution is advised when it comes to data mining. However, it can also be the birth of a trading idea – used consciously – by optimizing all possible entry points and holding periods. Every once in a while, you’ll find something that works and can withstand rigorous testing.

TRADERS ́: WHAT ABOUT THE OLD IDEA OF DEVELOPING THE WORST POSSIBLE TRADING STRATEGY AND THEN JUST TRADING THE OPPOSITE?

Pruitt: That can work. You need to keep an eye on the average trade metric. If it’s high (big avgerage loss), why not? Often, bad systems are the ones that can’t cover their trading costs, and that’s a function of trade frequency. So a bad system that trades too much will always be a bad system.

TRADERS ́: WHAT INDICATORS WERE YOUR FAVORITES OVER THE YEARS?

Pruitt: I like Bollinger Bands, Keltner Channels, Moving Averages, and the MACD. Through Murray Ruggiero, I was introduced to John Ehlers’ indicators such as the Laguerre RSI and the Dominant Cycle. RSI and stochastic are good for the entry point, but not necessarily for making the entry decision.

TRADERS: DAY TRADING STRATEGIES ARE VERY POPULAR. HOWEVER, MANY PEOPLE UNDERESTIMATE HOW DIFFICULT IT IS TO EARN MONEY IN THE LONG RUN. WHAT ARE THE BIGGEST CHALLENGES?

Pruitt: Day trading can be successful, but you can’t trade too many times a day, and you can’t trade every day. The algorithms need appropriate filter rules. However, it’s hard for many traders to skip a day if they’re day traders. You have to wait for a setup. Waiting is perhaps the hardest part.

TRADERS: DO YOU HAVE ANY TIPS FOR DAY TRADERS THAT CAN BE USED TO IMPROVE RESULTS?

Pruitt: Identify support and resistance levels and trade around those levels. Be selective about which trades you make and don’t trade more than three times a day. In addition, filters should be developed to avoid bad trades in the first place.

TRADERS: WHAT ARE THE ANOMALIES IN RETURNS? THAT STILL EXIST TODAY?

Pruitt: There are still patterns in the market. They are a reflection of human nature. And there are persistent anomalies that can be detected with data mining tools. One example is the turn-of-the-month strategy. For day traders, there are specific times on the trading day that are suitable for long or short trades.

And the aforementioned open range breakout, which I still believe in, as well as the trade in the opposite direction in case the initial setup fails.

TRADERS: NO STRATEGY ALWAYS YIELDS PROFITS. THAT’S WHY SYSTEMATIC TRADERS NEED DIFFERENT APPROACHES THAT COMPLEMENT EACH OTHER. CAN YOU SHOW US A COMBINATION TO START WITH?

Pruitt: I would combine a trend-following approach with mean reversion and day trading. The trend-following portfolio should be the largest.

Mean Reversion only works in a handful of markets, and you should test this to see which markets are in this mode. When day trading, you should stick to markets with high volume and high volatility. As a rule, these are stocks and stock indices.

TRADERS: ONE CONTROVERSIAL ELEMENT OF STRATEGY DEVELOPMENT IS OPTIMIZATION. HOW MUCH DO YOU THINK SHOULD BE OPTIMIZED?

AND WITH WHAT APPROACH?

Pruitt: At the end of the day, all system developers are optimizing. A common question is whether you should use different parameters for different markets. When I was still working with managed futures, we didn’t allow for different parameters for different markets. We programmed concepts that were functions of the market, such as the Average True Range (ATR).

However, I believe that different parameters can work as long as you don’t overdo it, for example by optimizing individual parameters over too large a space. Data mining using genetic optimization can also be useful. On the other hand, I don’t believe in walk-forward optimization. This means that you are always behind the curve.

TRADERS: ONE METHOD OF OPTIMIZATION IS TO FILTER OUT THE LESS ATTRACTIVE SIGNALS WITHOUT COMPROMISING THE GOOD ONES. IS IT POSSIBLE TO IMPLEMENT THIS CONSCIENTIOUSLY?

Pruitt: Often, losing signals go hand in hand with a certain type of market behavior. In this case, filtering is the best approach to improve.

Let’s take a day trading system that trades every day but makes a loss overall. If you add that it only trades after days with a tight trading range, the performance of the system often increases.

TRADERS: YOU HAVE EXTENSIVE PROGRAMMING SKILLS IN DIFFERENT LANGUAGES. WHICH OF THEM ARE FOR YOU TODAY

MOST USEFUL?

Pruitt: Definitely Python and EasyLanguage. The latter is more or less identical to PowerLanguage from MultiCharts. Most trading strategies can be programmed in EasyLanguage to test and generate signals. Python allows you to test ideas outside of EasyLanguage, mainly because of the data limitations and access to academic libraries.

TRADERS: TODAY, ARTIFICIAL INTELLIGENCE (AI) IS ON EVERYONE’S LIPS. YOU HAVE ALREADY DEALT WITH SIMILAR IDEAS A FEW YEARS AGO.

IN WHICH AREAS CAN AI HELP?

Pruitt: We were already working with AI in the 1990s. She can help the trader develop the code and explain the huge library of indicators. Genetic optimization is helpful to some extent. As far as machine learning goes, I haven’t had any personal experience, but I’ve seen some disappointing results.

TRADERS: WITH YOUR KNOWLEDGE OF MORE THAN 1000 DIFFERENT ALGORITHMS, YOUR PROGRAMMING SKILLS AND ALL THE DATA AT YOUR DISPOSAL, DO YOU HAVE THE HOLY GRAIL FOUND?

Pruitt: In quantum circles, I was known as a “bubble brusher.” Often, developers and traders tested with table calculations and didn’t realize that they were cheating by unconsciously using future information. It’s easy to do. For example, you make the decision to trade at the open, but you accidentally use the daily close in your calculations for the signal. Most test platforms nowadays prevent such leaks, in the case of EasyLanguage, for example, through the “next bar” paradigm. However, if you have multiple signals that can be triggered on the same day, it is difficult to determine which one actually took place from a back testing perspective. In other words, during the back test if you need to know which long position was initiated from the various potential trade signals, the next bar paradigm makes it difficult to ascertain this.

TRADERS’: BASED ON YOUR DECADES OF EXPERIENCE, WHAT DO YOU RECOMMEND THAT ASPIRING TRADERS SHOULD START WITH?

Pruitt: John Hill’s most famous saying was, “Trading is the hardest way to make easy money!” Those of us who were able to act in the 1980s, 1990s, and a few years after were gifted. Arbitrage opportunities abounded at the time. John often said that trading bonds in those days was as easy as shooting fish in an aquarium. Today, on the other hand, it is very difficult to trade successfully. We have better instruments, but the market is more efficient. Countless market participants, access to data and fast computers have robbed us of easy profit opportunities. I would definitely recommend using an algorithm, and not trading too frequently. Don’t worry about every little movement in the market. Sooner or later, a bigger one will inevitably come. And be prepared to change your preconceived notions. Don’t try to force anything.

Infobox: Toby Crabel

Toby Crabel is a successful tennis player, US futures trader and fund manager at the hedge fund Crabel Capital Management, which he founded. In 1990, he published the book "Day Trading With Short Term Price Patterns and Opening Range Breakout", which is now considered a collector's item. On Amazon, more than 500 euros are called up, on the US site even over 1000 US dollars.

Source: Wikipedia

Infobox: Pivot-Punk Clique

Camarilla pivot points are a modified version of the classic pivot points. Introduced in 1989 by Nick Scott, a successful bond trader, they indicate potential intraday support and resistance levels. Similar to classic pivot points, they use the previous day's high, low, and close. However, Fibonacci numbers are used in the calculation of levels.

What: https://www.babypips.com