Following the trend

Following the trend

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.


Share this

Risk disclosure:

No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.

ProRealTime ITF files and other attachments : How to import ITF files into ProRealTime platform?

New! PRC is also now on YouTube, subscribe to our channel for exclusive content and tutorials

  1. ladefense • 05/18/2016 #

    Doesn t work …no signals
    Marche pas chez moi ….

  2. Stef • 05/18/2016 #

    Backtesting from 1 July 1979 to today results in 2 trades. Looks like there is a problem somewhere.

  3. Mhingas • 05/18/2016 #

    Hi Stef,
    will take a look shortly, and advise. 

    • Mhingas • 05/18/2016 #

      hi Stef,
      the first two lines of code need to change to the last two respectively, so we put on a buy stop order tomorrow if the close today is the highest close in the past 50 days than, the logic is reversed for a short position

  4. Nicolas • 05/18/2016 #

    For your information, I have changed the code in the post, accordingly to Mhingas comment.

  5. wedret1 • 05/18/2016 #

    Hi Mhingas
    What instruments do you trade with this system in South Africa?

  6. Mhingas • 05/18/2016 #

    Hi wedret1,
    I run the strategy across all markets. commodities (including non agricultural commodities) ,energies, financials. Equities, but because this latter class is highly correlated, i don’t run it on individual stocks but the main indices. If one asset class is in a range, funds ( trends ) are moving in other asset classes. the strategy just needs to catch 2-4 directional trends a year, pay for losses incurred when markets are range bound, leave enough on the table to be up on the year.
    Mathonsi c 

  7. trendfollower86 • 05/18/2016 #

    Thanks for the code. How do you intent to implement the position sizing. From my experience entries and exits are less important that correct and optimum position sizing.

  8. Periho • 05/18/2016 #

    My contribution is more on the strategy side; the method of catching a lasting trend on upper Doncian can benefit of being supported by a break out of volume of more than 1,5 the average daily volume over the last 20 days. Trailing SL 5-7 x ATR and holding time 4.5 months. Check that the paper have high volume > 200000/day and is within the range of institutional investor (US is USD5+) (i will be careful with Forex doing this)

  9. MikeGC • 05/18/2016 #

    Thank you @Periho, I got a very nice result with some minor mods to your code.  I have optimised the EMA’s and the Donchian Bands to produce an ME of 1.75, and an IRR of 121%.  I had to preload 200 bars to get it to start.
    // Definition of code parameters

    DEFPARAM CumulateOrders = true // Cumulating positions activated
    DEFPARAM PreLoadBars = 200

    //**********************************************Conditions to enter long positions***********************************************//
    ema50 = ExponentialAverage[c](close)
    ema100 = ExponentialAverage[d](close)

    Uptrend = (ema50 > ema100)

    BuyCriteriaMet = (close > donchianUpperBand)
    initialstopExitPoint = Supertrend[3,10]
    BUY 1 SHARES AT high stop

    AddOnToLongPosition = close CROSSES UNDER SAR[0.02,0.02,0.2]

    //Exit Long
    ExitLongPosition = close < initialstopExitPoint
    //********************************************End Conditions to enter long positions***********************************************//

    //**************************************ShortSell Conditions to enter long positions***********************************************//
    Downtrend = (ema50 < ema100)
    SellCriteriaMet = (close < donchianLowerBand)


    AddOnToShortPosition = close < Supertrend[3,10] AND close CROSSES OVER SAR[0.02,0.02,0.2]
    ENDIF2Nicolas, I am having trouble uploading the code and the image: HTTP Error.

    //Exit Long
    ExitShortPosition = close > initialstopExitPoint


    • Periho • 05/18/2016 #

      This is great, the code is interesting – kindly clarify:

      Line 18: BUY 1 SHARES AT high stop | Please explain the function of: «high stop»
      Buying 1 SHARES at market is hardly profitable in my back testing . Any suggestions regarding calculation of position sizing?  
      Same for calculated losses, for example sizing of positions based on 2-3% losses  of the total risk capital?

      I am working on this myself and I will share it when its ready, however thoughts and ideas will be appreciated

  10. MikeGC • 05/18/2016 #

    Hi @Periho, 
    Re “Buy at high stop”, refer to this post  The reason that buying at market does not work is that it seems the code depends on buying at a price higher than the current market price.  (This command was in the original code – I did not add it.)
    Your will find some interesting code for money management at
    Hope your coding is a great success – keep me posted.

  11. elsys • 05/18/2016 #

    Do you have a working version of the strategy?

Register or


avatar avatar avatar avatar avatar
Related users ' posts
juanj Hi Jan, I did not include swap fees for this strategy as it is primarily a 'concept strategy...
jebus89 heres a pic of 200K bars:
bibiyanki doesn't work , not start
imonix Have been trying this on demo since Monday before deciding whether to go live with it. Using...
4 months ago
Lucho0712 Hi, there seems to be a copy/paste error at the end of the Momentum section. Also, the first...
Lucho0712 Hi, you need to insert "5", in order to not trade on Fridays.
delynot je n'arrive pas non plus avec le dernier code Syntax error line 29 char 58, it’s pointig a...
Darren Nash Thanks Souhail, in the end i just copy/paste the logic with variables and it works. I rem...
Darren Nash One thing to note also for DOW trading if using IG, change the buy/sell qty from 1 to 2
mostafa samady How can I optimize it for DAX 30? Thanks!
Jan Also the variables on top ( var1 0-69 and var2 0-69), those variables are needed to determin...
Jan It might be a good idea to reduce the average to 15 instead of 30 to reduce market noise eff...
oliverkeim Hello, Please can you help. I use 10.3 and are not able to set the strategy live. "Folgend...
swedshare You got some potential here. A couple of things I think about: 1, The opening hours in this...
phoentzs Ich habe hier mit Spread 2 gerechnet, also etwa dem Mittelwert zwischen Tag und Nacht. Das G...
phoentzs Hab festgestellt, das US500 fast noch besser funktioniert als der Dax. Was aber auch daran l...
Jan Wind Thanks for sharing ! The Gain/Loss ratio is a bit low, 1,16, hardly offset the risks take...
drive whats the period ?
samsampop Hi Crystal Babe - would you be happy sharing your revised code as I too am testing this on t...
Marcelus Bonjour, Sur Dax , en 1h avec ces réglages depuis 2011 : - HalfLength = 170 AtrLength =...
Marcelus Bonjour, Sur Dax , en 4h avec ces réglages backtestés depuis 2011 (200000unités) : HalfL...
robertogozzi Sorry for replaying so late, I really missed your post. There is a discussion thread here h...
robertogozzi Cela fonctionne bien, peut-ĂȘtre que vous avez fait un mauvais copier-coller, je ne sais pas....
RemiNhAPQM Bonjour, merci pour le super partage, la stratégie offre des trÚs beaux résultats. Je ne s...
GraHal Discussion Topic started here ...
samsampop Hi robertogozzi - thank you very much for sharing this strategy. I have performed various ...
robertogozzi Thank you samsampop.
Tony87 Gubben do we have a progress report?
Gubben So far so good. After a long drawdown it was winning four times in five weeks. Since 24 jul...
pat95162 Salut Pourquoi je n'ai pas les mĂȘme rĂ©sultats que vous
Marcus Quartus Aurius Hi thanks, it better work on timeframe 1H
Franro Marcus you run this?
pat95162 ça ne fonctionne pas pour moi
TempusFugit Interesting idea and with a lot of room for improvement.... maybe a trailing stop? Thanks fo...
Jan Wind Unglaubich das dieser Strategie Gewinne generiert ! Es erschient leider nicht so gleichmaßi...
ALZ Hello, currently, I don't have the same result as above and don't no if it works good in...
JJ Tec Hola. Me gustarĂ­a contactar contigo para ver la estrategia..
nilsla1981 Has someone already tested in real ?
Alberto Aguilera Hi! Thanks for your strategy Anyone can check it with 200 bars?
1 year ago
693579 As Allanrobison pointed out..... After setting Variable, "summation" from pro builder needs ...
Bard Thanks for this Ichimoku strategy Jan, I wonder now, how this strategy would benefit if the ...
vinit0412 Hi Friends. Please let me know inbuilt variable which contains current market price. I nee...
nfulcher Please could someone explain how the following code is calculated:- iDI = TEMA[3](DI[DI2]...
oakenstream Jan, I find sometimes that the priceexit variable is never set. It seems to happen when the ...
Matt66612 I do not understand the first time I launch the backtest I got the same result as you. but ...
Nicolas Discussions with many other versions and improvements can be found here: https://www.proreal...
darbes Hi How does it go on live ? JC
antonio73 Balmora74, io vedo che funziona anche su timeframe ad 1 minuto con piccole ottimizzazioni, t...
Exalaxe Hey, i just noticed you optimized this strategy. Could i see your new version, please?
Andrea.1981 sorry i add my code but it not enter why i dont know
Andrea.1981 this is code simply stop , and you can see another version for stop / Codice principale...