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 :
1 |
"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 ».
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// 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 |
Share this
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 :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
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 🙂
Ok 😉
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 🙂 )
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
/-------------------------------------------------------------------------
// Codice principale : STOCK SIMPLE CODE_fts100
//-------------------------------------------------------------------------
// STOCK SIMPLE CODE
// www.doctrading.fr
DEFPARAM CUMULATEORDERS = FALSE
DEFPARAM FlatBefore = 090000
DEFPARAM FlatAfter = 170000
//capital = 10000 + strategyprofit
//n = capital / close
// DEFINITION DE LA TENDANCE
MMlongue = average[246](close)
MMmoyenne = average[64](close)
MMcourte = average[19](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 1 shares AT MARKET
ENDIF
// SORTIE ACHAT
c1v = MMcourte crosses under MMmoyenne
IF c1v THEN
SELL AT MARKET
ENDIF
// ACHAT
c1a = close < MMlongue and MMlongue < MMlongue[1]
c2a = MMcourte crosses under MMmoyenne
IF c1a and c2a THEN
SellShort 1 shares AT MARKET
ENDIF
// SORTIE ACHAT
c1v = MMcourte crosses over MMmoyenne
IF c1v THEN
ExitShort AT MARKET
ENDIF
The new code