当前位置:网站首页>股票策略02 | 技术择时+行业因子+市值轮动
股票策略02 | 技术择时+行业因子+市值轮动
2022-08-01 14:24:00 【松鼠宽客】

量化策略开发,高质量社群,交易思路分享等相关内容
『正文』
ˇ
大家好,这期我们来做一个技术择时的股票交易策略:
SuperTrend
什么是超级趋势指标SuperTrend Indicator?
超级趋势指标SuperTrend Indicator是一个在外汇交易中常用指标,它的设计者是Jason Robinson。它的主要用途是确定价格趋势,和进行趋势追踪。
超级趋势指标SuperTrend Indicator的计算公式:
在做多时:
超级趋势指标SuperTrend =(最高价+最低价)/2 – N*ATR(M)
在作图中,这个值只上移不下移,就是取近期的最高值。
在做空时:
超级趋势指标= (最高价+最低价)/2 + N*ATR(M)
在作图中,这个值只下移不上移,就是取近期的最低值。
在这个指标当中适用了均值(H+L)/2,和ATR真是波动幅度的概念。在设置它的参数时,要考虑两个值,N,M。一个用来计算ATR的倍数,一个用来计算ATR的周期数。例如,周期数可以是10日,倍数可以是3倍,这是这个指标的基本设置。对于不同的交易市场,和交易对象来说,这两个参数是可以优化的。它的计算方法与肯特纳通道Keltner Channels很相似。
超级趋势指标SuperTrend的主要用途:
1, 可以作为决定趋势的过滤器;在上升趋势时,做多;在下降趋势中,做空。
2, 可以作为趋势追踪止损。在做多有盈利时,当收盘价小于这个指标近期最高值时,卖出,这样可以锁定利润,又不会因为止盈而错过大趋势。当然,它的正确适用和它的参数设置有密切关系。
/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// LonesomeTheBlue
//@version=4
study("Pivot Point SuperTrend", overlay = true)
prd = input(defval = 2, title="Pivot Point Period", minval = 1, maxval = 50)
Factor=input(defval = 3, title = "ATR Factor", minval = 1, step = 0.1)
Pd=input(defval = 10, title = "ATR Period", minval=1)
showpivot = input(defval = false, title="Show Pivot Points")
showlabel = input(defval = true, title="Show Buy/Sell Labels")
showcl = input(defval = false, title="Show PP Center Line")
showsr = input(defval = false, title="Show Support/Resistance")
float ph = na
float pl = na
ph := pivothigh(prd, prd)
pl := pivotlow(prd, prd)
plotshape(ph and showpivot, text="H", style=shape.labeldown, color=na, textcolor=color.red, location=location.abovebar, transp=0, offset = -prd)
plotshape(pl and showpivot, text="L", style=shape.labeldown, color=na, textcolor=color.lime, location=location.belowbar, transp=0, offset = -prd)
float center = na
center := center[1]
float lastpp = ph ? ph : pl ? pl : na
if lastpp
if na(center)
center := lastpp
else
center := (center * 2 + lastpp) / 3
Up = center - (Factor * atr(Pd))
Dn = center + (Factor * atr(Pd))
float TUp = na
float TDown = na
Trend = 0
TUp := close[1] > TUp[1] ? max(Up, TUp[1]) : Up
TDown := close[1] < TDown[1] ? min(Dn, TDown[1]) : Dn
Trend := close > TDown[1] ? 1: close < TUp[1]? -1: nz(Trend[1], 1)
Trailingsl = Trend == 1 ? TUp : TDown
linecolor = Trend == 1 and nz(Trend[1]) == 1 ? color.lime : Trend == -1 and nz(Trend[1]) == -1 ? color.red : na
plot(Trailingsl, color = linecolor , linewidth = 2, title = "PP SuperTrend")
plot(showcl ? center : na, color = showcl ? center < hl2 ? color.blue : color.red : na, transp = 0)
bsignal = Trend == 1 and Trend[1] == -1
ssignal = Trend == -1 and Trend[1] == 1
plotshape(bsignal and showlabel ? Trailingsl : na, title="Buy", text="Buy", location = location.absolute, style = shape.labelup, size = size.tiny, color = color.lime, textcolor = color.black, transp = 0)
plotshape(ssignal and showlabel ? Trailingsl : na, title="Sell", text="Sell", location = location.absolute, style = shape.labeldown, size = size.tiny, color = color.red, textcolor = color.white, transp = 0)
float resistance = na
float support = na
support := pl ? pl : support[1]
resistance := ph ? ph : resistance[1]
plot(showsr and support ? support : na, color = showsr and support ? color.lime : na, style = plot.style_circles, offset = -prd)
plot(showsr and resistance ? resistance : na, color = showsr and resistance ? color.red : na, style = plot.style_circles, offset = -prd)
alertcondition(Trend == 1 and Trend[1] == -1, title='Buy Signal', message='Buy Signal')
alertcondition(Trend == -1 and Trend[1] == 1, title='Sell Signal', message='Sell Signal')
alertcondition(change(Trend), title='Trend Changed', message='Trend Changed')

SuperTrend 这个指标大家都不陌生,特别是松鼠宽客基于期货在SF系列里推出了SF14超级趋势线交易策略。我们决定将它转移到股票策略上看看效果如何。
第一步:
现在TBQ里完成算法和标的图形显示,沪深300指数:


OK,指标显示无误,我们切换IF期货,测试一下绩效。这里需要注意,我们需要把保证金比例调整至100%,让其与现货一样。
交易条件:
1.SuperTrend 决定方向(只做多)
2.窄轨通道择时进场
3.万金油出场
什么是窄轨通道?
就是你在近期的K线里计算一定波动幅度然后与日收盘价相结合构建的小通道,注意小通道的参数不能比SuperTrend 的大,否则就不是小通道了,失去了择时的意义,如下图:

小通道的意义是,当你在趋势开始时错过了最佳进场位置,后面还能有机会再次上车。
回测(只做多):

看起来看不错,我们把它移植到股票市场看一下吧。
沪深300股票池:
筛选市值排名前10的股票进行交易,SuperTrend>0同时窄通道择时进场。


似乎不如在TBQ里的好,因为我没有加万金油出场,也就是说没有止盈只有正反手。加上以后回测太慢了,所以这次没加,下期股票策略会完善这个模块。目前来看使用SuperTrend+窄通道择时后,效果还可以接受,加入止盈止损后降低一下回撤。
多行业轮动
首先,我们来看一下掘金默认的行情轮动模型,这个是策略中心的公开策略。测试时间:2014年1月-2022年7月。


默认的行业因子还是不错的,是一个不错的轮动模型。如果我们给它加上技术择时,会不会更好一点。
多行业轮动+SuperTrend



绩效对比:
多行业轮动

多行业轮动+SuperTrend

加入松鼠宽客俱乐部(VIP),获得期货+股票策略源码。
本策略仅作学习交流使用,实盘交易盈亏投资者个人负责。
边栏推荐
猜你喜欢

魔众文档管理系统 v5.0.0

Longkou united chemical registration: through 550 million revenue xiu-mei li control 92.5% stake

PAT1166 Summit(25)

轮询和长轮询的区别

免费使用高性能的GPU和TPU—谷歌Colab使用教程

Chat technology in live broadcast system (8): Architecture practice of IM message module in vivo live broadcast system

OpenSSL SSL_read: Connection was reset, errno 10054

立新能源深交所上市:市值55亿 哈密国投与国有基金是股东

微服务系统架构的演变

倪光南:openEuler已达国际同类社区水准
随机推荐
荣信文化通过注册:年营收3.8亿 王艺桦夫妇为实控人
Two Permutations
tkinter-TinUI-xml实战(6)问卷
The soul asks: How does MySQL solve phantom reads?
透过开发抽奖小程序,体会创新与迭代
datetime64[ns] converted to datetime
207.数组序号转换
ECCV 2022|R2L: 用数据蒸馏加速NeRF
Pytorch —— 分布式模型训练
搭建LNMT架构
软件测试之发现和解决bug
表白代码vbs不同意无法关闭(vbs表白代码不同意按键会跑)
【无标题】
The little thing about Request reuse.The research is understood, and I will report it to you.
微服务原生案例搭建
redis主从同步方式(redis数据同步原理)
iPhone难卖,被欧洲反垄断的服务业务也难赚钱了,苹果的日子艰难
[Binary Tree] Path Sum II
AtCoder Beginner Contest 261 D - Flipping and Bonus
开放原子全球开源峰会原圆满结束,openEuler模式得到参会者高度认可