前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >策略代码拆解4-Volume,SAR,RSI,SMA,RMI

策略代码拆解4-Volume,SAR,RSI,SMA,RMI

作者头像
项勇
发布2023-03-24 13:54:46
5500
发布2023-03-24 13:54:46
举报
文章被收录于专栏:项勇项勇

代码片段5

代码语言:javascript
复制
// Volume
// inputs
volume_f_B = input.float(1.9, title='  Volume mult. Breakouts', minval=0, step=0.1, group='Volume (BREAKOUTS)')
sma_length_B = input.int(47, title='  Volume lenght Breakouts', minval=1, group='Volume (BREAKOUTS)')
// condt
Volume_Breakouts_condt = volume > ta.sma(volume, sma_length_B) * volume_f_B

官方文档解释

volume

当前K线成交量

ta.sma

sma函数返回移动平均值

参数

source (series int/float) 待执行的系列值

length (series int) K线数量(长度)

返回值

`length`K线返回的`source`的简单移动平均线。


对照解读

代码语言:javascript
复制
volume_f_B = input.float(1.9, title='  Volume mult. Breakouts', minval=0, step=0.1, group='Volume (BREAKOUTS)')
          //输入float    默认  标题                              最小值     步进      群组
代码语言:javascript
复制
Volume_Breakouts_condt = volume         >         ta.sma(volume, sma_length_B)                    *  volume_f_B
                         当前K线成交量   是否大于   source为volume,length为sma_length_B的移动平均线  乘  输入的volume
//该值后续用于开仓条件

代码片段6

代码语言:javascript
复制
//SAR
// inputs
Sst = input.float(0.91, title='  Sar Start', step=0.01, minval=0.01, group='SAR')
Sinc = input.float(0.1, title='  Sar Int', step=0.01, minval=0.01, group='SAR')
Smax = input.float(0.92, title='  Sar Max', step=0.01, minval=0.01, group='SAR')
// calc
SAR = ta.sar(Sst, Sinc, Smax)
// condt
L_sar = SAR < close
S_sar = SAR > close

官方文档解释

ta.sar

抛物线转向(抛物线停止和反向)是J. Welles Wilder, Jr.设计的方法,以找出交易市场价格方向的潜在逆转。

返回值

抛物线转向指标。

参数

start (simple int/float) 开始。

inc (simple int/float) 增加

max (simple int/float) 最大.

close

当前K线关闭时的收盘价


对照解读

代码语言:javascript
复制
//SAR  逆转指数
Sst = input.float(0.91, title='  Sar Start', step=0.01, minval=0.01, group='SAR') //对应ta.sar的参数start
Sinc = input.float(0.1, title='  Sar Int', step=0.01, minval=0.01, group='SAR')   //对应ta.sar的参数inc
Smax = input.float(0.92, title='  Sar Max', step=0.01, minval=0.01, group='SAR')  //对应ta.sar的参数max
SAR = ta.sar(Sst, Sinc, Smax)  //计算SAR
代码语言:javascript
复制
// condt
L_sar = SAR < close  //逆转指数小于收盘价格
S_sar = SAR > close  //逆转指数大于收盘价格
//该两参数后续都用于开仓条件

代码片段7

代码语言:javascript
复制
// RSI-VWAP
//inputs
RSI_VWAP_length = input.int(45, title='Rsi vwap lenght', group='RSI-VWAP')
// calc
RSI_VWAP = ta.rsi(ta.vwap(close), RSI_VWAP_length)
RSI_VWAP_overSold = 29
RSI_VWAP_overBought = 75
// condt
L_VAP = ta.crossover(RSI_VWAP, RSI_VWAP_overSold)
S_VAP = ta.crossunder(RSI_VWAP, RSI_VWAP_overBought)

官方文档解释

ta.rsi

相对强度指数。它是使用在最后一个 `length` K线上`source` 的向上和向下变化的`ta.rma()` 计算的。

返回值

相对强弱指标(RSI)

参数

source (series int/float) 待执行的系列值。

length (simple int) K线数量(长度).

ta.vwap

成交量加权平均价格。

ta.crossover

返回值

如果`source1`穿过`source2`则为true,否则为false。

参数

source1 (series int/float) 第一数据系列。

source2 (series int/float) 第二数据系列。

ta.crossunder

返回值

如果`source1`在`source2`下交叉,则为true,否则为false。

参数

source1 (series int/float) 第一数据系列。

source2 (series int/float) 第二数据系列。


对照解读

代码语言:javascript
复制
// RSI-VWAP   RSI指数
//inputs
RSI_VWAP_length = input.int(45, title='Rsi vwap lenght', group='RSI-VWAP') //长度默认45
代码语言:javascript
复制
// calc
RSI_VWAP = ta.rsi     (ta.vwap(close),                 RSI_VWAP_length)
         //相对强度指数  参数为close的成交量加权平均价格, length为RSI_VWAP_length
代码语言:javascript
复制
// condt
RSI_VWAP_overSold = 29
RSI_VWAP_overBought = 75
L_VAP = ta.crossover(RSI_VWAP, RSI_VWAP_overSold)
                     //RSI上穿RSI_VWAP_overSold,判断强势
S_VAP = ta.crossunder(RSI_VWAP, RSI_VWAP_overBought)
                      //RSI下穿RSI_VWAP_overSold,判断弱势
//该两参数后续都用于开仓条件

代码片段8

代码语言:javascript
复制
//SMAs 
// inputs
Length1 = input.int(12, title='  1-SMA Lenght', minval=1, group='SMA')
Length2 = input.int(16, title='  2-SMA Lenght', minval=1, group='SMA')
Length3 = input.int(44, title='  3-SMA Lenght', minval=1, group='SMA')
// calc
xPrice = close
SMA1 = ta.sma(xPrice, Length1)
SMA2 = ta.sma(xPrice, Length2)
SMA3 = ta.sma(xPrice, Length3)
// condt
Long_MA = SMA1 < close and SMA2 < close and SMA3 < close
Short_MA = SMA1 > close and SMA2 > close and SMA3 > close

官方文档解释

ta.sma

sma函数返回移动平均值

参数

source (series int/float) 待执行的系列值

length (series int) K线数量(长度)

返回值

`length`K线返回的`source`的简单移动平均线。


对照解读

代码语言:javascript
复制
//SMAs 指数
// inputs 输入三个默认的int值
Length1 = input.int(12, title='  1-SMA Lenght', minval=1, group='SMA')
Length2 = input.int(16, title='  2-SMA Lenght', minval=1, group='SMA')
Length3 = input.int(44, title='  3-SMA Lenght', minval=1, group='SMA')
代码语言:javascript
复制
// calc
xPrice = close //收盘价赋予xPrice
SMA1 = ta.sma(xPrice, Length1) //计算source为xPrice ,length为Length1的移动平均线SMA1
SMA2 = ta.sma(xPrice, Length2) //计算source为xPrice ,length为Length2的移动平均线SMA2
SMA3 = ta.sma(xPrice, Length3) //计算source为xPrice ,length为Length3的移动平均线SMA3
代码语言:javascript
复制
// condt
Long_MA = SMA1 < close and SMA2 < close and SMA3 < close   //收盘价都大于三个移动平均线
Short_MA = SMA1 > close and SMA2 > close and SMA3 > close  //收盘价都小于三个移动平均线
//该两参数也用于判断趋势强弱 后续都用于开仓条件

代码片段9

代码语言:javascript
复制
//RMI 
// inputs
RMI_len = input.int(26, title='Rmi Lenght'  , minval=1, group='Relative Momentum Index')
mom     = input.int(11, title='Rmi Momentum', minval=1, group='Relative Momentum Index')
// calc
RMI_os = 32
RMI_ob = 70
RMI(len, m) =>  
    up = ta.ema(math.max(close - close[m], 0), len)
    dn = ta.ema(math.max(close[m] - close, 0), len)
    RMI = dn == 0 ? 0 : 100 - 100 / (1 + up / dn)
    RMI 
// condt
L_rmi = ta.crossover(RMI(RMI_len, mom), RMI_os)
S_rmi = ta.crossunder(RMI(RMI_len, mom), RMI_ob)

官方文档解释

ta.ema

ema 函数返回指数加权移动平均线。

返回值

`source` 的指数移动平均线,alpha = 2 / (长度 + 1)。

参数

source (series int/float) 待执行的系列值。

length (simple int) K线数量(长度).

math.max

返回多个值中最大的一个。

ta.crossover

返回值

如果`source1`穿过`source2`则为true,否则为false。

参数

source1 (series int/float) 第一数据系列。

source2 (series int/float) 第二数据系列。

ta.crossunder

返回值

如果`source1`在`source2`下交叉,则为true,否则为false。

参数

source1 (series int/float) 第一数据系列。

source2 (series int/float) 第二数据系列。


对照解读

代码语言:javascript
复制
//RMI 指数
// inputs
RMI_len = input.int(26, title='Rmi Lenght'  , minval=1, group='Relative Momentum Index')
mom     = input.int(11, title='Rmi Momentum', minval=1, group='Relative Momentum Index')
代码语言:javascript
复制
// calc
RMI_os = 32
RMI_ob = 70
RMI(len, m) =>  //RMI函数,len和m为传入参数
    up = ta.ema       (math.max(close        - close[m],      0), len)
         ema移动平均线  取最大值( 当前收盘价格 - 上m个K线的收盘价,0) 长度
    dn = ta.ema(math.max(close[m] - close, 0), len)
    RMI = dn == 0 ? 0 : 100 - 100 / (1 + up / dn)
    RMI //最终返回的值
代码语言:javascript
复制
// condt
L_rmi = ta.crossover(RMI(RMI_len, mom), RMI_os) //取RMI计算的结果与RMI_os,做上穿判断,判断强势
S_rmi = ta.crossunder(RMI(RMI_len, mom), RMI_ob)//取RMI计算的结果与RMI_ob,做下穿判断,判断弱势
//该两参数也用于判断趋势强弱 后续都用于开仓条件

策略代码拆解1是策略准备配置相关内容

策略代码拆解2 是SupportandResistance指标

策略代码拆解3-adx是ADX指标

加上本篇的Volume,SAR,RSI,SMA,RMI,至此,代码已经完成了指标解读

本文参与 腾讯云自媒体分享计划,分享自微信公众号。
原始发表:2022-12-03,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 项勇 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • volume
  • ta.sma
  • ta.sar
  • close
  • ta.rsi
  • ta.vwap
  • ta.crossover
  • ta.crossunder
  • ta.sma
  • ta.ema
  • math.max
  • ta.crossover
  • ta.crossunder
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档