双均线智能追踪交易策略是一种基于均线和特定指标的趋势跟踪策略。该策略运用两条不同参数设置的均线构建通道,并结合OTT指标设定通道上下限,实现对价格趋势的智能跟踪。当价格突破通道时,进行买入或卖出操作。
该策略主要运用两条移动平均线及OTT指标构建自适应通道,具体原理如下:
计算快线MAvg,以CLOSE收盘价和自定义均线为输入,长度为5;
根据MAvg和设置百分比,计算通道上下限长线位置长Stop和短线位置短Stop;
计算OTT指标中的通道移动止损MT,根据多空状态计算通道价格OTT;
当价格突破OTT时,产生交易信号。
以上构建自适应通道的过程,使得策略可以实时跟踪价格变化趋势,进而产生交易信号。
该策略具有以下优势:
该策略也存在一些风险:
针对上述风险,可以通过参数优化,结合其他指标或基本面过滤信号等方式进行改进和优化。
该策略可以从以下几个方向进行优化:
本策略总体来说是一个基于双均线通道和OTT指标进行趋势跟踪的策略,核心思路是构建自适应通道,并以突破产生交易信号。该策略具有一定的优势,但也存在可能的改进空间。通过参数及规则优化,该策略可以成为一个值得实盘验证的高效量化交易策略。
/*backtest start: 2023-02-11 00:00:00 end: 2024-02-17 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title="BugRA_Trade_Strategy", shorttitle="BugRA_Trade_Strategy", overlay=true) // Kullanıcı Girdileri length = input(5, title="Period", minval=1) percent = input(1, title="Sihirli Yüzde", type=input.float, step=0.1, minval=0) mav = input(title="Hareketli Ortalama Türü", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"]) wt_n1 = input(10, title="Kanal Periyodu") wt_n2 = input(21, title="Averaj Uzunluğu") src = close // Tarih Aralığı Girdileri startDate = input(20200101, title="Başlangıç Tarihi (YYYYMMDD)") endDate = input(20201231, title="Bitiş Tarihi (YYYYMMDD)") // Tarih Filtresi Fonksiyonu isDateInRange() => true // Özel Fonksiyonlar Var_Func(src, length) => valpha = 2 / (length + 1) vud1 = src > src[1] ? src - src[1] : 0 vdd1 = src < src[1] ? src[1] - src : 0 vUD = sum(vud1, length) vDD = sum(vdd1, length) vCMO = (vUD - vDD) / (vUD + vDD) varResult = 0.0 varResult := nz(valpha * abs(vCMO) * src + (1 - valpha * abs(vCMO)) * nz(varResult[1])) varResult Wwma_Func(src, length) => wwalpha = 1 / length wwma = 0.0 wwma := wwalpha * src + (1 - wwalpha) * nz(wwma[1]) wwma Zlema_Func(src, length) => zxLag = floor(length / 2) zxEMAData = src + (src - src[zxLag]) zlema = ema(zxEMAData, length) zlema Tsf_Func(src, length) => lrc = linreg(src, length, 0) lrs = lrc - linreg(src, length, 1) tsf = lrc + lrs tsf getMA(src, length) => ma = mav == "SMA" ? sma(src, length) : mav == "EMA" ? ema(src, length) : mav == "WMA" ? wma(src, length) : mav == "TMA" ? sma(sma(src, ceil(length / 2)), floor(length / 2) + 1) : mav == "VAR" ? Var_Func(src, length) : mav == "WWMA" ? Wwma_Func(src, length) : mav == "ZLEMA" ? Zlema_Func(src, length) : mav == "TSF" ? Tsf_Func(src, length) : na // Strateji Hesaplamaları MAvg = getMA(src, length) fark = MAvg * percent * 0.01 longStop = MAvg - fark longStopPrev = nz(longStop[1], longStop) longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop shortStop = MAvg + fark shortStopPrev = nz(shortStop[1], shortStop) shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop dir = 1 dir := nz(dir[1], dir) dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir MT = dir==1 ? longStop: shortStop OTT = MAvg > MT ? MT*(200+percent)/200 : MT*(200-percent)/200 plot(OTT, title="BugRA", color=color.rgb(251, 126, 9)) // Alım ve Satım Koşulları longCondition = crossover(src, OTT) and isDateInRange() shortCondition = crossunder(src, OTT) and isDateInRange() // Strateji Giriş ve Çıkış Emirleri if (longCondition) strategy.entry("Long", strategy.long) if (shortCondition) strategy.close("Long")