Bonjour à tous,
Vous souvenez-vous de mon « Code HARAMI sur l’EUR/USD en graphes D1 » ?
.
Grâce à l’intervention de Pierre, voici un code « Harami » pour l’USD/SEK en graphes H4.
La stratégie est profitable à partir de 2016 (probablement en raison des optimisations de variables effectuées).
Pour le backtest, un spread de 4 points a été considéré (je ne suis pas sûr de cette valeur, à vérifier chez IG Markets).
.

.
Même Backtest avec 25 pips de spread :
Détails conditions forex :

.
.
Voici le code du BACKTEST :
Defparam cumulateorders = False // Variables n = 4 EMA50 = exponentialaverage[40](close) EMA20 = exponentialaverage[25](close) SPT3 = supertrend[3,10] Kijun = (highest[26](close)+lowest[26] (close))/2 //atr=averagetruerange[14](close)*10000 //Condition timing IF dayofweek>0 and dayofweek <5 THEN ctime=1 ELSE ctime=0 ENDIF // Définition du Harami c1= high[0] < high[1] c2= low[0] > low[1] harami = c1 and c2 //Test tendance If close>ema50 and close >spt3 AND close >kijun and ema20>ema20[1] THEN trend=1 ELSIF close<ema50 and close <spt3 AND close <kijun and ema20<ema20[1] THEN trend=-1 ELSE trend=0 ENDIF // Prise de position IF harami AND trend=1 AND close < open AND ctime=1 THEN buy n contracts at market set stop ploss 400 set target pprofit 450 ELSIF harami and trend=-1 AND close >open AND ctime=1 THEN sellshort n shares at market set stop ploss 400 set target pprofit 500 ENDIF // Clôture IF longonmarket AND barindex - tradeindex = 8 THEN sell at market ELSIF shortonmarket AND barindex - tradeindex = 3 THEN exitshort at market ENDIF // Remontée du stop IF longonmarket AND (close - tradeprice) >0.015 AND barindex - tradeindex >1 then set stop ploss 100 ENDIF IF shortonmarket AND (-close + tradeprice) >0.02 AND barindex - tradeindex >1 then set stop ploss 50 ENDIF // Sortie avant le weekend IF dayofweek=5 AND time=220000 AND onmarket then sell at market exitshort at market ENDIF
.
MISE A JOUR : 02/11/2019
Code « V2 »

.
Voici le code du BACKTEST « V2 » :
Defparam cumulateorders = False // Variables n = 1 EMA50 = exponentialaverage[25](close) EMA20 = exponentialaverage[35](close) SPT3 = supertrend[2.5,10] Kijun = (highest[26](close)+lowest[26](close))/2 //Condition timing IF dayofweek >1 and dayofweek <5 THEN ctimeV=1 ctimeA=1 ELSE IF dayofweek=1 THEN ctimeA=1 ctimeV=0 ELSE ctimeA=0 ctimeV=0 ENDIF ENDIF // Définition du Harami c1= high[0] < high[1] c2= low[0] > low[1] harami = c1 and c2 //Test tendance IF close>ema50 and close >spt3 and close >kijun and ema20>ema20[1] THEN trend=1 ELSIF close<ema50 and close <spt3 and close <kijun and ema20<ema20[1] THEN trend=-1 ELSE trend=0 ENDIF // Prise de position IF harami and trend=1 and close < open and ctimeA=1 THEN buy n contracts at market set stop ploss 400 set target pprofit 450 ELSIF harami and trend=-1 and close >open and ctimeV=1 THEN sellshort n shares at market set stop ploss 450 set target pprofit 500 ENDIF // Clôture IF longonmarket and barindex - tradeindex = 9 THEN sell at market ELSIF shortonmarket and barindex - tradeindex = 3 THEN exitshort at market ENDIF // Remontée du stop IF NOT ONMARKET THEN breakevenLevel = 0 ENDIF IF LONGONMARKET AND close - tradeprice >= 0.04 THEN breakevenLevel = tradeprice + 0.025 ENDIF IF breakevenLevel > 0 THEN SELL AT breakevenLevel STOP ENDIF IF ShortONMARKET AND tradeprice - close >= 0.025 THEN IF breakevenLevel=0 then breakevenLevel = tradeprice - 0.02 ENDIF ENDIF IF breakevenLevel > 0 THEN exitshort AT breakevenLevel STOP ENDIF // Sortie avant le weekend IF dayofweek=5 and time>=200000 and onmarket THEN sell at market exitshort at market ENDIF