Trend Breakout Long Shadow Strategy
This strategy judges the current trend direction by calculating the ratio of bullish/bearish shadow length, and identifies trend with ATR indicator. It opens reverse position on breakout points and sets stop loss and…

This strategy judges the current trend direction by calculating the ratio of bullish/bearish shadow length, and identifies trend with ATR indicator. It opens reverse position on breakout points and sets stop loss and take profit to capture short-term trends.
Strategy Logic
The strategy mainly judges the current trend by calculating bullish/bearish shadow ratio. Long bearish indicates downward trend while long bullish indicates upward trend.
The specific logic is:
- Calculate bearish shadow: close - low
- Calculate bullish shadow: high - open
- Take the max of bearish and bullish shadow as shadow length
- Calculate candle body length: high - low
- Calculate ratio between shadow and body length
- If ratio > 0.5 and bearish > bullish, judge downward trend and long position
- If ratio > 0.5 and bullish > bearish, judge upward trend and short position
- Validate breakout with candle length > 0.75 * ATR
- Set stop loss and take profit after entry, with 2:1 ratio
The above is the basic trading logic, identifying reverse breakout points with trend detection and optimizing profit with stop loss/take profit.
Advantages
- Shadow ratio accurately judges the trend
- ATR filters out false breakout signals
- Stop loss and take profit manages risk
- 2:1 risk-reward ratio meets quant trading standard
- Suitable for short-term trading on high volatility stocks
- Simple and clear logic, easy to understand
Risks
- Price volatility may hit stop loss and increase loss
- Performance relies heavily on parameter tuning
- Trend reversal may lead to loss
- Expanding stop loss/take profit may increase loss probability
- Failed breakout can lead to large loss
Risks can be managed by reasonable stop loss, parameter optimization, and timely position exit.
Enhancement
The strategy can be optimized in the following ways:
- Optimize shadow ratio parameter for best value
- Optimize ATR parameter for best candle length
- Optimize stop loss/take profit coefficients for optimal risk-reward
- Add position sizing like gradual position increase
- Add trailing stop loss for profit protection
- Add other indicators to filter signals
- Optimize backtest time period and test different market stages
With multi-faceted testing and optimization, the strategy performance can be maximized.
Overall, this strategy profits from short-term price swings through trend identification and risk management. When optimized, it can become a robust short-term breakout strategy for quant trading.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 2020 | Backtest Start Year |
| v_input_2 | true | Backtest Start Month |
| v_input_3 | true | Backtest Start Day |
| v_input_4 | 2025 | Backtest End Year |
| v_input_5 | true | Backtest End Month |
| v_input_6 | true | Backtest End Day |
| v_input_7 | 0.8 | N - % offset for N*SL and (2N)*TP |
Source Pine Script
/*backtest
start: 2022-11-08 00:00:00
end: 2023-11-14 00:00:00
period: 1d
basePeriod: 1h
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/
// © ondrej17
//@version=4
strategy("longWickstrategy", overlay=true )
// Inputs
st_yr_inp = input(defval=2020, title='Backtest Start Year')
st_mn_inp = input(defval=01, title='Backtest Start Month')
st_dy_inp = input(defval=01, title='Backtest Start Day')
en_yr_inp = input(defval=2025, title='Backtest End Year')
en_mn_inp = input(defval=01, title='Backtest End Month')
en_dy_inp = input(defval=01, title='Backtest End Day')
sltp_inp = input(defval=0.8, title='N - % offset for N*SL and (2N)*TP')/100
// Dates
start = timestamp(st_yr_inp, st_mn_inp, st_dy_inp,00,00)
end = timestamp(en_yr_inp, en_mn_inp, en_dy_inp,00,00)
canTrade = time >= start and time <= end
// Indicators Setup
// Strategy Calcuations
lowerWick = (open > close) ? close-low : open - low
upperWick = (open > close) ? high-open : high-close
wickLength = max(lowerWick,upperWick)
candleLength = high-low
wickToCandleRatio = wickLength / candleLength
entryFilterCandleLength = candleLength > 0.75*atr(48)
// Entries and Exits
longCondition = entryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick > upperWick and canTrade and strategy.position_size == 0
shortCondition = entryFilterCandleLength and wickToCandleRatio > 0.5 and lowerWick < upperWick and canTrade and strategy.position_size == 0
strategy.entry("pendingLong", strategy.long, limit=low+wickLength/2, when = longCondition)
strategy.entry("pendingShort", strategy.short, limit=high-wickLength/2, when = shortCondition)
longStop = strategy.position_size > 0 ? strategy.position_avg_price*(1-sltp_inp) : na
longTP = strategy.position_size > 0 ? strategy.position_avg_price*(1+2*sltp_inp) : na
shortStop = strategy.position_size < 0 ? strategy.position_avg_price*(1+sltp_inp) : na
shortTP = strategy.position_size < 0 ? strategy.position_avg_price*(1-2*sltp_inp) : na
strategy.exit("longSLTP","pendingLong", stop=longStop, limit = longTP)
strategy.exit("shortSLTP","pendingShort", stop=shortStop, limit = shortTP)
plot(longStop, color=color.red, style=plot.style_linebr, linewidth=2)
plot(shortStop, color=color.red, style=plot.style_linebr, linewidth=2)
plot(longTP, color=color.green, style=plot.style_linebr, linewidth=2)
plot(shortTP, color=color.green, style=plot.style_linebr, linewidth=2)
plotLongCondition = longCondition ? high+abs(open-close) : na
plot(plotLongCondition, style=plot.style_circles, linewidth=4, color=color.green)
plotShortCondition = shortCondition ? high+abs(open-close) : na
plot(plotShortCondition, style=plot.style_circles, linewidth=4, color=color.red)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-11-15. 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/Trend-Breakout-Long-Shadow-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
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Advanced Multi Pattern Breakout Trading StrategyPine Script · Breakout · 1d
- BB Breakout StrategyPine Script · Breakout · 1d
- Bollinger Band Breakout Trend Following StrategyPine Script · Breakout · 1d
- Breakout Strategy Based on Turtle TradingPine Script · Breakout · 1d