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
osupero https://www.screencast.com/t/2fCW8fkGsOeZ....solo posiciones largas por ahora
osupero https://www.screencast.com/t/MIaSZ2PRg
ALZ Hi JohnSher, Nice but not the same result Do you have the last itf of it ? Good result i...
dertopen HI Wwhy you said avoiding bear market? Don't you think that we can use this code for short...
maurizio dove si trova lo screener?
macdopa Thanks...
Eric If you have a high percentage winners and the trades are closed with take profit the spread ...
Casenova I Agree with you JaunJ, and Yes Eric, what you say makes sense too. Optimizing the Stop Loss...
ET Thanks for the system Casenova. In determining the high of the past 4 bars, is there a reaso...
Milochenta Hello, I downloaded your strategy and I can not get it to have signals. I work with the fre...
gabri Hi, I am not sure the reason you have this problem. I am not familiar with the free version ...
pixx ciao gabri scusa una domanda mi ptresti spiegare il codice perfavore??
apachx Hi. Please, describe the algorithm in words. I want to understand how it works, but for now...
ak5hay2 Works like crazy on bitcoin. Use different timeframes. Thanks a lot Doc!!!
richyowen Hi, great code thanks. Very new to this forum. Is there a way to add a 100point target on an...
lisamitch50 Morning all, Just backtested on quite a few instruments, worked well on backtesting, but tel...
FULVIO09 Attualmente non c'è sufficiente volatilità : la condizione "C0 = AverageTrueRange[1500](Clos...
vlongobardo67 Ma io intendevo in backtest ! Scusa non l’ho menzionato.
ciniselloftse salve fulvio .il trading sistem e sempre profittevole?
bertrandpinoy hi Leo, are you still using thoses strategy right now?
avatar
crazytrader Any improvements of this?
princedon184 hi my name is prince i need help
reb Hello have you used this strat since last year ? live or Back test ? What are the results ?
beeb Yes last Year. But only back test
drysheep Hi all, did anyone test this strategy recently? As i dont get a single trade in the backt...
Francesco78 Jan Wind, I obtain it from the backtest
Kris75 Hi Francesco, The results are totally different with the tickbytick mode; it becomes a losin...
UkDownUnder Takes to long!
juanj This gets me thinking about creating a strategy on the 5min timeframe that only takes trades...
GraHal I noted above does okay on DAX 10 min with even a reduction to 30 of the Stop Loss. I've s...
Kris75 Hi Grahal, What about making the same great work you did with the snipet on google doc but...
verdi55 You can find me at www.FXautomate.com Ahh. So i got it ? 4 different supertrends without th...
juanj What? This has nothing to do with the website. The site is simply a service to help people ...
Nicolas Advertising is allowed,as long as people are helping others and if provided services are abo...
Yannick TradingDayLong = dayofweek = 1 or dayofweek = 2 or dayofweek = 3 or dayofweek = 4 or dayof...
Marlon Hey JohnScher, your code works fine, but my results aren't as good as yours. Even if I use ...
DarioMazza Bha... this code dont work. gg
LancerX This catch my attention, tried to load in pro order but not coming through. What variables n...
macdopa Hello ALE. Is there any way to help us develop or program an algo-strategy for automatic tr...
Giuseppe68 Ciao, sono nuovo e poco esperto, volevo chiedere perchè il ProBacktest lo esegue correttamen...
Yannick Hello There is a mistake in trailing stop code, I think that this should fix the problem s...
Paul About the trailing-stop the way it's coded. That works for backtesting only, just look at th...
Jonny sorry paul, but system says that is not possible to put many stop order combined...what have...
BC
7 years ago
TempusFugit Thanks Bin, nice code, I can use several ideas of the way you build it
DarioMazza Thanks Bin, great concentration, i understand the first idea, but may u indicate me the asse...
Bin Hi Mazza This robot is optimized for DAX30.
Madrosat Bonjour Nicolas la formule du stop loss est elle vraiment valable ?? il n'y a pas au depart ...
Nicolas Il y a peut-être un erreur en effet, essayer avec: set stop ploss (averagetruerange[14] * ...
Madrosat ok merci Nicolas c'est avec /pipsize que ça fonctionne
GraHal Please forgive the daft question, but why is 3-bars-trailing-stop-williams-3.itf included a...
Kris75 Hi, Seems great but what would be the code for a stock ? Thanks, Chirs
oakenstream Paul, what is the best way in your opinion to know if I have over optimized?
edocasa CIAO , SCUSA SE TI CONTATTO,VOLEVO SAPERE SE SEI UN PROGRAMMATORE,NELCASO SE SARESTI DI...
gabri Non sono un genio ma so fare qualcosa. Posso provare ad aiutarti ma se e' troppo complicato ...

Top