Strategy vault / Mean reversion
Bullish Harami Reversal Strategy
This strategy identifies "bullish harami" candlestick patterns for bullish reversal trades. Specifically, long signals are generated when: 1. Current candle has a small body that is engulfed by the large previous…
This strategy identifies "bullish harami" candlestick patterns for bullish reversal trades. Specifically, long signals are generated when:
- Current candle has a small body that is engulfed by the large previous bearish body
- Current candle body color is opposite of previous candle
- Current candle opens higher than previous candle's close
- Current candle body is smaller than previous candle's body
When these conditions are met, it signifies bullish reversal momentum, at which point a long entry is taken. Stop loss and take profit exits are set after entry.
The advantage of this strategy is it uses classical candlestick patterns to identify reversal points visually. However, some limitations exist:
- Bullish harami may not sustain, risks being reversed
- Difficulty in accurately identifying candlestick patterns, requires optimization
- Lagging signals, poor entry timing
- Backtest curve fitting risk is high
Overall, the bullish harami reversal strategy can serve as a reference for trend analysis, but should be applied cautiously in live trading. Parameters should be loosened and combined with other indicators for pattern verification. Also, strict risk management is key to successfully implementing this strategy.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 60 | Take Profit pip |
| v_input_2 | 18 | Stop Loss pip |
| v_input_3 | true | Min. Size Body pip |
Source Pine Script
/*backtest
start: 2023-01-01 00:00:00
end: 2023-09-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
////////////////////////////////////////////////////////////
// Copyright by HPotter v1.0 18/01/2019
// This is a bullish reversal pattern formed by two candlesticks in which a small
// real body is contained within the prior session's unusually large real body.
// Usually the second real body is the opposite color of the first real body.
// The Harami pattern is the reverse of the Engulfing pattern.
//
// WARNING:
// - For purpose educate only
// - This script to change bars colors.
////////////////////////////////////////////////////////////
strategy(title = "Bullish Harami Backtest", overlay = true)
input_takeprofit = input(60, title="Take Profit pip")
input_stoploss = input(18, title="Stop Loss pip")
input_minsizebody = input(1, title="Min. Size Body pip", step = 0.01)
barcolor(abs(close - open) >= input_minsizebody ? open[1] > close[1] ? close > open ? close <= open[1] ? close[1] <= open ? close - open < open[1] - close[1] ? yellow :na :na : na : na : na : na)
pos = 0.0
barcolor(nz(pos[1], 0) == -1 ? red: nz(pos[1], 0) == 1 ? green : blue )
posprice = 0.0
posprice := abs(close - open) >= input_minsizebody? open[1] > close[1] ? close > open ? close <= open[1] ? close[1] <= open ? close - open < open[1] - close[1] ? close :nz(posprice[1], 0) :nz(posprice[1], 0) : nz(posprice[1], 0) : nz(posprice[1], 0) : nz(posprice[1], 0): nz(posprice[1], 0)
pos := iff(posprice > 0, 1, 0)
if (pos == 0)
strategy.close_all()
if (pos == 1)
strategy.entry("Long", strategy.long)
posprice := iff(low <= posprice - input_stoploss and posprice > 0, 0 , nz(posprice, 0))
posprice := iff(high >= posprice + input_takeprofit and posprice > 0, 0 , nz(posprice, 0))Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-11. Collected in the Quant Trading Vault. Unvalidated research: re-test with your own data and costs before trusting it.
Build this with AgenKit
A spec is not a trading system. Paste this into your coding agent and AgenKit runs a specialist team — architecture, test-first build, risk gates, review — with paper trading on by default.
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Bullish-Harami-Reversal-Strategy.md- npx agenkit install engineering-kit in your project
- Paste the command into your agent and approve each phase
- Get tests, backtest, risk controls and a paper-trading switch
Understand it first
Before you run this, read the lesson behind the idea and how to backtest it honestly. Specs like this one are the survivors of an unknown number of trials; deflate their results accordingly.
Related specs
- 1 2 3 Pattern Quantitative Trading Strategy with EMAs MACD and 4th Candle ExtensionPine Script · Mean reversion · 1h
- 3 10 Oscillator Profile Flagging StrategyPine Script · Mean reversion · 1d
- A Trend Reversal Strategy Based on Moving Averages Price Patterns and VolumePine Script · Mean reversion · 1d
- ATR and EMA based Dynamic Take Profit and Stop Loss Adaptive StrategyPine Script · Mean reversion · 1h
- Adaptive Mean Reversion Trading Strategy Based on Chande Momentum OscillatorPine Script · Mean reversion · 1d
- Adaptive Moving Average Tracking StrategyPine Script · Mean reversion · 1d