本策略是一个基于自定义G通道和指数移动平均线(EMA)的趋势跟踪交易系统。G通道由上轨(a)、下轨(b)和中轨(avg)构成,通过动态计算当前和历史价格来确定通道边界。该策略结合EMA作为趋势过滤器,通过价格与通道线的交叉以及与EMA的位置关系来产生交易信号,有效地捕捉市场趋势转折点。
策略的核心逻辑包含两个主要组件:G通道和EMA过滤器。G通道的计算基于当前价格和历史数据,通过自适应算法动态调整通道宽度。上轨线(a)取当前价格与前期上轨的较大值,并根据通道宽度和长度参数进行动态调整;下轨线(b)采用类似方法计算最小值;中轨则为上下轨的算术平均值。交易信号的触发条件结合了价格与通道线的交叉以及与EMA的相对位置:当价格突破下轨且位于EMA下方时产生买入信号;当价格跌破上轨且位于EMA上方时产生卖出信号。
G通道与EMA趋势过滤交易系统是一个结合了通道突破和趋势跟踪的完整交易策略。通过G通道的动态特性和EMA的趋势确认功能,该策略能够有效捕捉市场转折点并控制交易风险。虽然存在一定的局限性,但通过提出的优化方向,策略的整体性能有望得到进一步提升。该策略适合在趋势明显的市场中使用,并可以作为构建更复杂交易系统的基础框架。
/*backtest
start: 2024-11-04 00:00:00
end: 2024-12-04 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("G-Channel with EMA Strategy", overlay=true)
// G-Channel Indicator
length = input.int(100, title="G-Channel Length")
src = input(close, title="Source")
var float a = na
var float b = na
a := math.max(src, nz(a[1])) - (nz(a[1]) - nz(b[1])) / length
b := math.min(src, nz(b[1])) + (nz(a[1]) - nz(b[1])) / length
avg = (a + b) / 2
// G-Channel buy/sell signals
crossup = ta.crossover(close, b)
crossdn = ta.crossunder(close, a)
bullish = ta.barssince(crossdn) <= ta.barssince(crossup)
// EMA Indicator
emaLength = input.int(200, title="EMA Length")
ema = ta.ema(close, emaLength)
// Buy Condition: G-Channel gives a buy signal and price is below EMA
buySignal = bullish and close < ema
// Sell Condition: G-Channel gives a sell signal and price is above EMA
sellSignal = not bullish and close > ema
// Plotting the G-Channel and EMA
plot(a, title="Upper", color=color.blue, linewidth=2, transp=100)
plot(b, title="Lower", color=color.blue, linewidth=2, transp=100)
plot(avg, title="Average", color=bullish ? color.lime : color.red, linewidth=1, transp=90)
plot(ema, title="EMA", color=color.orange, linewidth=2)
// Strategy Execution
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
// Plot Buy/Sell Signals
plotshape(buySignal, location=location.belowbar, color=color.green, style=shape.labelup, text="Buy")
plotshape(sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, text="Sell")