0bps

Strategy vault / Trend following

Adaptive Trend Following and Multi Confirmation Trading Strategy

This strategy is a trend following trading system that combines the Coral Trend indicator with the Donchian Channel. By precisely capturing market momentum and providing multiple confirmations of trend breakouts, it…

Author
ChaoZhang
Complexity
Starter · 70 lines
Parameters
0
Backtest bar
1d · swing
Tested on
BTC/USDT · futures

IMG

Overview

This strategy is a trend following trading system that combines the Coral Trend indicator with the Donchian Channel. By precisely capturing market momentum and providing multiple confirmations of trend breakouts, it effectively filters out false signals in oscillating markets and improves trading accuracy. The strategy employs adaptive moving average techniques that can dynamically adjust parameters to maintain stable performance across different market conditions.

Strategy Principles

The core logic is built on the synergistic effect of two main indicators:

  1. Coral Trend Indicator: Calculates a smoothed value of (high + low + close)/3 and compares it with the current closing price to determine trend direction.
  2. Donchian Channel: Determines whether price breaks key levels by calculating the highest and lowest prices within a user-defined period.

The system generates long signals when both indicators confirm an uptrend (coralTrendVal == 1 and donchianTrendVal == 1), and short signals when both confirm a downtrend (coralTrendVal == -1 and donchianTrendVal == -1). The strategy uses a state machine (trendState) to track the current trend state and avoid duplicate signals.

Strategy Advantages

  1. Multiple Confirmation Mechanism: Combining two independent trend indicators significantly reduces the probability of false signals.
  2. Strong Adaptability: The smoothing calculation method of the Coral Trend indicator enables it to adapt to different market volatility states.
  3. Parameter Adjustability: The strategy offers flexible parameter settings that can be optimized for different trading instruments and timeframes.
  4. Trend Persistence Recognition: The system effectively identifies strong trend conditions and maintains positions during trends.
  5. Clear Visual Feedback: Traders can intuitively understand market conditions through chart markers and trend lines.

Strategy Risks

  1. Trend Reversal Risk: May experience lag at trend turning points, leading to drawdowns. Solution: Add volatility filters to reduce positions when market volatility increases.
  2. Sideways Market Performance: May generate excessive trading signals in range-bound markets. Solution: Add trend strength confirmation indicators to open positions only when trends are clear.
  3. Parameter Sensitivity: Different parameter settings may lead to significant variations in strategy performance. Solution: Recommend finding optimal parameter combinations through historical data backtesting.

Strategy Optimization Directions

  1. Dynamic Parameter Adjustment: Automatically adjust Donchian Channel period and Coral Trend smoothing period based on market volatility.
  2. Add Stop Loss Mechanism: Recommend adding dynamic ATR-based stop losses to improve risk control.
  3. Add Volume Confirmation: Include volume filtering conditions when generating signals to increase trend confirmation reliability.
  4. Optimize Position Management: Implement a dynamic position management system based on trend strength.
  5. Market Environment Classification: Add market environment recognition module to use different parameter combinations in different market states.

Summary

This strategy achieves a robust trend following system through multiple trend confirmation mechanisms and flexible parameter settings. Its adaptive features and clear signal logic make it suitable for various trading timeframes and market environments. Through the suggested optimization directions, there is room for further improvement in strategy performance. When applying to live trading, it is recommended to incorporate risk management measures and optimize parameters according to the characteristics of specific trading instruments.

Source Pine Script

/*backtest
start: 2019-12-23 08:00:00
end: 2025-01-16 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/

//@version=5
strategy("Coral Tides Strategy", shorttitle="CoralTidesStrat", overlay=true)

// === Inputs ===
dlen = input.int(defval=20, title="Donchian Channel Period", minval=10)
coralPeriod = input.int(defval=14, title="Coral Trend Period")

// === Functions ===
// Coral Trend Calculation
coralTrend(period) =>
    smooth = (high + low + close) / 3
    coral = ta.ema(smooth, period)
    trend = 0
    trend := close > coral ? 1 : close < coral ? -1 : trend[1]
    [trend, coral]

// Donchian Trend Calculation
donchianTrend(len) =>
    hh = ta.highest(high, len)
    ll = ta.lowest(low, len)
    trend = 0
    trend := close > hh[1] ? 1 : close < ll[1] ? -1 : trend[1]
    trend

// === Trend Calculation ===
[coralTrendVal, coralLine] = coralTrend(coralPeriod)
donchianTrendVal = donchianTrend(dlen)

// === Signal Logic ===
var int trendState = 0
buySignal = false
sellSignal = false

if (coralTrendVal == 1 and donchianTrendVal == 1 and trendState != 1)
    buySignal := true
    sellSignal := false
    trendState := 1
else if (coralTrendVal == -1 and donchianTrendVal == -1 and trendState != -1)
    sellSignal := true
    buySignal := false
    trendState := -1
else
    buySignal := false
    sellSignal := false

// === Strategy Execution ===
// Entry Signals
if (buySignal)
    strategy.entry("Long", strategy.long)
if (sellSignal)
    strategy.entry("Short", strategy.short)

// === Plots ===
// Coral Trend Line
plot(coralLine, color=color.green, linewidth=2, title="Coral Trend Line")

// Buy/Sell Signal Labels
if buySignal
    label.new(bar_index, low, "BUY", color=color.green, textcolor=color.white, style=label.style_label_down, size=size.normal)
if sellSignal
    label.new(bar_index, high, "SELL", color=color.red, textcolor=color.white, style=label.style_label_up, size=size.normal)

Published by ChaoZhang on the FMZ strategy square · last modified 2025-01-17. 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/Adaptive-Trend-Following-and-Multi-Confirmation-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