Momentum Breakout Backtesting Support Resistance Strategy
This strategy mainly uses the previous trading day's high, low and close prices as the support and resistance levels for the current day. It goes long when the resistance level is broken and goes short when the…

Overview
This strategy mainly uses the previous trading day's high, low and close prices as the support and resistance levels for the current day. It goes long when the resistance level is broken and goes short when the support level is backtested. It belongs to a typical breakout strategy.
Strategy Principle
The code first defines a function calculateSupportResistance to calculate the support and resistance levels, which extracts the previous trading day's high, low and close prices as the current day's support and resistance levels.
Then in the main logic, this function is called to get these three price levels and plot them.
In the backtesting logic, if the close price is lower than the previous day's low while the current price is higher than that low forming a breakout, it goes long. If the close price is higher than the previous day's high while the current price is lower than that high forming a breakout, it goes short.
Through this breakout model, the judgment of trend and generation of trading signals are implemented.
Advantages
Use previous trading day's data to build current day's support and resistance levels, avoiding the parameter optimization problem
Support and resistance levels come from real market trading data, with some reference value
Simple and straightforward backtesting model, easy to understand and implement
Visual display of support and resistance levels forms perception of prices
Real-time monitoring of breakouts, timely catching trading opportunities
Risks
Support and resistance levels change over time, hard to determine validity
Unable to predict trend direction, risk of missing reversals
Easily affected by false breakouts, premature entry risk
Unable to determine persistence of breakouts, early stop loss likely
Individual support and resistance failure more likely under huge market fluctuation
Countermeasures:
Combine more factors to judge validity of breakouts
Appropriately expand stop loss range to catch trends
Open positions in batches, reduce impact of individual fluctuations
Optimizations
Add more historical data like 5-day, 10-day lines to determine levels
Incorporate other indicators like volume to judge breakout validity
Set stop loss based on actual volatility
Optimize capital management, control single loss
Summary
Overall this is a typical breakout strategy, simple and intuitive. By building current day's support and resistance with previous day's data and backtesting breakouts of those levels for long/short. Pros are easy to understand and directly visualize levels; cons are false breakout risks and uncertainty of persistence. Next steps are improving breakout validity, controlling risks, optimizing capital management etc.
Source Pine Script
/*backtest
start: 2024-01-22 00:00:00
end: 2024-02-21 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Support and Resistance with Backtesting", overlay=true)
// Function to calculate support and resistance levels
calculateSupportResistance() =>
highPrevDay = request.security(syminfo.tickerid, "D", high[1], lookahead=barmerge.lookahead_on)
lowPrevDay = request.security(syminfo.tickerid, "D", low[1], lookahead=barmerge.lookahead_on)
closePrevDay = request.security(syminfo.tickerid, "D", close[1], lookahead=barmerge.lookahead_on)
[highPrevDay, lowPrevDay, closePrevDay]
// Call the function to get support and resistance levels
[supResHigh, supResLow, supResClose] = calculateSupportResistance()
// Plotting support and resistance levels
plot(supResHigh, color=color.red, linewidth=2, title="Previous Day High")
plot(supResLow, color=color.green, linewidth=2, title="Previous Day Low")
plot(supResClose, color=color.blue, linewidth=2, title="Previous Day Close")
// Backtesting logic
backtestCondition = close[1] < supResLow and close > supResLow
strategy.entry("Long", strategy.long, when=backtestCondition)
// Plotting buy/sell arrows for backtesting
plotarrow(backtestCondition ? 1 : na, colorup=color.green, offset=-1, transp=0)
Published by ChaoZhang on the FMZ strategy square · last modified 2024-02-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/Momentum-Breakout-Backtesting-Support-Resistance-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
- Bollinger Bands Breakout Trading StrategyPine Script · Breakout · 1h
- Bollinger Bands Dynamic Breakout StrategyPine Script · Breakout · 1h
- Cross period Value Area Breakout StrategyPine Script · Breakout · 1d
- Donchian Channel Breakout Strategy 442842Pine Script · Breakout · 4h
- Dynamic Support Resistance Breakout Moving Average Crossover StrategyPine Script · Breakout · 1d
- Dynamic Support and Resistance Adaptive Pivot Trading StrategyPine Script · Breakout · 1d