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?

PRC is also 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. 
    Rgds,
     

    • 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
      donchianUpperBand=Highest[50](high)
      donchianLowerBand=Lowest[50](low)
      donchianUpperBand=Highest[50](close[1])
      donchianLowerBand=Lowest[50](low[1])

  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.
    Rgds,
    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)
    donchianUpperBand=Highest[a](high[1])
    donchianLowerBand=Lowest[b](low[1])

    BuyCriteriaMet = (close > 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 < 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
    ENDIF2Nicolas, I am having trouble uploading the code and the image: HTTP Error.

    //Exit Long
    ExitShortPosition = close > initialstopExitPoint
    IF SHORTONMARKET AND ExitShortPosition THEN
    EXITSHORT AT MARKET
    ENDIF

     

    • 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 http://www.prorealcode.com/topic/difference-between-buy-at-stop-and-buy-at-limit/.  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 http://www.prorealcode.com/topic/grid-orders-with-one-combined-stop-loss-and-limit-can-it-be-done/.
    Hope your coding is a great success – keep me posted.

  11. elsys • 05/18/2016 #

    Do you have a working version of the strategy?

avatar
Register or

Likes

avatar avatar avatar avatar avatar avatar
Related users ' posts
YvesRobert Hello David, can you explain to me this strategy ? You calculate the difference between t...
davidelaferla The strategy calculates the variation between the body and the previous body (however in pro...
KumoNoJuzza Thanks David it looks great. I am playing with it to get familiar. Do you think it would b...
BaderBader Good day davidelaferla, Thank you for making your strategy available to the community, I do...
Anjuna Marine Thanks for sharing this. I've tested it over 13 years, and each year has been profitable. I ...
noisette Thank you for this code. looks robust and can easily be improved with trailing stop and adju...
phoentzs
1 year ago
banjoo78 Which is the timezone's setting of USA SP 500? I've differents results and I don't know why....
pdrh I have runit in the UTC+2 TZ and got matching results
BaderBader Hey @banjoo78, maybe its because of your License for US Indices? Because I have the sa...
pdrh Bonjour WE ARE SOCIETY,Vous optimisez toujours votre Algo chaque
WE ARE SOCIETY Bonjour, je l'optimise et l'améliore chaque semaine en évitant au maximum les interdictions ...
dammon c'est un bien beau code que tu nous sors là. il m'a fallu du temps pour bien tout comprendre...
Germano77 hello, thx for sharing, but wich broker do you use? At IG I got the notification "automatic...
Musiar Hi Davide, You have done a great job: I modified a bit your strategy for Nasdaq, and now I ...
Maik2404 Musiar können sie den code des automatischen systems teilen.
sfl CAC on Weekly timeframe, long only, short dosent work. Defparam cumulateorders = false ...
superfalcio This kind of strategies coming from Connors research usually work well on timeframes from 1D...
AndyB72 Sbaglio o Short non fa nemmeno un'operazione ? Andare Long su SPY con la MM200 è praticament...
Stanko Ciao Crusoe, grazie per il commento: confermo che il trailing stop non funziona bene. Provo ...
taklause I was wondering, you said it works on the 1 min Chart, but you never use it in the code as t...
Stanko Ciao taklause. Utilizzando il grafico a 1 minuto e fino al grafico a 15 minuti il codice fun...
YvesRobert Hello davidelaferla, how do you put a stop loss and where exactly ? the moment you enter on ...
Hypersimo Buongiorno Davide a quale distanza inserire stop loss e tp nella strategia? grazie
beanpole Thank you for sharing the code. I applied it to the "CAC40 Index" on Euronext market on a da...
ProRealAlgos Hi Crusoe76. Do you mean that you would like a short version of this?
crusoe76 yes please
banjoo78 Hi, first of all thank you for your sharing. I'm new of ProRealTime and I can't replicate y...
ProRealAlgos Same here ;)
YvesRobert Hello, can someone explain this strategy because I don't understand what the program does ex...
andyfx79 l have been demoing for the past couple of weeks with great results , but during a bear mark...
ProRealAlgos.com Hi JohnScher. Yes I think you refer to the strategy called "Turnaround tuesday". This strate...
JohnScher I am not alluding to the turnaround tuesday. The general opinion is that Turnaroundtuesday ...
ProRealAlgos.com Yeah that's maybe not of importance. Anyway. Enjoy! :)
superfalcio Hello, very interesting. Do you have already some tested condiction including timeframe and ...
KumoNoJuzza Thanks. I did not know IG had Futures. I am always missing an info or a detail. I used to th...
joaoarcher Hi, thank you for the this. Is it possible to create a screener from this indicator, so that...
superfalcio Last very good gain of the system: positions on Eurostoxx50 closed yesterday friday 06/12/2024.
JohnScher Short variant, see at https://www.prorealcode.com/topic/late-lunch-trade-dax40-strategy/
DANY Hi JohnScher, Thanks a lot for your contribution. Consider this release to avoid overfit...
JohnScher Thank you so much for exploring the Late Lunch Strategy. For discussion and in answer to yo...
BenJuice JohnScher, merci de partager ta stratégie. Je suis nouveau dans ce domaine, sur ton code q...
JohnScher As a percentage of the price, here 2%. StopLoss as well as TargetProfit. SL and TP come ...
Wilko I absolutely love the simplicity of this mean-reversion strategy. Well done!
Patrice210 bonjour STANKO, effectivement la première ligne apparait en anomalie et je ne comprend pas v...
KumoNoJuzza Hi guys, Thanks @Stanko and everyone for your contributions. I have been playing around ...
Stanko Hi KumoNoJuzza, thanks for the post. I also tried your code with Dax and the performance is ...
thomas2004ch Hi, Is this startegy suitable for daily SPY? Regards
ebous64 Je cherche à traiter des effets de bords avec un encadrement ajustable des variables. Vous a...
thomas2004ch What are the values for nbx, nby, pbx, pby, ptsup, stplos, stptg, tp, vsmax, vsmin?
JohnScher Postscript: It's running in the live right now. One position after the other is opened. ...
ullle73 nice!! how's it been since your last post on going live? :)
thomas2004ch Hi, Is this strategy suitable for daily SPY? Regards

Top