Breakout Strategy Based on Swing Highs and Lows
This article explains in detail a quantitative breakout trading strategy based on price swing highs and lows. It generates trading signals by identifying breaks of key price levels. I. Strategy Logic The main trading…
This article explains in detail a quantitative breakout trading strategy based on price swing highs and lows. It generates trading signals by identifying breaks of key price levels.
I. Strategy Logic
The main trading logic is:
Calculate the highest high and lowest low of recent 3 bars for current short-term swing.
Calculate highest high and lowest low of recent 50 bars for the near-term range.
A buy signal is generated when price breaks below the short-term low and lower than the near-term low.
A sell signal is generated when price breaks above the short-term high and higher than the near-term high.
Stop loss and take profit are set to control risks.
By identifying breaks of key levels, this can effectively detect new emerging trends.
II. Advantages of the Strategy
The main advantages are:
Firstly, the breakout rules are simple and easy to implement.
Secondly, stop loss and take profit settings directly control trade risks.
Lastly, backtest time ranges can be set for testing different periods.
III. Potential Weaknesses
However, some potential issues exist:
Firstly, breakouts alone may generate false signals, failing to determine trends accurately.
Secondly, the lack of parameter tuning leads to limited stability.
Lastly, stop loss and take profit levels require optimization for risk-reward.
IV. Summary
In summary, this article has explained a quantitative breakout trading strategy based on price swing highs and lows. It aims to discover opportunities through key level breaks. While the concept is simple and clear, improvements in parameter tuning are required. Overall it provides a unique breakout approach.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_1 | 10 | Stop Loss $ |
| v_input_2 | 100 | Profit Target $ |
| v_input_3 | true | Month |
| v_input_4 | 2021 | Year |
Source Pine Script
/*backtest
start: 2023-08-15 00:00:00
end: 2023-09-14 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("JetzGiantz Strategy", overlay=true)
// Getting inputs
StopTgt = input(10, minval=1, title="Stop Loss $")
ProfTgt = input(100, minval=1, title="Profit Target $")
//Filter backtest month and year
startMonth = input(1, minval=1, maxval=12, title="Month")
startYear = input(2021, minval=2000, maxval=2100, title="Year")
//Filter funtion inputs
//Calculations
Low3 = lowest(low,3)
Low50 = lowest(low,50)
High3 = highest(high,3)
High50 = highest(high,50)
if (month>=startMonth and year>=startYear)
if(close[1] < open[1] and close > open and close > open[1] and (Low3 < Low50[1] or Low3 < Low50[2] or Low3 < Low50[3]))
strategy.order("BuyEntry", strategy.long, when=strategy.position_size == 0, comment="BuyEntry")
if (month>=startMonth and year>=startYear)
if(close[1] > open[1] and close < open and close > open[1] and (High3 > High50[1] or High3 > High50[2] or High3 > High50[3]))
strategy.order("SellEntry", strategy.short, when=strategy.position_size == 0, comment="SellEntry")
strategy.exit("bracket", loss=StopTgt, profit=ProfTgt, when=strategy.position_size > 0)
strategy.exit("bracket", loss=StopTgt, profit=ProfTgt, when=strategy.position_size < 0)
Published by ChaoZhang on the FMZ strategy square · last modified 2023-09-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/Breakout-Strategy-Based-on-Swing-Highs-and-Lows.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
- 5 Day Moving Average Channel Breakout Strategy Combined With Mileage ConceptPine Script · Breakout · 1d
- ATR Trailing Stops StrategyPine Script · Breakout · 1h
- ATR Trend Breakout StrategyPine Script · Breakout · 1d
- Adaptive Bollinger Breakout with Moving Average Quantitative Strategy SystemPine Script · Breakout · 1h
- Adaptive Channel Breakout StrategyPine Script · Breakout · 1d
- Adaptive Multi Period Trading Strategy Based on Wave Trend Momentum BreakoutPine Script · Breakout · 2h