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.
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.
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.
/*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)