本文针对Noro编写的追踪移动平均跳空策略进行详细分析。该策略通过计算关闭价与简单移动平均的偏离程度,判断市场趋势发生转折的时机,实现低买高卖。
该策略首先计算3日简单移动平均sma。然后计算收盘价close与sma的比值,再减去1,得到一个指标ind。当ind上穿预设参数limit时,表明收盘价已明显超过sma,考虑做多;当ind下穿-limit时,表明收盘价已大幅低于sma,考虑做空。
策略还绘制了0轴、limit轴和-limit轴。 ind指标在不同区域时,用不同颜色进行着色,辅助判断。当ind指标穿过limit或-limit时,表示出现做多或做空信号。
策略在产生做多或做空信号时,会先平掉当前方向相反的持仓,然后开仓做多或做空。当ind指标回到0轴之间时,会平掉所有持仓。
使用跳空原理,当价格出现明显离开移动平均线时,采取逆势操作,这与趋势跟踪有所不同,跳空策略追求捕捉转折点。
绘制指标轴线,直观判断指标的位置和穿越。
优化了平仓逻辑,在平当前仓位后才反向开新仓,避免不必要的反向持仓。
设定交易时间范围,避免不必要的过夜仓位。
允许设置进入多空两边的交易开关,可仅做多或仅做空。
追踪移动平均线策略容易产生多次亏损交易,适合耐心持仓。
移动平均线作为判断指标缺乏灵活性,不能及时反映价格变化。
预设参数limit较静态,不同品种和市场环境下需要调整。
追踪移动平均线无法识别趋势内波动,应结合波动指标等使用。
需要优化持仓规则,如设置止损、止盈;或只在趋势初期捕捉跳空。
可以测试不同参数设置,如sma周期;或采用指数移动平均等自适应移动平均线。
可以加入移动平均线方向、角度等判定,避免平台期无谓交易。
可以考虑与波动率指标结合,如布林带,在波动加大时暂停交易。
可以设定仓位管理规则,如固定数量开仓、递增加仓、资金管理等方式。
可以设置止损止盈线,或在固定比例止损时暂停新订单,控制单笔风险。
本文对Noro编写的追踪移动平均跳空策略进行了详细分析。该策略利用价格跳空移动平均线的特征,设计了指标轴线和颜色绘制,判断入场时机。同时优化了平仓顺序逻辑,设定了交易时间范围。但该策略存在追踪移动平均线的固有缺点,需要进一步优化参数设置、止损规则、与其他指标结合等方面,以提高稳定性。
/*backtest
start: 2022-10-19 00:00:00
end: 2023-10-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Noro
//2018
//@version=3
strategy(title = "Noro's Shift Close Strategy v1.0", shorttitle = "Shift Close 1.0", default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 5)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot, %")
limit = input(10)
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From Day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To Day")
//Shift MA
sma = sma(ohlc4, 3)
ind = ((close / sma) - 1) * 100
//Oscilator
plot(3 * limit, color = na, transp = 0)
plot(limit, color = black, transp = 0)
plot(0, color = black, transp = 0)
plot(-1 * limit, color = black, transp = 0)
plot(-3 * limit, color = na, transp = 0)
plot(ind, linewidth = 3, transp = 0)
col = ind > limit ? red : ind < -1 * limit ? lime : na
bgcolor(col, transp = 0)
//Signals
size = strategy.position_size
up = ind < -1 * limit
dn = ind > limit
exit = ind > -1 * limit and ind < limit
//Trading
lot = 0.0
lot := size == 0 ? strategy.equity / close * capital / 100 : lot[1]
if up
if strategy.position_size < 0
strategy.close_all()
strategy.entry("Long", strategy.long, needlong == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if dn
if strategy.position_size > 0
strategy.close_all()
strategy.entry("Short", strategy.short, needshort == false ? 0 : lot, when=(time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if exit
strategy.close_all()