- Joined
- 12 November 2007
- Posts
- 1,629
- Reactions
- 47
A mean reversion system tested on Norgate Premium Data's 496 stock list of ASX. Date range 1/1/1999 through 6/15/2016. 17.5 years (which is way too long to expect the same system to work without adjustment)
The code was recovered from a directory that was left untouched for two years.
Profitable on 407, not profitable on 89, traded individually.
Allowing all trades on all stocks, there are 141675 trades -- a little more than one trade per stock per month.
83% are profitable.
Average gain per trade is 0.40%.
Average holding period is 3 days.
View attachment 67112
The AmiBroker code
// BuyAfterAnNDaySequenceMultiPosition.afl
//
// This is a modificatiion of Listing 3.2
// BuyAfterAnNDaySequenceMultiPosition.afl
// contained in the book
// "Mean Reversion Trading Systems"
// which is copyright © 2013 Blue Owl Press, Inc
//
// The author of the book and programmer
// of the code is Dr. Howard B. Bandy.
//
// Please read and understand the disclaimer
// associated with all materials related to the book.
//
// To obtain a copy of the book,
// visit the book's website:
// www.MeanReversionTradingSystems.com
//
// This code is provided for the convenience of
// readers of the book.
// Please respect the copyright.
// Do not post this listing without
// the express written consent of Dr. Bandy
//
SetOption( "ExtraColumnsLocation", 1 );
SetOption ( "CommissionMode", 2 ); // $ per trade
SetOption( "CommissionAmount", 0 );
SetOption( "InitialEquity", 1000000 );
SetPositionSize( 10000, spsValue );
MaxPos = 500;
SetOption( "MaxOpenPositions", MaxPos );
//SetBacktestMode( backtestRegularRawMulti );
SetBacktestMode( backtestRegular );
SetTradeDelays( 0, 0, 0, 0 );
BuyPrice = Close;
SellPrice = Close;
// ObFn == K-ratio, CAR/MDD, expectancy
// Define a day as rising based on the closing price
Rising = C > Ref( C, -1 );
Falling = C < Ref( C, -1 );
// The number of days in the sequence
N = Optimize( "N", 2, 1, 7, 1 );
// Direction. 1 == Rising, 0 == Falling
Direction = 0; // Optimize( "Direction", 0, 0, 1, 1 );
// Exit variables
// Maximum holding period
HoldDays = Optimize( "HoldDays", 7, 1, 7, 1 );
// Profit target
ProfitTarget = Optimize( "ProfitTarget", 1.0, 0.2, 4, 0.2 );
// Detect an N day sequence
if ( Direction == 1 )
{
NDaySequence = Sum( Rising, N ) >= N;
}
else
{
NDaySequence = Sum( Falling, N ) >= N;
}
Buy = NDaySequence;
Sell = 0;
ApplyStop( stopTypeProfit, stopModePercent, ProfitTarget );
ApplyStop( stopTypeNBar, stopModeBars, HoldDays );
// Plots
Plot( C, "C", colorBlack, styleCandle );
shapes = IIf( Buy, shapeUpArrow, shapeNone );
shapecolors = IIf( Buy, colorGreen, colorWhite );
PlotShapes( shapes, shapecolors );
/////////////// end /////////////////
Best,
Howard
Off topic, but thought I'd let you know your website isn't working Howard. Any of them(Blue Owl Press either).