Strategy vault / Mean reversion
Reverse Opening Engulfing Strategy
The Reverse Opening Engulfing Strategy is a simple intraday trading strategy based on the first candlestick after the opening. The core idea of this strategy is to judge the uptrend or downtrend of the first…

Overview
The Reverse Opening Engulfing Strategy is a simple intraday trading strategy based on the first candlestick after the opening. The core idea of this strategy is to judge the uptrend or downtrend of the first candlestick when it appears after the opening every day, and take counter operations. If the first candlestick is a red yang line, go long; if the first candlestick is a green yin line, go short. The strategy also sets up stop loss and take profit mechanisms for exiting positions.
Strategy Logic
The principle behind this strategy is the peculiarity of the first candlestick after opening. When the market opens, the forces of longs and shorts confront most intensely, and the probability of a reversal is relatively large. Judging the uptrend or downtrend of the first candlestick and taking counter operations is the core idea of this strategy.
Specifically, after the opening of a new day, the strategy will record the opening price, closing price and price change of the first candlestick. If the opening price is higher than the closing price (green yin line), it means the bears have won and we should long; if the opening price is lower than the closing price (red yang line), it means the bulls have won and we should short. By taking such counter operations, the strategy attempts to capture reversal opportunities after opening.
Meanwhile, the strategy also sets up stop loss and take profit mechanisms, including long stop loss price, long take profit price, short stop loss price and short take profit price, to control risks and profits of long and short positions, avoiding excessive losses or premature profit taking.
Advantage Analysis
The Reverse Opening Engulfing Strategy has the following advantages:
- The logic is simple and clear, easy to understand and implement.
- It utilizes the high predictive value of the opening segment to capture reversal opportunities.
- The stop loss and take profit settings can effectively control risks.
- The strategy idea has universality and is suitable for most stocks.
- The participation cost is relatively low and capital control is easy.
Risk Analysis
The Reverse Opening Engulfing Strategy also has some risks, mainly including:
- Probability of opening reversal failure. A failed reversal signal of the first candlestick may cause huge losses.
- Inability to effectively filter low-quality stocks. The strategy lacks sufficient fundamental analysis and may pick some stocks with poor fundamentals.
- Inability to effectively control systemic risks from black swan events, such as the impact of significantly negative news.
- Improper stop loss and take profit settings may lead to magnified losses or narrowed profits.
Optimization Directions
The Reverse Opening Engulfing Strategy can be optimized in the following aspects:
- Increase the validity test of opening reversal signals to avoid invalid signals, for example, combine volume analysis.
- Select stock pools by integrating fundamental and technical analysis to filter low-quality stocks.
- Add monitoring modules for major events and news to control systemic risks.
- Use genetic algorithms, machine learning and other methods to dynamically optimize stop loss and take profit settings.
Summary
The Reverse Opening Engulfing Strategy attempts to capture reversal opportunities after opening by judging the direction of the first candlestick and taking counter operations. The strategy idea is simple with low participation costs, and has some practical value. But we should also be soberly aware of the risks, and constantly improve and optimize the strategy in practice to make it more robust and reliable.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 0915-1455 | Market session |
| v_input_2 | true | Long Take Profit (%) |
| v_input_3 | true | Short Take Profit (%) |
| v_input_4 | 0.5 | Long Stop Loss (%) |
| v_input_5 | 0.5 | Short Stop Loss (%) |
Source Pine Script
/*backtest
start: 2023-10-22 00:00:00
end: 2023-11-21 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vikris
//@version=4
strategy("[VJ]First Candle Strategy", overlay = true,calc_on_every_tick = true,default_qty_type=strategy.percent_of_equity,default_qty_value=100,initial_capital=750,commission_type=strategy.commission.percent,
commission_value=0.02)
// ********** Strategy inputs - Start **********
// Used for intraday handling
// Session value should be from market start to the time you want to square-off
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session,
defval="0915-1455", confirm=true)
// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
shortProfitPerc = input(title="Short Take Profit (%)",
type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01
shortLossPerc = input(title="Short Stop Loss (%)",
type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01
// ********** Strategy inputs - End **********
// ********** Supporting functions - Start **********
// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0
// Figure out take profit price
longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)
// Determine stop loss price
longStopPrice = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)
// ********** Supporting functions - End **********
// ********** Strategy - Start **********
// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)
// Trade only if intraday session is active
//=================Strategy logic goes in here===========================
// If start of the daily session changed, then it's first bar of the new session
isNewDay = time("D") != time("D")[1]
var firstBarCloseValue = close
var firstBarOpenValue = open
if isNewDay
firstBarCloseValue := close
firstBarOpenValue := open
greenCandle = firstBarOpenValue < firstBarCloseValue
redCandle = firstBarOpenValue > firstBarCloseValue
buy = redCandle
sell = greenCandle
// plot(firstBarCloseValue)
// plot(firstBarOpenValue)
//Final Long/Short Condition
longCondition = buy
shortCondition =sell
//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
stop_level = longStopPrice
profit_level = longExitPrice
strategy.entry("My Long Entry Id", strategy.long)
strategy.exit("TP/SL", "My Long Entry Id", stop=stop_level, limit=profit_level)
//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
stop_level = shortStopPrice
profit_level = shortExitPrice
strategy.entry("My Short Entry Id", strategy.short)
strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")
// ********** Strategy - End **********Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-22. 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/Reverse-Opening-Engulfing-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