0bps

Strategy vault / Breakout

Keltner Channel Tracking Strategy

This strategy is designed based on the Keltner Channel indicator to generate trading signals when price breaks through the upper and lower bands of the channel. The strategy only goes long, if a sell signal appears…

Author
ChaoZhang
Complexity
Starter · 55 lines
Parameters
3
Backtest bar
1h · intraday
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is designed based on the Keltner Channel indicator to generate trading signals when price breaks through the upper and lower bands of the channel. The strategy only goes long, if a sell signal appears, it will flatten the position to neutral.

Strategy Logic

The strategy uses SMA and ATR to build the Keltner Channel. The upper and lower bands are calculated as:

Upper Band = SMA + ATR * Multiplier Lower Band = SMA - ATR * Multiplier

When price breaks above the upper band, a buy signal is generated. When price breaks below the lower band, a sell signal is generated.

Since it only goes long, if a sell signal appears, it will cancel previous orders and flatten the position.

The logic is:

  1. Build Keltner Channel with SMA and ATR
  2. When price breaks above upper band, set entry price and go long
  3. When price breaks below lower band, flatten previous long position

Advantage Analysis

The advantages of this strategy:

  1. Simple and clear logic, easy to understand and implement
  2. Keltner Channel is intuitive for trend identification
  3. Only go long avoids chasing stop loss risk
  4. Conditional orders for precision entries

Risk Analysis

There are also some risks:

  1. Frequent open/close trades during market fluctuation
  2. Unable to take advantage of short opportunities
  3. Lack of exit mechanism, need manual intervention

Solutions:

  1. Optimize channel parameters to reduce false signals
  2. Add short module for two-way trading
  3. Add exit mechanisms like moving stop loss, trailing stop

Optimization Directions

The strategy can be optimized in the following aspects:

  1. Optimize parameters like channel period, ATR multiplier etc
  2. Add short module based on lower band breakout
  3. Incorporate stop loss mechanisms like ATR trailing stop
  4. Consider more filters to avoid false signals
  5. Test effectiveness across different products

Conclusion

This strategy effectively catches market trends with simple Keltner Channel rules. The logic is clear and easy to understand. Although the lack of exits and short module, it has great potential for improvements like parameter tuning, adding stops, going short etc. Overall a valuable quant strategy worth in-depth research and application.

Parameters

NameDefaultWhat it controls
v_input_1trueuseTrueRange
v_input_220length
v_input_3truemult

Source Pine Script

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

//@version=3
strategy("Keltner Channel Strategy", overlay=true)
source = close

useTrueRange = input(true)
length = input(20, minval=1)
mult = input(1.0)

ma = sma(source, length)
range = useTrueRange ? tr : high - low
rangema = sma(range, length)
upper = ma + rangema * mult
lower = ma - rangema * mult

crossUpper = crossover(source, upper)
crossLower = crossunder(source, lower)

bprice = 0.0
bprice := crossUpper ? high+syminfo.mintick : nz(bprice[1])

sprice = 0.0
sprice := crossLower ? low -syminfo.mintick : nz(sprice[1]) 

crossBcond = false
crossBcond := crossUpper ? true 
 : na(crossBcond[1]) ? false : crossBcond[1]

crossScond = false
crossScond := crossLower ? true 
 : na(crossScond[1]) ? false : crossScond[1]

cancelBcond = crossBcond and (source < ma or high >= bprice )
cancelScond = crossScond and (source > ma or low <= sprice )

if (cancelBcond)
    strategy.cancel("KltChLE")

if (crossUpper)
    strategy.entry("KltChLE", strategy.long, stop=bprice, comment="KltChLE")

if (cancelScond)
    strategy.cancel("KltChSE")

if (crossLower)
    strategy.entry("KltChSE", strategy.short, stop=sprice, comment="KltChSE")

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)

Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-25. 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/Keltner-Channel-Tracking-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