Trend Trading Model, following the trend By Mr Cleanow I recently finished reading following the trend by Andreas F Cleanow.
In the book, Mr Cleanow constructs a simple Trend following Module which he then thoroughly tests across a diverse investment Universe. He then compares the results achieved by this simple trend module to the results achieved by most successful hedge funds.
The equity curve achieved by this model is more or less the same as what the big CTA’s out there are achieving year on year with acceptable draw downs. I decided to code the model and put it to test my self, as i’m still learning the programming language used here i thought this would be a great exercise to test what i’ve learnt so far. There’s code which i commented out which i was using in my back tests, the add on portion is not part of the model, but i figured the model is designed to catch trends, so if it does catch a trend it only makes sense to compound positions as the trend develops, it impacts on results drastically. But the main exercise here to code the main model and run the tests myself. Reading the book was an eye opener.
// Definition of code parameters
DEFPARAM CumulateOrders = true // Cumulating positions activated
//**********************************************Conditions to enter long positions***********************************************//
ema50 = ExponentialAverage[50](close)
ema100 = ExponentialAverage[100](close)
Uptrend = (ema50 > ema100)
donchianUpperBand=Highest[50](close[1])
donchianLowerBand=Lowest[50](low[1])
BuyCriteriaMet = (close CROSSES OVER donchianUpperBand)
initialstopExitPoint = Supertrend[3,10]
IF NOT LONGONMARKET AND Uptrend AND BuyCriteriaMet THEN
BUY 1 SHARES AT high stop
ENDIF
//AddOn
//AddOnToLongPosition = close CROSSES UNDER SAR[0.02,0.02,0.2]
//IF LONGONMARKET AND COUNTOFLONGSHARES < 3 AND POSITIONPERF > 0.02 AND AddOnToLongPosition THEN
//BUY 1 SHARES AT MARKET
//ENDIF
//Exit Long
ExitLongPosition = close < initialstopExitPoint
IF LONGONMARKET AND ExitLongPosition THEN
SELL AT MARKET
ENDIF
//********************************************End Conditions to enter long positions***********************************************//
//**************************************ShortSell Conditions to enter long positions***********************************************//
Downtrend = (ema50 < ema100)
SellCriteriaMet = (close CROSSES UNDER donchianLowerBand)
IF NOT SHORTONMARKET AND Downtrend AND SellCriteriaMet THEN
SELLSHORT 1 SHARES AT MARKET
ENDIF
//AddOn
//AddOnToShortPosition = close < Supertrend[3,10] AND close CROSSES OVER SAR[0.02,0.02,0.2]
//IF SHORTONMARKET AND COUNTOFSHORTSHARES < 3 AND POSITIONPERF > 0.02 AND AddOnToShortPosition THEN
//SELLSHORT 1 SHARES AT MARKET
//ENDIF
//Exit Long
ExitShortPosition = close > initialstopExitPoint
IF SHORTONMARKET AND ExitShortPosition THEN
EXITSHORT AT MARKET
ENDIF