双均线指标随机策略是一种试图利用均线指标与随机指标的组合来寻找交易机会的策略。它会在快速EMA上穿越慢速SMA时产生交易信号,同时利用随机指标K值判定是否超买超卖来滤除部分信号。
该策略主要基于两个技术指标:
均线:计算快速EMA、慢速SMA、慢速VWMA三条不同参数的均线,当快速EMA上穿或下穿慢速SMA时产生交易信号。
随机指标:计算%K值,当其超过设定的超买区或超卖区阈值时,认为行情可能反转,可以滤除部分均线交易信号。
具体来说,策略信号发出的逻辑是:
当快速EMA上穿慢速SMA,且%K值低于超卖区阈值时,做多;当快速EMA下穿慢速SMA,且%K值高于超买区阈值时,做空。
对于打开的多头头寸,如果%K值重新进入超卖区域,或者价格跌破止损线,则平仓。对于打开的空头头寸,如果%K值重新进入超买区域,或者价格涨破止损线,则平仓。
通过组合均线指标和随机指标,该策略试图在高概率的均线信号点发出入场信号,同时利用随机指标过滤部分误入的机会。
该策略有以下主要优势:
该策略也存在一些风险:
对应方法:
1. 优化参数,寻找最佳指标参数组合。
2. 适当缩小头寸规模,分批建仓。
3. 结合基本面分析,避开重大事件。
该策略主要可从以下几个方面进行优化:
双均线指标随机策略通过快慢均线指标与随机指标的组合,设计出较为稳健的趋势跟踪策略。但也存在一些可优化空间,如参数选择、止损方式等。若进一步引入更多指标判断和优化,该策略可望获取较稳定的超额收益。
/*backtest start: 2023-01-22 00:00:00 end: 2024-01-28 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy("TVIX MEAN REV V2 TREND", overlay=true) length = input(16, minval=1) OverBought = input(80) OverSold = input(20) TradeLong = input (true) TradeShort = input (true) OverBoughtClose = input(80) OverSoldClose = input(20) smoothK = 3 smoothD = 3 trail_points = input(50) k = sma(stoch(close, high, low, length), smoothK) d = sma(k, smoothD) k2 = sma(stoch(close, high, low, length), smoothK) d2 = sma(k, smoothD) // === GENERAL INPUTS === // short Ema maFastSource = input(defval=close, title="Fast EMA Source") maFastLength = input(defval=1, title="Fast EMA Period", minval=1) // long Sma maSlowSource = input(defval=close, title="Slow SMA Source") maSlowLength = input(defval=100, title="Slow SMA Period", minval=1) // longer Sma maSlowerSource = input(defval=close, title="Slower SMA Source") maSlowerLength = input(defval=30, title="Slower SMA Period", minval=1) //ATR Stop Loss Indicator by Keith Larson atrDays = input(7, "ATR Days Lookback") theAtr = atr(atrDays) atrModifier = input(5.0, "ATR Modifier") //plot(atr * atrModifier, title="ATR") LstopLoss = close - (theAtr * atrModifier) SstopLoss = close + (theAtr * atrModifier) // === SERIES SETUP === /// a couple of ma's.. maFast = ema(maFastSource, maFastLength) maSlow = sma(maSlowSource, maSlowLength) maSlower = vwma(maSlowerSource, maSlowerLength) rsi = rsi(maSlowerSource, maSlowerLength) // === PLOTTING === fast = plot(maFast, title="Fast MA", color=color.red, linewidth=2, style=plot.style_line, transp=30) slow = plot(maSlow, title="Slow MA", color=color.green, linewidth=2, style=plot.style_line, transp=30) slower = plot(maSlower, title="Slower MA", color=color.teal, linewidth=2, style=plot.style_line, transp=30) // === LOGIC === Basic - simply switches from long to short and vice-versa with each fast-slow MA cross LongFilter = maFast > maSlow ShortFilter = maSlow > maFast BUY=crossover(k, d) and k < OverSold SELL=crossunder(k, d) and k > OverBought SELLCLOSE=crossover(k, d) and k < OverSoldClose BUYCLOSE=crossunder(k, d) and k > OverBoughtClose Open = open if not na(k) and not na(d) if crossover(k, d) and k < OverSold and LongFilter and TradeLong strategy.entry("$", strategy.long, limit = Open, comment="Long") strategy.close("$",when = crossunder(k, d) and k > OverBoughtClose or open < LstopLoss ) ///strategy.close("$",when = open < LstopLoss ) if not na(k) and not na(d) if crossunder(k, d) and k > OverBought and ShortFilter and TradeShort strategy.entry("$1", strategy.short, limit = Open, comment="S") strategy.close ("$1", when = crossover(k, d) and k < OverSoldClose or open > SstopLoss ) ///strategy.close ("$1", when = open < SstopLoss)