Test results: 4 different entries + Random Exits

Discussions about the testing and simulation of mechanical trading systems using historical data and other methods. Trading Blox Customers should post Trading Blox specific questions in the Customer Support forum.
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Test results: 4 different entries + Random Exits

Post by sluggo »

Van Tharp's book Trade Your Way to Financial Freedom discusses a system with random entries + good exits. I decided to explore the reverse: good entries + random exits. My hypothesis is that some entry signals are so good that they can generate profits even when used with random exits, even after commissions and slippage.

I tested the Random Exit systems the same way Van Tharp tested his Random Entry system: using $100 per contract for round-turn commissions+slippage, and using a portfolio of 10 futures markets. He ran his tests for the most recent ten years (i.e. 1981 to 1991), and so did I: from March 1997 to March 2007.

I decided to implement a particularly ugly form of Random Exits: once a trade has been entered, generate a random number "R" uniformly distributed between 1 and 30. Hold this trade exactly "R" bars and then exit on the close. (Each trade generates a new random number R and so each trade is held for a different, random, number of bars.) This is the ugly part: the short hold-time, 1-30 bars. Most trendfollowing systems hold onto trades, particularly winning trades, up to 100 or 200 bars; by restricting my test to 1-30 bar hold times, I'm applying additional stress. Roughly speaking, it takes more than 10 or 15 bars of hold time to get the average profit per trade above the commission and slippage costs ($100/contract). But I'm forcing random hold times as small as 1-2 bars. Ouch! Losing trades are cut short, and so are winning trades; both pay $100/contract commission and slippage. c.f. tested random exits having a random hold-time between 20 and 150 bars; nickmar chose a random hold-time between 20 and 200 bars. I'm sticking with the "ugly" choice of 1-30 bars, because it's a worst case test; if entry signals can make profits with these terribly punishing exits, then the benefits of good entries are demonstrated even more strongly.

First, to get a baseline, I tested Random Entries + Random Exits. Once a trade is entered, the Random Exit generates a new random number R1 and holds that trade for R1 bars, then it exits on the close. (R1 is uniformly distributed between 1 and 30 bars). After a trade exit, the Random Entry generates a new random number R2, stays out of the market (waits) for R2 bars, and then enters in a random direction (long or short) at the market price. The random wait time before new entry, R2, is between 1 and 30 bars, uniformly distributed. The system was coded into Blox and a picture of its parameter settings is shown below.

The figure called "Result1" shows the Random Entry + Random Exit system in action. Fifty different runs of this system are overlaid on the same graph, the better to visualize the min, typical, and max performance. 48 of the 50 runs lost money, and the median run (25th best out of 50) had a Compound Annual Growth Rate of -8.4 percent per year. We can think of -8.4%/yr as the Frictional Cost of commissions and slippage. Since random trading has no systematic advantage ("edge"), the expected result is breakeven, minus commissions and slippage. From this figure we see that an entry signal needs to have an "edge" of at least +8.4%/year, just to overcome C&S and achieve breakeven.

"Result2" shows another system, this time using the "ADX Burst" entry signal from Tushar Chande's book Beyond Technical Analysis. The idea behind ADX Burst is quite simple: When it appears that the trend has accelerated very quickly, jump aboard! Chande defines "a quick acceleration of trend" to be a very large one-day jump in the ADX indicator. Since ADX only measures strength of trend but not direction, Chande uses 2 moving averages to tell whether a long or a short entry is warranted. In pseudocode,

Code: Select all

if( today's ADX(18days) > (1.0 + yesterday's ADX(18days))), AND
if( EMA(4days) > EMA(16days) ), THEN Enter a Long Position
An "ADX Burst" has occurred, if today's ADX is more than 1.0 larger than yesterday's ADX.

The ADX Burst entry is profitable enough to overcome Commissions and Slippage, even with Random Exits. 42 of the 50 runs were profitable, and the Median run (25th best out of 50) had a Compound Annual Growth Rate of +3.1% per year, including the effects of slippage and commissions. It's no great surprise that the ADX Burst entry signal handily beats Random Entries: median CAGR= +3.1% versus Random Entry median CAGR = -8.4%. ADX Burst Entries are significantly better than random entries.
Attachments
ADX Burst Entry + Random Exits
ADX Burst Entry + Random Exits
result2.png (91.74 KiB) Viewed 32364 times
Random Entries + Random Exits
Random Entries + Random Exits
result1.png (77.35 KiB) Viewed 32364 times
Parameters used to simulate the Random Exit systems in Blox
Parameters used to simulate the Random Exit systems in Blox
p012c.png (48.21 KiB) Viewed 32364 times
Last edited by sluggo on Sat Mar 24, 2007 11:25 am, edited 6 times in total.
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

Next, the Channel Breakout Entry was paired with Random Exits ("Result3"). Go long on a stop order at the highest high of the most recent 220 bars; go short on a stop order at the lowest low of the most recent 220 bars. After entry, generate a new random number R (uniformly distributed between 1 and 30), hold the trade for R bars, and then exit on the close. "Result3" shows that the median of the test runs (25th best out of 50) had a Compound Annual Growth Rate of +5.1% per year, which trounces the -8.4% per year of Random Entries. All 50 out of 50 test runs were profitable. Please notice that the increase in profits (5.1 + 8.4 = 13.5% per year) are exclusively due to the use of good entries; the same random exit signals were used in both systems. Channel Breakout entries are significantly better than random entries.

Finally, "Result4" shows the pairing of a Dual Exponential Moving Average entry, with Random Exits. If the 20-bar EMA is above the 350-bar EMA, go long; otherwise, go short. Hold the trade a random number R of bars and then exit on the close. (R is uniformly distributed between 1 and 30). The median of the test runs (25th best out of 50) had a Compound Annual Growth rate of +7.1% per year (versus -8.4% per year for Random Entries). All 50 out of 50 test runs were profitable. The 15.5% increase of profits is due to the Dual EMA entry signal exclusively. Dual EMA entries are significantly better than random entries.

In summary, good entries plus random exits can produce positive profits, even after commissions and slippage, even for punishingly short trade hold-times. This demonstrates that entry signals are a significant contributor to system profitability; the oft-quoted remark that "All profits come from exit signals; entry signals are unimportant," is wrong. Dead wrong.
Attachments
dual EMA entries + Random Exits
dual EMA entries + Random Exits
result4.png (92.34 KiB) Viewed 32361 times
Channel Breakout entries + Random Exits
Channel Breakout entries + Random Exits
result3.png (79.18 KiB) Viewed 32362 times
System parameters used in Blox simulations
System parameters used in Blox simulations
p34.png (28.78 KiB) Viewed 32360 times
Last edited by sluggo on Sat Mar 24, 2007 8:22 am, edited 1 time in total.
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

Here is all the Blox source code for the various systems discussed.

They are divided into modules; one exit Blok to do the Random Exit using (1 < R < N day hold times); one Money Manager Blok to do the Volatility Based positionsizing; and four entry Bloks to implement the four different entry signals discussed. There is also a "statistic" Blok which prints the equity curve values at biweekly intervals.

Fool around with it. Try your own definitions of slippage and commisisons. Change the hold-time to something less ridiculous than (1 to 30 days). Use your own portfolio of markets. Try your favorite entry signals. Change the test dates. Run it for 35 years instead of 10. Be creative, have some fun.

Enjoy!
sluggo
Attachments
Blox_Code_Random_Exits.zip
Blox code used for these test runs
(8.21 KiB) Downloaded 1167 times
nickmar
Roundtable Knight
Roundtable Knight
Posts: 192
Joined: Tue Oct 26, 2004 12:38 pm
Contact:

Post by nickmar »

Great contribution Sluggo!! Sorta like a stress test for your entry logic.
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

Here is one more Entry signal that makes money even with random exits. It uses John Bollinger's "%B" oscillator, which is just Bollinger Bands wrapped into an oscillator. Parameters, results, and Blox source code are attached.
Attachments
Random_Exit_PctB_entry.zip
Blox source code for PercentB entry signal
(1.06 KiB) Downloaded 995 times
%B Entries + random exits
%B Entries + random exits
Result5.png (82.36 KiB) Viewed 32207 times
parameter settings for %B entries
parameter settings for %B entries
p5.png (18.36 KiB) Viewed 32202 times
explorer
Roundtable Fellow
Roundtable Fellow
Posts: 50
Joined: Thu Jun 07, 2007 8:45 pm
Location: Bay Area, CA

Post by explorer »

Sluggo,

I would be very interested to know, how these types of charts are created?

Kind of thinking to create similar charts to track the development of a group of trades bar by bar.

Would you mind to share your chart expertise? Did these charts come from TB or Excel or ???

Thanks,
explorer
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

Excel. If you look at the trading system code you'll see that the equity is printed (for subsequent plotting) semi-monthly. This reduces the amount of data to be plotted by a factor of ten: from 20 datapoints per month, to 2.
explorer
Roundtable Fellow
Roundtable Fellow
Posts: 50
Joined: Thu Jun 07, 2007 8:45 pm
Location: Bay Area, CA

Post by explorer »

Thanks, I will try to create one.

explorer
explorer
Roundtable Fellow
Roundtable Fellow
Posts: 50
Joined: Thu Jun 07, 2007 8:45 pm
Location: Bay Area, CA

Post by explorer »

I managed to create a sample chart that shows the typical a trendfollowing characteristics.

The only thing that I didn't do, I didn't normalize all the trades to start from 0.

It is a pain in the neck to create manually these chart, I wish it would be a built in feature of TB.

Thanks again for the tips Sluggo,
Attachments
TrendFollowingExample.png
TrendFollowingExample.png (35.45 KiB) Viewed 30883 times
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Dear Sluggo, Tim,

I have been trying to use these blocks without success on TBB v3.8 x64.

Is it necessary to change the code to make it work with this newer version of TBB?

Using the blox as posted, variable "UnitSize" in the RandomExit_blox_MoneyManager is undefined.

However even after defining it as a floating point BPV with System scope, one gets zero trades when running a simulation?

Additionally, I get the attached error message for indicator "pctB"?

Thank you,
Dantes
Attachments
Error message.jpg
Error message.jpg (21.61 KiB) Viewed 24595 times
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Dear Tim,

Any chance you could point me in the right direction for this?

Thank you,
Dantes
tigertaco
Full Member
Full Member
Posts: 23
Joined: Fri Feb 27, 2009 1:50 am

frequent contracts

Post by tigertaco »

"Roughly speaking, it takes more than 10 or 15 bars of hold time to get the average profit per trade above the commission and slippage costs ($100/contract)"

It's believable but how then it could be profitable to trade futures with monthly contracts (like oil) ? Wouldn't commission and slippage at rollover times eat almost all profits?
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

dantes wrote:Dear Tim,

Any chance you could point me in the right direction for this?

Thank you,
Dantes
Replace lines 2 & 3 with this line pair:

Code: Select all

   Order.SetQuantity ( (RiskPct * Test.TotalEquity) _
                        / (2.0 * MyATR * Instrument.BigPointValue) ) 
This is required because UnitSize is now a reserved word in TB. In TB's the earlier day, which when this module was created, it was used as you now have it. Above script should get you past this issue.
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Thank you Roger.

For some reason I had missed your kind pointer - it now works perfectly!

Dantes
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Dear Roger, Sluggo,

I'm probably just being dense here... but I was taught that if you don't ask, you never learn...

I don't quite understand what the "2.0 *" is for in the formula below from the Unit Size script in the RandomExit_blox_MoneyManager Blox?
Order.SetQuantity ( (RiskPct * Test.TotalEquity) / (2.0 * MyATR * Instrument.BigPointValue) )
Any help would be much appreciated.

Thank you,
Dantes
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

Let's take all of the equation for others who might want more:

Code: Select all

   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  Original algorithm
   Order.SetQuantity ( (RiskPct * Test.TotalEquity) _
                        / (2.0 * MyATR * Instrument.BigPointValue) )
   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  Define Property Values
   '  Example Values that could be in the above properties
   Test.TotalEquity = 200,000.00

   RiskPct = 1.0% OR 0.01 as a decimal

   Instrument.BigPointValue = 1,000 (E.G. Crude Oil)

   MyATR = 0.50 Points (Average TrueRange Calculation on Order Day)

   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  To determine Size using a Fractional Risk Rate, an early Step is To
   '  Determine How Much Can be Risked on this Order
   Available_Trade_Risk_Equity_Amount = (RiskPct * Test.TotalEquity)
                                         0.01    * 200,000.00

   Available_Trade_Risk_Equity_Amount = 2,000

   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  Let's calculate the Risk-Points this order will carry
   '  to create a Close to Protective price estimate
   Order_Risk = 2.0 * MyATR 
                2.0 * 0.50

   Order_Risk = 1.0 Points
   
   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  In order to understand the value of that risk in dollar terms,
   '  Order_Risk needs to convert its value to a currency value so the
   '  Available_Trade_Risk_Equity_Amount can be used in the next step
   EntryRisk_Dollars = (Order_Risk * Instrument.BigPointValue)
                           1.0     *       1,000.00

   EntryRisk_Dollars = 1,000.00
   
   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   '  Using Sluggo's algorithm, we can now take the equation and put
   '  into this format to determine how many contracts will be give
   '  to this Order's Unit Size
   Order.SetQuantity( Available_Trade_Risk_Equity_Amount / EntryRisk_Dollars )
                                   2,000                 /     1,000.00

   Order.Quantity = 2 Contracts
   '  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Hi Roger, thanks for the quick reply.

The calculation was actually clear, but I still don't see why one needs to have

Code: Select all

Order_Risk = 2.0 * MyATR * Instrument.BigPointValue
as opposed to just

Code: Select all

Order_Risk = MyATR * Instrument.BigPointValue
?

Why would you multiply the ATR value times 2?

Thanks again,
Dantes
Roger Rines
Roundtable Knight
Roundtable Knight
Posts: 2038
Joined: Wed Oct 06, 2004 10:52 am
Location: San Marcos, CA

Post by Roger Rines »

Sluggo's calculation is a estimating approach that attempts to provide some reasonable risk estimation that isn't too far from what would happen had the order been generated with a protective price.

With an example point of 0.50 as the MyATR value, that puts the protective price very close to the price action. While it is possible to use 1.0 instead of 2.0, for estimate process is it better to be conservative, if trading survival is important.

Risk estimation for generating a fractional amount on which to base an order's size isn't anything other than a best guess process. It is a best guess process because if it needed to more realistically reflect what the actual risk of the trade an order would have carried, the risk points provided would have been generated by the distance to a protective stop price from the order day's Close price instead of an expanding MyATR calculation.

When signals generate orders without a protective price, a risk estimator like Sluggo's example is a fall-back method for creating some form of volatility measure that won't be off the planet when the risk is absorbed by a failed trade. Even then, without a protective estimate there isn't any reasonable belief that the actual cost of a failed trade will be close to the risk estimation because the risk estimate is assuming no protective price. Positions without protective prices carry an infinite risk level, and that is usually more than 2.0 * MyATR.

With the above in mind, you can change the 2.0 to just about anything you want. A smaller number will increase size for the same MyATR value, and a larger number will reduce the size for the same MyATR level when used with Crude Oil.

Does this help?
sluggo
Roundtable Knight
Roundtable Knight
Posts: 2987
Joined: Fri Jun 11, 2004 2:50 pm

Post by sluggo »

At the time, 2007, there was much enthusiasm for using "Original Turtle Style" calculations/definitions of "trade risk". See page 264 of WAY OF THE TURTLE for the details.

Or, alternatively, see "Stop Placement" (internal page number 24; adobe page number 28 ... :-) ) of document below.
Attachments
historical.pdf
Trade risk of The Turtles
(495.14 KiB) Downloaded 810 times
dantes
Roundtable Knight
Roundtable Knight
Posts: 128
Joined: Sun May 08, 2011 1:40 pm

Post by dantes »

Dear Roger, Sluggo - once again thanks for sharing your thoughts on the forum.

Dantes
Post Reply