Strategy vault / Trend following
Channel Trend Strategy
The Channel Trend strategy is a trend following strategy based on the opening price and Donchian Channel. It identifies trend direction by plotting a line from current price to the trend line benchmarked on opening…

Overview
The Channel Trend strategy is a trend following strategy based on the opening price and Donchian Channel. It identifies trend direction by plotting a line from current price to the trend line benchmarked on opening price, combined with the price channel formed by Donchian Channel. Trading signals are generated when price breaks through the channel.
Strategy Logic
Select a timeframe (daily, weekly etc.) and get its opening price as the benchmark price.
Calculate the N-day moving average of highest price and lowest price using Donchian Channel indicator, forming a price channel.
Draw a straight line from current closing price to the opening price of that timeframe, as the trend benchmark line.
When closing price breaks through the upper band of Donchian Channel, a buy signal is generated. When closing price breaks through the lower band, a sell signal is generated.
Set stop loss and take profit strategy.
The combination of benchmark line and channel lines locks in trend direction and generates persistent signals when trend exists, while filtering out some noise.
Advantage Analysis
Using opening price as strategy benchmark line can effectively determine price trend changes within different timeframes.
Donchian Channel indicator can effectively eliminate the impact of short-term fluctuations on the benchmark line.
The combination of benchmark line and Donchian Channel can generate signals when trend is clear, avoiding false breakouts.
Automatic stop loss and take profit setting locks in some profits and controls risks.
This strategy has few parameters and is easy to implement.
Risk Analysis
It may generate more invalid signals during range-bound market.
If parameters are set improperly, stop loss may be triggered prematurely.
This strategy relies more on trending market and is not suitable for mean-reversion strategies.
In abnormal market condition, price may break through stop loss line directly resulting in huge loss.
Optimization Direction
Test different timeframe parameters to select the smoothest one for signal generation.
Adjust parameters of Donchian Channel to set more suitable channel width.
Optimize stop loss and take profit ratios based on different product characteristics.
Add other indicator filters to avoid signals generated in abnormal market conditions.
Summary
The Channel Trend strategy utilizes the channel lines formed by opening price and Donchian Channel to identify price trend direction. It can generate easy-to-read persistent signals, locks in profits and controls risks through stop loss and take profit setting, making it a very practical trend following strategy. Through constant testing and parameter optimization, this strategy can be applied to different products and achieve good returns in trending markets.
Parameters
| Name | Default | What it controls |
|---|---|---|
| v_input_string_1 | M | TIMELINE |
| v_input_int_1 | 21 | length |
| v_input_int_2 | 15 | Take Profit % |
Source Pine Script
/*backtest
start: 2023-11-17 00:00:00
end: 2023-12-17 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//
strategy("STR-TREND", overlay=true)
emax = ta.ema(close,1)
plot(emax,title="X-EMA",color=color.black,linewidth=2)
XDX = input.string(title="TIMELINE", defval="M")
xdaily = request.security(syminfo.tickerid, XDX, open,barmerge.gaps_off, barmerge.lookahead_on)
length = input.int(21, minval=1)
lower = ta.lowest(xdaily,length)
upper = ta.highest(xdaily,length)
XXX = close>upper?lower:upper
plot(XXX,title="STR-X",color=color.red,linewidth=4)
TAKEPROFIT = input.int(15,title="Take Profit %", minval=1)
SELLTAKEPROFIT = XXX * (1-(TAKEPROFIT/100))
BUYTAKEPROFIT = XXX * (1+(TAKEPROFIT/100))
TAKEPROFITX = close<XXX?SELLTAKEPROFIT:BUYTAKEPROFIT
plot(TAKEPROFITX,title="TAKE PROFIT",color=color.black,linewidth=1)
//////////////STRATEGY ///////////////////
buystat= ta.crossover(close,XXX)
sellstat = ta.crossunder(close,XXX)
plotshape(buystat==true, title='long', text='BUY', textcolor=color.new(color.white, 0), style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny)
plotshape(sellstat==true, title='short', text='SELL', textcolor=color.new(color.white, 0), style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny)
//////////////STRATEGY ///////////////////
strategy.entry("LONG", strategy.long, when = buystat==true, comment="")
strategy.exit("BUY TP", "LONG", qty_percent = 50 ,limit = BUYTAKEPROFIT)
strategy.close("LONG", when = sellstat==true, comment="")
strategy.entry("SHORT", strategy.short, when = sellstat==true, comment="")
strategy.exit("SELL TP", "SHORT", qty_percent = 50 ,limit = SELLTAKEPROFIT)
strategy.close("SHORT", when = buystat==true , comment="")
Published by ChaoZhang on the FMZ strategy square · last modified 2023-12-18. 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/Channel-Trend-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
- Triple Supertrend Ichimoku Cloud Quantitative Trading StrategyPine Script · Trend following · 1d
- Crossing Moving Average Trend Tracking StrategyPine Script · Trend following · 2h
- TrendHunter w MF Multi Timeframe Trend StrategyPine Script · Trend following · 1h
- Ichimoku Balance Line trend following StrategyPine Script · Trend following · 1d
- Five EMA RSI Trend Following Dynamic Channel Trading SystemPine Script · Trend following · 1d
- Ichimoku Cloud MACD and Stochastic Based Multi Timeframe Trend Tracking StrategyPine Script · Trend following · 4h