0bps

Strategy vault / Breakout

ATR Channel Breakout Trend following Strategy

This strategy utilizes the ATR channel and breakout theory to follow trends by entering when the channel is broken. It belongs to trend-following strategies. The strategy is simple and easy to understand, using…

Author
ChaoZhang
Complexity
Intermediate · 93 lines
Parameters
2
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy utilizes the ATR channel and breakout theory to follow trends by entering when the channel is broken. It belongs to trend-following strategies. The strategy is simple and easy to understand, using moving average channels and ATR indicators to determine trend direction and issuing trading signals at key points.

Principle

This strategy constructs upper and lower bands with high, low, close prices and ATR indicator to form an ATR channel. The channel width is determined by the ATR parameter size. When the price breaks through the channel, it is judged as the beginning of a trend, at which points long or short positions are entered. The strategy has two tiers of trading signals. When the price breaks through one ATR width, it is considered as an emerging trend, triggering the first tier of buy/sell points. When the price breaks through two ATR widths, it is considered an accelerating trend, triggering the second tier of buy/sell points.

Advantage Analysis

The main advantages of this strategy are:

  1. Using ATR indicators to construct channels considers market volatility better than simple moving averages.
  2. The two-tier buy/sell points allow staged entry with controllable risks.
  3. Breakout theory accurately locates key trend points.
  4. The concise code is easy to understand and implement.

Risk Analysis

The main risks of this strategy are:

  1. Reliance on a single indicator means high failure probability if ATR fails.
  2. Lack of stop loss and position management leads to insufficient risk control.
  3. Utility needs verification and may underperform in live trading conditions.
  4. Improper parameters may cause whipsaws or overtrading.

Optimization Directions

The optimization directions for this strategy include:

  1. Adding filters with multiple indicators to prevent misjudgments.
  2. Adding stop loss modules to enhance risk control.
  3. Adding position control and money management.
  4. Parameter tuning for different products.
  5. Reducing trading frequency and position sizing for live trading.

Summary

The overall framework of this strategy is clear and usable as a proof of concept. But there are gaps from live trading that allow substantial optimizations. If risk controls and trading frequencies can be further improved, the application prospects would be good.

Parameters

NameDefaultWhat it controls
v_input_timeframe_160TimeFrame
v_input_int_160ATR length

Source Pine Script

/*backtest
start: 2023-12-03 00:00:00
end: 2024-01-02 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Myhaj_Lito

//@version=5
strategy("Renko Trend Strategy",shorttitle = "RENKO-Trend str.",overlay = true)
TF = input.timeframe(title='TimeFrame', defval="60")
ATRlength = input.int(title="ATR length", defval=60, minval=2, maxval=1000)

HIGH = request.security(syminfo.tickerid, TF, high)
LOW = request.security(syminfo.tickerid, TF, low)
CLOSE = request.security(syminfo.tickerid, TF, close)
ATR = request.security(syminfo.tickerid, TF, ta.atr(ATRlength))


RENKOUP = float(na)
RENKODN = float(na)
H = float(na)
COLOR = color(na)
BUY = int(na)
SELL = int(na)
UP = bool(na)
DN = bool(na)
CHANGE = bool(na)

RENKOUP := na(RENKOUP[1]) ? (HIGH + LOW) / 2 + ATR / 2 : RENKOUP[1]
RENKODN := na(RENKOUP[1]) ? (HIGH + LOW) / 2 - ATR / 2 : RENKODN[1]
H := na(RENKOUP[1]) or na(RENKODN[1]) ? RENKOUP - RENKODN : RENKOUP[1] - RENKODN[1]
COLOR := na(COLOR[1]) ? color.white : COLOR[1]
BUY := na(BUY[1]) ? 0 : BUY[1]
SELL := na(SELL[1]) ? 0 : SELL[1]
UP := false
DN := false
CHANGE := false

// calculating 
if not CHANGE and close >= RENKOUP[1] + H * 2
    CHANGE := true
    UP := true
    RENKOUP := RENKOUP[1] + ATR * 2
    RENKODN := RENKOUP[1] + ATR
    COLOR := color.rgb(0, 255, 170,60)
    SELL := 0
    BUY += 2
    BUY


if not CHANGE and close >= RENKOUP[1] + H
    CHANGE := true
    UP := true
    RENKOUP := RENKOUP[1] + ATR
    RENKODN := RENKOUP[1]
    COLOR := color.rgb(0, 230, 38,60)
    SELL := 0
    BUY += 1
    BUY

if not CHANGE and close <= RENKODN[1] - H * 2
    CHANGE := true
    DN := true
    RENKODN := RENKODN[1] - ATR * 2
    RENKOUP := RENKODN[1] - ATR
    COLOR := color.rgb(255, 92, 43,60)
    BUY := 0
    SELL += 2
    SELL
if not CHANGE and close <= RENKODN[1] - H
    CHANGE := true
    DN := true
    RENKODN := RENKODN[1] - ATR
    RENKOUP := RENKODN[1]
    COLOR := color.rgb(245, 69, 69,60)
    BUY := 0
    SELL += 1
    SELL
//// STRATEGY 
if(UP)
    strategy.entry("Long",strategy.long)
if(DN)
    strategy.entry("Short",strategy.short)


// ploting 

bgcolor(COLOR)

Published by ChaoZhang on the FMZ strategy square · last modified 2024-01-03. 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/ATR-Channel-Breakout-Trend-following-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