0bps

Strategy vault / Breakout

Long Breakout Range Trading Strategy

This is a trading strategy based on generating signals when price breaks out of a fixed lookback range. When price breaks above the highest high of the lookback period, long positions are taken; when price falls…

Author
ChaoZhang
Complexity
Starter · 30 lines
Parameters
2
Backtest bar
2h · intraday
Tested on
BTC/USDT · futures

Overview

This is a trading strategy based on generating signals when price breaks out of a fixed lookback range. When price breaks above the highest high of the lookback period, long positions are taken; when price falls below the high, positions are closed. Trade direction can be easily switched.

Strategy Logic

  1. Set lookback period parameter, e.g. 4 days.

  2. Calculate highest high of the past 4 days.

  3. Go long when today's high breaks out above this 4-day highest high.

  4. Close positions when price fails to break the 4-day highest high.

  5. Trade direction can be switched via the reverse parameter.

Advantage Analysis

Advantages of this strategy:

  1. Breakout is simple and signals are clear.

  2. Fixed breakout range avoids complex optimization and overfitting.

  3. Easily switch between long/short, adaptable to various market conditions.

  4. Lookback range filters noise for sustained trend tracking.

  5. No complex indicators required, efficient strategy.

Risk Analysis

Main risks:

  1. Fixed breakout range cannot adapt to market changes.

  2. No stop loss exposes strategy to excessive losses beyond risk tolerance.

  3. Fixed parameters vulnerable to market regime changes.

  4. Excessive noise trades may increase transaction costs.

  5. Lack of parameter optimization prevents achieving optimal results.

Optimization Directions

Improvements:

  1. Optimize key parameters to find best combinations.

  2. Introduce dynamic ranges based on ATR etc.

  3. Consider adding trailing stop loss or fixed percentage stop loss.

  4. Incorporate trend filter to avoid overtrading in ranging markets.

  5. Test parameter robustness across more trading instruments.

  6. Add machine learning for automatic parameter optimization.

Summary

Overall this is a very simple price breakout trading strategy. With enhancements like optimized parameter range, stop losses, trend filters and more, it can become an easy to implement and practical quantitative strategy.

Parameters

NameDefaultWhat it controls
v_input_14Look Bak
v_input_2falseTrade reverse

Source Pine Script

/*backtest
start: 2023-08-19 00:00:00
end: 2023-09-18 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version = 2
////////////////////////////////////////////////////////////
//  Copyright by HPotter v1.0 28/11/2016
// Breakout Range Long Strategy
// You can change long to short in the Input Settings
// Please, use it only for learning or paper trading. Do not for real trading.
////////////////////////////////////////////////////////////
strategy(title="Breakout Range Long Strategy Backtest", overlay = true)
look_bak = input(4, minval=1, title="Look Bak")
reverse = input(false, title="Trade reverse")
xHighest = highest(high, look_bak)
pos =	iff(high > xHighest[1], 1, 0)
if (pos == 1 and strategy.position_size == 0 and reverse == false) 
    strategy.entry("Long", strategy.long)
if (pos == 1 and strategy.position_size == 0 and reverse == true) 
    strategy.entry("Short", strategy.short)
if (pos == 0 and strategy.position_size > 0)
    strategy.close("Long")
if (pos == 0 and strategy.position_size < 0)
    strategy.close("Short")
barcolor(strategy.position_size > 0 ? green: strategy.position_size < 0 ? red: blue)   
plotshape(pos, style=shape.triangleup, location = location.belowbar, color = green)

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.

in Claude Code, Cursor, Codex & 4 more
/agenkit build a production-grade trading bot with a backtest engine, risk controls and paper trading by default from strategies/Long-Breakout-Range-Trading-Strategy.md
  1. npx agenkit install engineering-kit in your project
  2. Paste the command into your agent and approve each phase
  3. 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

esc

Try , , or .

↑↓ move↵ open