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