Bonjour à toutes et tous,
J’ai effectué un backtest d’une stratégie en faisant appel à Extratrend.
J’aimerai transformé cette stratégie en indicateur, afin de pouvoir l’utiliser en temps réel. Pourriez vous m’aider à le faire svp ?
Merci d’avance,
Voici le code du backtest :
DEFPARAM CumulateOrders=False
capitalinitial=10000
risque=0.5
exitstrategy=1
profitfactor=6
stopfactor=1.5
partialprofit=1
partialprofitfactor=3
ratchetfactor=7
// Appel des valeurs d'ExtraTrend
//myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
// Tendance ExtraTrend
if myTrend>myTrend[1] then
tendance=1
endif
if myTrend<myTrend[1] then
tendance=0
endif
if tendance and not tendance[1] and not longonmarket THEN
//if not longonmarket then
positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
//positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
BUY positionsize shares AT MARKET
set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
set target profit profitfactor*averagetruerange[20]
endif
flag=0
endif
if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
sell round(positionsize/2) shares at market
flag=1
endif
if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
sell at market
endif
ok je vais regarder cela, je vais ajouter du texte sur le graphique pour marquer les événements, si il faut changer cet aspect visuel on verra par la suite, il faudra me l’indiquer.
Ci-joint la version graphique de cette stratégie avec Extratrend:
capitalinitial=10000
risque=0.5
exitstrategy=1
profitfactor=6
stopfactor=1.5
partialprofit=1
partialprofitfactor=3
ratchetfactor=7
// Appel des valeurs d'ExtraTrend
myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
// Tendance ExtraTrend
if myTrend>myTrend[1] then
tendance=1
endif
if myTrend<myTrend[1] then
tendance=0
endif
if tendance and not tendance[1] and not ionmarket THEN
drawarrowup(barindex,low-AverageTrueRange[14](close)/2) coloured("green")
istoploss = close-stopfactor*averagetruerange[20]
//set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
itakeprofit = close+profitfactor*averagetruerange[20]
//set target profit profitfactor*averagetruerange[20]
endif
flag=0
ionmarket=1
endif
if ionmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
drawtext("X",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
flag=1
endif
if ionmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
drawtext("exit",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
ionmarket=0
endif
//test stoploss & takeprofit
if ionmarket then
if high >= itakeprofit and exitstrategy=0 then
drawtext("TP",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
ionmarket=0
elsif low <= istoploss then
drawtext("SL",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("red")
ionmarket=0
endif
endif
return itakeprofit style(dottedline2) coloured("green"), istoploss style(dottedline3) coloured("red")
Super, un grand merci Nicolas !
Je vais essayer ça et je te reviens.
Cela a l’air de bien marcher.
J’ai trois questions.
– Je suppose que :
SL c’est Stop Loss touché
Le “X” c’est une prise de profit
La flèche vers le haut c’est la prise de position
Mais qu’est ce que le “EXIT” ?
– Est il possible d’avoir le niveau trailing stop ? Car sur le graphique, il ne “suit” pas vraiment le cours. Je suis prévenu que lorsqu’il est tapé.
– J’essaye de changer la couleur des évènements du vert vers le noir, mais je n’y arrive pas ^^
X c’est le profit partiel que tu as codé et EXIT, c’est la sortie totale avec le SELL AT MARKET.
D’accord, merci Nicolas.
Mais du coup, si EXIT est la sortie totale, qu’est ce que “SL” ?
Ta stratégie comporte un STOPLOSS, ce niveau je le teste dans le code et si il est touché, on affiche “SL” 🙂
et tu as aussi codé une sortie de position selon des conditions (voir ton code lignes 41 à 43) = EXIT
Bonsoir Nicolas,
Un grand merci pour ton aide !
Je viens de recevoir ma licence Metascore, et j’aimerai rajouter une condition d’achat.
Pourrais tu m’aider à le faire stp ? (Désolé, je suis vraiment très mauvais en codage, je ne sais pas faire grand chose).
J’aimerai conserver cette stratégie (entrée quand nouvelle zone de force à condition de ne pas déjà être en position, prise de profit partielle, trailing stop avec un ratchet…) mais en rajoutant la condition stricte que le métascore soit supérieur ou égal à 80.
J’aimerai le backtester d’abord et puis le transformer en indicateur visuel si cela se révèle probant.
En te remerciant par avance,
Amicalement,
Thibaut
On récupère l’information de la valeur de MetaScore comme ceci:
myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)
ensuite on teste myScore si il est < ou > à la valeur souhaitée.
D’accord, merci.
J’ai tenté d’implémenter.
Cela donne ça, c’est correct ?
DEFPARAM CumulateOrders=False
capitalinitial=10000
risque=0.5
exitstrategy=1
profitfactor=6
stopfactor=1.5
partialprofit=1
partialprofitfactor=3
ratchetfactor=7
// Appel des valeurs d'ExtraTrend
//myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
// Tendance ExtraTrend
if myTrend>myTrend[1] then
tendance=1
endif
if myTrend<myTrend[1] then
tendance=0
endif
// score Metascore
myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)
if myScore>80 then
tendance=1
endif
if myScore<80 then
tendance=0
endif
//strategy of entry
if tendance and not tendance[1] and not longonmarket THEN
//if not longonmarket then
positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
//positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
BUY positionsize shares AT MARKET
set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
set target profit profitfactor*averagetruerange[20]
endif
flag=0
endif
if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
sell round(positionsize/2) shares at market
flag=1
endif
if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
sell at market
endif
Bonjour, pour joindre le code PRT au bon format, merci d’utiliser le bouton “insert PRT code”, s’il disparait temporairement (bug du site), merci de faire CTRL+F5 pour le faire réapparaitre, mini-tuto qui contourne le bug et permet de localiser le bouton si on ne le connait pas encore: https://www.youtube.com/watch?v=jBuqwWPW3H4
(psa besoin de reposter, je vais éditer le code ci-dessus pour le mettre au bon format)
Non, la logique n’est pas correct, le code devrait être comme ceci :
DEFPARAM CumulateOrders=False
capitalinitial=10000
risque=0.5
exitstrategy=1
profitfactor=6
stopfactor=1.5
partialprofit=1
partialprofitfactor=3
ratchetfactor=7
// Appel des valeurs d'ExtraTrend
//myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
// Tendance ExtraTrend
if myTrend>myTrend[1] then
tendance=1
endif
if myTrend<myTrend[1] then
tendance=0
endif
// score Metascore
myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)
//strategy of entry
if tendance and not tendance[1] and not longonmarket and myscore>80 THEN
//if not longonmarket then
positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
//positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
BUY positionsize shares AT MARKET
set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
set target profit profitfactor*averagetruerange[20]
endif
flag=0
endif
if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
sell round(positionsize/2) shares at market
flag=1
endif
if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
sell at market
endif
Bonjour Nicolas,
J’ai développé une variante de ma stratégie, en incluant une partie SHORT.
Mais j’ai du mal à la transformer en indicateur visuel ^^
Je ne veux pas abuser mais pourrais tu m’aider stp ?
(Désolé mais j’ai beau tape CTRL+F5 mais le bouton Insert PRT code ne s’affiche pas…)
DEFPARAM CumulateOrders=False
capitalinitial=100000
risque=0.5
exitstrategy=1
profitfactor=6
stopfactor=1.5
partialprofit=1
partialprofitfactor=3
ratchetfactor=7
//myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
myTrend, ignored, ignored, myReDyn, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
// Tendance ExtraTrend
if myTrend>myTrend[1] then
tendance=1
endif
if myTrend<myTrend[1] then
tendance=0
endif
// Break Résistance Dynamique ExtraTrend
if myReDyn>myReDyn[1] then
ReDyn=1
endif
if myReDyn<myReDyn[1] then
ReDyn=0
endif
// Metascore
myScore, ignored, ignored = CALL "MetaScore"[0,0,0](close)
//STRATEGIES OF BUY
if tendance and not tendance[1] and not longonmarket and not shortonmarket and myScore>80 and ReDyn=1 THEN
//if not longonmarket then
positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
//positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
BUY positionsize shares AT MARKET
set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
set target profit profitfactor*averagetruerange[20]
endif
flag=0
endif
if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
sell round(positionsize/2) shares at market
flag=1
endif
if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
sell at market
endif
//STRATEGIES OF SELL
if not tendance and not tendance[0] and not shortonmarket and not longonmarket and myScore<20 THEN
//if not ShortOnMarket then
positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
//positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
SELLSHORT positionsize shares AT MARKET
set stop loss stopfactor*averagetruerange[20]
if exitstrategy=0 then
set target profit profitfactor*averagetruerange[20]
endif
flag=0
endif
if shortonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
sell round(positionsize/2) shares at market
flag=1
endif
if shortonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
exitshort at market
endif