Strategy vault / Mean reversion
Gap Down Reversal Strategy
This strategy trades gap down reversals. When the current candle opens below the prior close and finishes up on the day with a close greater than the open, the strategy enters long on the next day's open or close.
Overview
This strategy trades gap down reversals. When the current candle opens below the prior close and finishes up on the day with a close greater than the open, the strategy enters long on the next day's open or close.
Strategy Principle
Check if a gap down occurs, i.e. current open below prior close.
If gapped down, observe if the current close is above the open, indicating an upside reversal.
If gap down reversal conditions are met, go long on the next day's open or close.
Set a trailing stop loss at a percentage, e.g. 5%, after entry. The stop level moves up with the price.
When price drops to hit the stop loss, the position is closed.
Advantage Analysis
Main advantages of this strategy:
Captures reversal trading opportunities from gap down patterns.
High probability reversal pattern aligns with alternating fear/greed.
Trailing stop locks in profits without needing manual monitoring.
Flexible settings for entry and stop loss to suit individual stocks.
Automated execution and easy backtesting/optimization.
Risk Analysis
Main risks of this strategy:
Failed gap down reversals can occur, need pattern verification.
Oversized stop loss prone to being taken out leading to amplified losses.
Poor stock selection may lead to hard reversals.
Insufficient backtest data leads to overfit risks.
Execution differs between backtest and live.
Solutions:
Optimize stop loss level and cap loss percentage per trade.
Gauge overall market trend to avoid topping stocks.
Verify pattern and volume changes.
Expand sample size for backtest, simulate live trading.
Optimization Directions
Some ways to improve the strategy:
Add trend filter to avoid countertrend entries.
Dynamically adjust stop loss percentage to protect profits.
Consider adding time filter to trade on specific dates.
Assess strength of pattern for position sizing.
Test different holding periods to find optimal exit spots.
Summary
The gap down reversal strategy capitalizes on high probability reversal patterns. Stops effectively control risk but beware of false bounces and changing market conditions. When trading live, cautious evaluation of patterns and trends along with ongoing optimizations are recommended.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | true | Start Date |
| v_input_2 | true | Start Month |
| v_input_3 | 2009 | Start Year |
| v_input_4 | 5 | Trail Long Loss (%) |
Source Pine Script
/*backtest
start: 2023-09-11 00:00:00
end: 2023-09-12 04:00:00
period: 1m
basePeriod: 1m
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/
// © RolandoSantos
//@version=2
strategy(title="Gap Down reversal strat", overlay=true, pyramiding=1, default_qty_type = strategy.cash, default_qty_value = 10000, initial_capital = 10000 )
/// Start date
startDate = input(title="Start Date", defval=1, minval=1, maxval=31)
startMonth = input(title="Start Month", defval=1, minval=1, maxval=12)
startYear = input(title="Start Year", defval=2009, minval=1800, maxval=2100)
// See if this bar's time happened on/after start date
afterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))
// STEP 1:
// Configure trail stop level with input options (optional)
longTrailPerc = input(title="Trail Long Loss (%)",
type=float, minval=0.0, step=0.1, defval=5.0) * 0.01
// Calculate trading conditions
gap_d_r = open < close[1] and close > open
// Plot Shapes
plotshape(gap_d_r, style=shape.triangleup, location=location.belowbar)
///plotshape(gap_u_r, style=shape.triangledown, location=location.abovebar)
///// Use Low, or close/////
//hlco = input(title="Stop Modifier", defval="close", options=["open", "high", "low"])
// STEP 2:
// Determine trail stop loss prices
longStopPrice = 0.0 ///, shortStopPrice = 0.0
longStopPrice := if (strategy.position_size > 0)
stopValue = close * (1 - longTrailPerc)
max(stopValue, longStopPrice[1])
else
0
// Plot stop loss values for confirmation
plot(series=(strategy.position_size > 0) ? longStopPrice : na,
color=red, style=circles,
linewidth=1, title="Long Trail Stop")
// Submit entry orders
if (afterStartDate and gap_d_r)
strategy.entry(id="EL", long=true)
// Submit exit orders for trail stop loss price
if (strategy.position_size > 0)
strategy.exit(id="Stop out", stop=longStopPrice)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-19. 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/Gap-Down-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