I originally found this code on internet.
To go “long” : when meeting a Harami with a black (or red) candle above the 50 days moving average, we buy the next day at the opening.
We close days later, no matter what happens !
The procedure is the opposite for the “short” trades.
The strategy is profitable on EUR/USD.
WARNING :
The test exclude Sunday candles (included in Mondays).
If you view the candle of Sunday (from 23H to 00H), then the test will be completely distorted !
This code is certainly not a panacea, but it deserves to be refined and improved, no doubt.
DEFPARAM CUMULATEORDERS = false
n = 15
MM50 = average[50](close)
REM Définition du Harami
c1= high[0] < high[1]
c2= low[0] > low[1]
harami = c1 and c2
// Prise de position
IF harami and close > MM50 and close < open THEN
buy n shares at market nextbaropen
ENDIF
IF harami and close < MM50 and close > open THEN
sellshort n shares at market nextbaropen
ENDIF
// Clôture
IF barindex - tradeindex = 1 THEN
sell at market
exitshort at market
ENDIF