I propose this code which takes a position on trend rebounds at the 32.2% and 61.8% Fibonacci level with a Williams% R confirmation, and the Vwap Weekly as a trend indicator. I created this backtest on the CAC 40 in 30Min time frame But I think that this strategy can be applied to other assets and also be optimized.
The details are in the code in comments to help understanding.
Thank you
//================================================//
// ========== PARAMETRE GENERAUX ================ //
//================================================//
DEFPARAM CumulateOrders = false
// REINVESTISSEMENT DES GAINS
REINV = 1 // 0 = NON / 1 = OUI
IF REINV = 0 THEN
Capital = CapitalInit
ELSIF REINV = 1 THEN
Capital = CapitalInit + (strategyprofit*2/3)
ENDIF
//================================================//
// ========== PARAMETRES DES POSITIONS ========== //
//================================================//
// MONEY MANAGEMENT // 3 VARIABLES A PARAMETRER //
Capitalinit = 10000 // CAPITAL INITIAL
RisquePourc = 1.5 // RISQUE PAR TRADE EN %
DSL = 46 // DISTANCE AU STOP LOSS
RisquePartrade = capital*RisquePourc*0.01
RisqueParContrat = DSL*pipsize
N = RisquePartrade / RisqueParContrat
IF N < 1 then N = 1 endif // PLAGES HORRAIRES DE TRADING // CtimeAchat1 = time >= 080000 and time < 223000
//================================================//
// ========== PARAMETRE DES INDICATEURS ========= //
//================================================//
// RETRACEMENT DE FIBONACCI ET LOCALISATION DES ZONES // 1 VARIABLE A PARAMETRER //
NbCycle = 54 // NOTE : LE NOMBRE DE BOUGIE PRECEDENTE CORRESPOND A UN CYCLE , EXEMPLE 40 BOUGIES DE 30 MIN REPRESENTENT UN CYCLE DE 20H00 //
hh = highest[NbCycle](high) // hh est le plus haut des X bougies précédentes
ll = lowest[NbCycle](low) // LL est le plus bas des X bougies précédentes
amplitudefibo = ((hh - ll)/ll)*100 // L'amplitude est égale au plus haut des NBP précédentes
RT382 = ll+(hh-ll)*0.382 // Niveau de retracement 38,2%
RT618 = ll+(hh-ll)*0.618 // Niveau de retracement 61,8%
RT788 = ll+(hh-ll)*0.788 // Niveau de retracement 78,8%
// LES V-WAP YEARLY , MONTHLY ET DAYLY //
//calcule de la période
if DayOfWeek=0 or (dayofweek[1]=5 and dayofweek<>5) then
weekbar=barindex
endif
if month<>month[1] then
monthbar=barindex
endif
if year<>year[1] then
yearbar=barindex
endif
once dWeekly=1
once dMonthly=1
once dYearly=1
dWeekly = max(dWeekly, barindex-weekbar)
dMonthly = max(dMonthly, barindex-monthbar)
dYearly = max(dYearly, barindex-yearbar)
VWAPweekly = SUMMATION[dWeekly](volume*typicalprice)/SUMMATION[dWeekly](volume)
VWAPmonthly = SUMMATION[dMonthly](volume*typicalprice)/SUMMATION[dMonthly](volume)
VWAPyearly = SUMMATION[dYearly](volume*typicalprice)/SUMMATION[dYearly](volume)
// LE Volatility index //
PTotETMoving=20
PeriodET = 2 //"Ecart type"
PeriodTotET = 18 //"Période de recherche",minval=0)
PeriodEMA= 3 //"Période EMA",minval=0, type=input.integer)
BMax= 0.8 //"Borne Maximum",minval=0, type=input.float)
BMin= 0.2 //"Borne Minimum",minval=0, type=input.float)
ET = std[PeriodET]
ETmaxpostTotET=highest[PeriodTotET](ET)
if (PTotETMoving<PeriodTotET+PeriodET and barindex>PeriodET) then
PTotETMoving= PTotETMoving+1
if ETmaxPeriodET+PeriodTotET) then
ETmax=ETmaxpostTotET
endif
Volat=(ET/ETmax)
MMExp=average[PeriodEMA,1](volat)
//williams %R//
Catest = williams[22]<williams(close) and williams < -31 //================================================// // ======== LES CONDITIONS D'ENTREE LONG ======== // //================================================// //Les condition de Momentum// CaMom1 = hh > VWApWeekly // CONDITION MOMENTUM 1 :le cours cloture au dessus de la VWAP monthly
CaMom2 = VWAPWEEKLY > VWAPWEEKLY[21] // La Vwap weekly est ascendante : la vwap weekly cloture au dessus de la vwap weekly a 24 périodes
CaMom3 = MMExp < 0.2 // Le marché est toujours en zone d'accumulation : La Moyenne mobile exponentiel est au dessous de la borne Minimum Bmin //les conditions de localisation// //achat sur REBOND premier arrêt 38,2% de retracement// CaLoc4 = amplitudefibo > 0.8 //la hauteur minumum du mouvement de référence en pourcentage
CaLoc5 = amplitudefibo < 1.4 //La hauteur maximum du mouvement de référence en pourcentage
//ENTREE LONG SUR PREMIER ARRET //
//Les Conditions de figure //
CaFiG6 = LOWEST[1](low) < RT382 AND CLOSE[1] > RT382 //La bougie précédente croise les 38,2% de retracement mais cloture au dessus
//stoploss et take profit //
takeprofit = 2.02
Stoploss = (tradeprice*takeprofit/100)*0.5
If stoploss > DSL Then
stoploss = DSL
endif
If CtimeAchat1 AND CaMom1 AND CaMom2 AND CaMom3 AND CaLoc4 AND CaLoc5 AND CaFig6 and Catest THEN
BUY n SHARES AT MARKET
set target %profit takeprofit
set stop loss Stoploss ptrailing stoploss*1.02
ENDIF
//ENTREE LONG SUR RELOAD ZONE //
// les conditions de Momentum
CaMom1bis = hh > VWApWeekly // CONDITION MOMENTUM 1 :le cours cloture au dessus de la VWAP monthly
CaMom2bis = VWAPWEEKLY > VWAPWEEKLY[54] // La Vwap weekly est ascendante : la vwap weekly cloture au dessus de la vwap weekly a 24 périodes
CaMom3bis = MMExp < 0.18 // Le marché est toujours en zone d'accumulation : La Moyenne mobile exponentiel est au dessous de la borne Minimum Bmin CaLoc4bis = amplitudefibo > 0.8
CaLoc5bis = amplitudefibo < 1.4
//Les Conditions de figure //
CaFiG6bis = LOWEST[1](low) < RT618 AND CLOSE[1] > RT618 //La bougie précédente croise les 61,8% de retracement mais cloture au dessus
CaFig7bis = open>close
//stoploss et take profit //
takeprofitbis = 2.51
Stoplossbis = (tradeprice*takeprofit/100)*0.4
If stoplossbis > DSL Then
stoplossbis = DSL
endif
If CtimeAchat1 AND CaMom1bis AND CaMom2bis AND CaMom3bis AND CaLoc4bis AND CaLoc5bis AND CaFig6bis AND CaFig7bis and catest THEN
BUY n SHARES AT MARKET
set target %profit takeprofitbis
set stop loss Stoplossbis ptrailing stoplossbis*1.54
ENDIF
//===============================================//
// ======= LES CONDITIONS D'ENTREE SHORT ======= //
//===============================================//
//achat sur REBOND premier arrêt 38,2% de retracement//
//Les condition de Momentum//
CvMom1 = hh < VWApWeekly[75] // CONDITION MOMENTUM 1 :le cours cloture en dessous de la VWAP monthly
CvMom2 = VWAPWEEKLY < VWAPWEEKLY[22] // La Vwap weekly est ascendante : la vwap weekly cloture en dessous de la vwap weekly a 22 périodes CvMom3 = MMExp > 0.27 // Le marché est toujours en zone d'accumulation : La Moyenne mobile exponentiel est au dessous de la borne Minimum Bmin
CvWill = williams[9]<williams(close) //les conditions de localisation// CvLoc4 = amplitudefibo > 0.8 //la hauteur minumum du mouvement de référence en pourcentage
CvLoc5 = amplitudefibo < 1.95 //La hauteur maximum du mouvement de référence en pourcentage //ENTREE LONG SUR PREMIER ARRET SHORT// //Les Conditions de figure // CvFiG6 = HIGHEST[1](HIGH) > RT618 AND CLOSE[1] < RT618 //La bougie précédente croise les 38,2% de retracement mais cloture EN DESSOUS //stoploss et take profit // takeprofit = 1.98 StoplossV = (tradeprice*takeprofit/100)*0.44 If stoplossV > DSL Then
stoplossV = DSL
endif
If CtimeAchat1 AND CvMom1 and CvMom2 AND CvMom3 AND CvWill AND CvLoc4 AND CvLoc5 AND CvFig6 THEN
sellshort n SHARES AT MARKET
set target %profit takeprofit
set stop loss StoplossV ptrailing stoplossV*1.08
ENDIF
//achat sur REBOND premier arrêt 61.8% de retracement//
//Les condition de Momentum//
CvMom1Vbis = hh < VWApWeekly[64] // CONDITION MOMENTUM 1 :le cours cloture en dessous de la VWAP monthly
CvMom2Vbis = VWAPWEEKLY < VWAPWEEKLY[21] // La Vwap weekly est ascendante : la vwap weekly cloture en dessous de la vwap weekly a 22 périodes
CvMom3Vbis = MMExp < 0.49 // Le marché est toujours en zone d'accumulation : La Moyenne mobile exponentiel est au dessous de la borne Minimum Bmin
CvWillVbis = williams[43]<williams(close) and williams > -23
//les conditions de localisation//
CvLoc4Vbis = amplitudefibo > 0.8 //la hauteur minumum du mouvement de référence en pourcentage
CvLoc5Vbis = amplitudefibo < 1.3 //La hauteur maximum du mouvement de référence en pourcentage //ENTREE LONG SUR PREMIER ARRET SHORT// //Les Conditions de figure // CvFiG6Vbis = HIGHEST[1](HIGH) > RT382 AND CLOSE[1] < RT382 //La bougie précédente croise les 61.2% de retracement mais cloture EN DESSOUS //stoploss et take profit // takeprofitVbis = 2.57 StoplossVbis = (tradeprice*takeprofit/100)*0.44 If stoplossVbis > DSL Then
stoplossVbis = DSL
endif
If CtimeAchat1 AND CvMom1Vbis AND CvMom2Vbis AND CvMom3Vbis AND CvWillVbis AND CvLoc4Vbis AND CvLoc5Vbis AND CvFig6Vbis THEN
sellshort n SHARES AT MARKET
set target %profit takeprofitVbis
set stop loss StoplossVbis ptrailing stoplossVbis*1.1
ENDIF
You must be logged in to post a comment.
Bonjour, Je voudrais mettre le liens du code en format .itf mais je n'y arrive pas , quelqu'un peut-il m'indiquer la marche a suivre ?
//================================================// // ========== PARAMETRE GENERAUX ================ // //================================================// DEFPARAM CumulateOrders = false // REINVESTISSEMENT DES GAINS REINV = 1 // 0 = NON / 1 = OUI IF REINV = 0 THEN Capital = CapitalInit ELSIF REINV = 1 THEN Capital = CapitalInit + (strategyprofit*2/3) ENDIF //================================================// // ========== PARAMETRES DES POSITIONS ========== // //================================================// // MONEY MANAGEMENT // 3 VARIABLES A PARAMETRER // Capitalinit = 10000 // CAPITAL INITIAL RisquePourc = 1.5 // RISQUE PAR TRADE EN % DSL = 46 // DISTANCE AU STOP LOSS RisquePartrade = capital*RisquePourc*0.01 RisqueParContrat = DSL*pipsize N = RisquePartrade / RisqueParContrat IF N = 080000 and time < 223000 //================================================// // ========== PARAMETRE DES INDICATEURS ========= // //================================================// // RETRACEMENT DE FIBONACCI ET LOCALISATION DES ZONES // 1 VARIABLE A PARAMETRER // NbCycle = 54 // NOTE : LE NOMBRE DE BOUGIE PRECEDENTE CORRESPOND A UN CYCLE , EXEMPLE 40 BOUGIES DE 30 MIN REPRESENTENT UN CYCLE DE 20H00 // hh = highest[NbCycle](high) ll = lowest[NbCycle](low) amplitudefibo = ((hh - ll)/ll)*100 RT382 = ll+(hh-ll)*0.382 RT618 = ll+(hh-ll)*0.618 // LES V-WAP YEARLY , MONTHLY ET DAYLY // //calcule de la période if DayOfWeek=0 or (dayofweek[1]=5 and dayofweek5) then weekbar=barindex endif once dWeekly=1 dWeekly = max(dWeekly, barindex-weekbar) VWAPweekly = SUMMATION[dWeekly](volume*typicalprice)/SUMMATION[dWeekly](volume) // LE Volatility index // // LE Volatility index // PTotETMoving=20 PeriodET = 2 //"Ecart type" PeriodTotET = 18 //"Période de recherche",minval=0) PeriodEMA= 3 //"Période EMA",minval=0, type=input.integer) BMax= 0.8 //"Borne Maximum",minval=0, type=input.float) BMin= 0.2 //"Borne Minimum",minval=0, type=input.float) ET = std[PeriodET] ETmaxpostTotET=highest[PeriodTotET](ET) if (PTotETMovingPeriodET) then PTotETMoving= PTotETMoving+1 if ETmaxPeriodET+PeriodTotET) then ETmax=ETmaxpostTotET endif Volat=(ET/ETmax) MMExp=average[PeriodEMA,1](volat) //williams %R// Catest = williams[22]<williams(close) and williams VWApWeekly CaMom2 = VWAPWEEKLY > VWAPWEEKLY[21] CaMom3 = MMExp 0.8 CaLoc5 = amplitudefibo < 1.4 //ENTREE LONG SUR PREMIER ARRET // //Les Conditions de figure // CaFiG6 = LOWEST[1](low) RT382 //stoploss et take profit // takeprofit = 2.02 Stoploss = (tradeprice*takeprofit/100)*0.5 If stoploss > DSL Then stoploss = DSL endif If CtimeAchat1 AND CaMom1 AND CaMom2 AND CaMom3 AND CaLoc4 AND CaLoc5 AND CaFig6 and Catest THEN BUY n SHARES AT MARKET set target %profit takeprofit set stop loss Stoploss set stop ptrailing stoploss*1.02 ENDIF //ENTREE LONG SUR RELOAD ZONE // // les conditions de Momentum CaMom1bis = hh > VWApWeekly CaMom2bis = VWAPWEEKLY > VWAPWEEKLY[54] CaMom3bis = MMExp 0.8 CaLoc5bis = amplitudefibo < 1.4 //Les Conditions de figure // CaFiG6bis = LOWEST[1](low) RT618 CaFig7bis = open>close //stoploss et take profit // takeprofitbis = 2.51 Stoplossbis = (tradeprice*takeprofit/100)*0.4 If stoplossbis > DSL Then stoplossbis = DSL endif If CtimeAchat1 AND CaMom1bis AND CaMom2bis AND CaMom3bis AND CaLoc4bis AND CaLoc5bis AND CaFig6bis AND CaFig7bis and catest THEN BUY n SHARES AT MARKET set target %profit takeprofitbis set stop loss Stoplossbis set stop ptrailing stoplossbis*1.54 ENDIF //===============================================// // ======= LES CONDITIONS D'ENTREE SHORT ======= // //===============================================// //Les condition de Momentum// CvMom1 = hh < VWApWeekly[75] CvMom2 = VWAPWEEKLY 0.27 CvWill = williams[9] 0.8 CvLoc5 = amplitudefibo RT618 AND CLOSE[1] DSL Then stoplossV = DSL endif If CtimeAchat1 AND CvMom1 and CvMom2 AND CvMom3 AND CvWill AND CvLoc4 AND CvLoc5 AND CvFig6 THEN sellshort n SHARES AT MARKET set target %profit takeprofit set stop loss StoplossV set stop ptrailing stoplossV*1.08 ENDIF //short sur REBOND 61.8% de retracement// //Les condition de Momentum// CvMom1Vbis = hh < VWApWeekly[64] CvMom2Vbis = VWAPWEEKLY < VWAPWEEKLY[21] CvMom3Vbis = MMExp < 0.49 CvWillVbis = williams[43] -23 CvLoc4Vbis = amplitudefibo > 0.8 CvLoc5Vbis = amplitudefibo RT382 AND CLOSE[1] DSL Then stoplossVbis = DSL endif If CtimeAchat1 AND CvMom1Vbis AND CvMom2Vbis AND CvMom3Vbis AND CvWillVbis AND CvLoc4Vbis AND CvLoc5Vbis AND CvFig6Vbis THEN sellshort n SHARES AT MARKET set target %profit takeprofitVbis set stop loss StoplossVbis set stop ptrailing stoplossVbis*1.1 ENDIF
Bonjour, Voici le code simplifié , j'ai aussi modifié l'écriture des trailing stop pour permettre de de lancer sur Ig market . Merci
Bonjour Jigsaw2000 Ton code à l'air vraiment bien mais le fichier ITF ne se télécharge plus... Pourrais tu le réinitialiser s'il te plait ? J'ai hâte de le tester. Merci pour ton travail
Bonjour, merci pour votre travail, les backtests sont très prometteurs ! J'ai tenté de lancer le code en automatique via ProOrder mais j'ai le message d'erreur suivant : "Les stops combinés ne peuvent pas être utilisés avec ProOrder". Auriez-vous un moyen d'y remédier ? En vous remerciant d'avance.
j'aime bien reflex de john elher que nicolas a traduit mais trop lourd pour mon code
Bonjour, effectivement je dois préciser ma demande . En fait je cherche un oscillateur , un indicateur donc borné pour limiter les variables . c'est très important pour moi que ce soit un oscillateur car c'est un signal de vente et d'achat . Ma stratégie définie le plus haut et le plus bas des 40 bougie précédente et trace un Fibonacci , je souhaite rentrer sur un retournement au 38,2 ou 61,8 , l'oscillateur de cycle doit m'avertir proche de ces niveau d'un retournement de cycle (un pull back sur l'oscillateur par exemple) . j'
Bonjour, vous pensiez à quel indicateur de John Ehler en oscillateur de cycles. Si je me souviens bien il a fait des stochastiques et d'autres indicateurs dont la longueur est adaptative, surtout valables pour des produits cycliques (matières premières, commodities). Il y a le momentum, le RSI, les stochastiques (valable en range surtout), le DeMarker (DeM), le OBV, le KVO, repulse, et certains composés (le PRT cycle à base de stochastiques), le DMI, les MACD, les MACD0delay (mesurant les accélérations), le DPO... Tout dépend de ce que vous cherchez optimiser les entrées avec des oscillateurs de type surachat/survente, ou des oscillateurs de tendance.
Bonjour, je travail toujours à évoluer mon code pour le DAX en M15 , je souhaite intégrer un indicateur type oscillateur de cycle , certains indicateurs , notamment ceux de J.ehler sont parfaits mais trop lourd pour mon code , auriez vous une idée d'indicateur de cycle simple pour filtrer au mieux les signaux achat/vente ?
this strategy seems promising however in the code there are still script errors that cannot be corrected for those who would like to alleviate it by removing the monthly and annual VWAps from the DAX M15 version seems to be in preparation ... to see also if will the strategy recover at the start of 2021? the one who will want to make the corrections for the others is an angel thank you
Félicitation à ses résultats de plus de 450% au dernier trade (du 29 mars au 01 avril) avec CAC40 à 30 min après avoir débattu aux 2 premiers trades. Ceci démontre l'atout majeur de ce code qui résulte en sa capacité de tirer énormément des profits tant que la tendance est prononcée et maintenue longtemps . (A @Jigsaw20000 de nous aider à séparer cette partie du script pour autres utilisations). Essayez de vérifier les résultats à longue période : 2'500 unités ou 10'000 unités.
Bonjour, J'ai mis en Pièce jointe le fichier .ITF , vous pouvez l'importer directement dans la plateforme , souvent le copier/coller peut modifier le code en ne respectant pas les espace ou les sauts de ligne .
hello, i tryed to copy and past in prorealtime, but i got a lot of errors and undefinite parameters... did it happened also to you and than you fixed? tankyou
Bonjour , Merci pour le commentaire je prépare une version DAX en M15 , et en allégeant un peu le code , les VWAp monthly et Yearly ne servent à rien dans ce code et ralentissent pas mal les backtest . si vous le souhaitez vous pouvez déja les effacer du code .
Bonjour, Votre système a l'air intéressant et prometteur mais en l'état il est inutilisable tant il y a de bugs (sans doute à cause d'un souci de copier/coller). Vous serait-il possible de nous transmettre une version exploitable ? Merci par avance, Malloc