Hello everyone,
I just had the idea to write a little code, which makes you enjoy the rising shares.
We take only long positions, on stocks in bullish phase (defined relative to the moving average 200 periods).
The formula includes reinvestment of earnings.
Without reinvestment, it is necessary to use :
"Buy 10,000 cash at market."
We must optimize the variables « mm » and « cc », but generally we have good results with mm = 3 and cc = 4.
Screenshot : code tested for example on « Pernod Ricard », over the last 20 years.
The code is profitable on the vast majority of the shares, because it only takes positions in the uptrend.
This code is a light version of my personal code, the « CODE BOURSE PEA ».
// STOCK SIMPLE CODE
// www.doctrading.fr
DEFPARAM CUMULATEORDERS = FALSE
capital = 10000 + strategyprofit
n = capital / close
// DEFINITION DE LA TENDANCE
MMlongue = average[200](close)
MMmoyenne = average[mm](close)
MMcourte = average[cc](close)
// Optimiser les variables mm et cc de 1 à 10
// ACHAT
c1a = close > MMlongue and MMlongue > MMlongue[1]
c2a = MMcourte crosses over MMmoyenne
IF c1a and c2a THEN
BUY n shares AT MARKET
ENDIF
// SORTIE ACHAT
c1v = MMcourte crosses under MMmoyenne
IF c1v THEN
SELL AT MARKET
ENDIF
You must be logged in to post a comment.
I think the "best" method to backtest is to do a simplier Walk forward backtest (and we hope we will have a full Walk forward backtest in the next version 10.4.) :
Optimize the parameters in the 2/3 of the duration of the backtest and test them on the Last 1/3
For example test on the 2 first months and test them on the Last month for a duration of 3 month
It's not ideal but better than Optimize on all duration because the past is the past
Have a nice day (From bali, in holidays :-) )
Ok ;-)
Thanks again for sharing Doc.
Beware of optimization, it introduces survivor bias that is incompatible with automated trading. Over fitting past behaviour of a strategy, is like rewrite history by yourself :)
I wrote a short blog article on this: http://www.prorealcode.com/blog/avoid-equity-curve-fitting-with-probacktest-trading-strategy-optimisation/
Delete equity over-fit introduced by parameters in strategies is the major and hard part of automatic trading research. Code long only strategies that buy instruments that perform since thirty years, is the easy one :)
Hi,
I have modified and optimized the strategy on FTSE 100 CASH Eur 1 on IG demo account. Below the code modified and optimized. I have a result of 50% positive trade with a gain, starting from january 2016, of 670 euro with Time Frame of 5 minute. Can you aid me to develop the strategy in order to improve the result on the same market or EURUSD mini (I use IG). Thanks
The new code