The Harami Closing Price strategy is a quantitative trading strategy based on candlestick patterns. This strategy identifies “Harami” patterns to generate buy and sell signals.
The core logic is: When the current candlestick is a red candle and the previous one is a green candle, and the current candle’s lowest price is higher than the previous candle’s lowest price, the current candle’s highest price is lower than the previous candle’s highest price, the “Harami” pattern is formed. This means the uptrend momentum is losing strength and it is a signal for selling. On the contrary, a “Harami” pattern with two candles inverted constitutes a buy signal.
The average of the candle body is used as a stop loss line. When the body is larger than half the stop loss line, stop loss triggers.
The main advantages of the Harami Closing Price strategy are:
There are also some risks for this strategy:
To mitigate these risks, combining with trading volume, moving averages and other technical indicators is recommended, to make more comprehensive judgments on market trends. The stop loss line can also be dynamically adjusted based on market volatility.
The Harami Closing Price strategy can also be improved from the following aspects:
The Harami Closing Price strategy is easy to understand and implement for generating certain buy and sell signals based on candlestick patterns. But it also has some limitations like generating false signals and blindness. These problems also point to directions for further optimizations, by applying more comprehensive judgments with trading volumes, multiple timeframes, and other technical indicators. This can greatly enhance the strategy’s efficacy.
/*backtest start: 2023-11-20 00:00:00 end: 2023-11-27 00:00:00 period: 10m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //Noro //2018 //@version=3 strategy(title = "Noro's Harami Strategy v1.0", shorttitle = "Harami str 1.0", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0) //Settings needlong = input(true, defval = true, title = "Long") needshort = input(false, defval = false, title = "Short") fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year") toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year") frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month") tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month") fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day") today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day") //Body body = abs(close - open) abody = sma(body, 10) //MinMax Bars min = min(close, open) max = max(close, open) bar = close > open ? 1 : close < open ? -1 : 0 //Signals up = bar == 1 and bar[1] == -1 and min > min[1] and max < max[1] dn = bar == -1 and bar[1] == 1 and min > min[1] and max < max[1] exit = ((strategy.position_size > 0 and bar == 1) or (strategy.position_size < 0 and bar == -1)) and body > abody / 2 //Trading if up if strategy.position_size < 0 strategy.close_all() strategy.entry("Long", strategy.long, needlong == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59))) if dn if strategy.position_size > 0 strategy.close_all() strategy.entry("Short", strategy.short, needshort == false ? 0 : na, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59))) if time > timestamp(toyear, tomonth, today, 23, 59) or exit strategy.close_all()