开始使用免费开始使用

使用 sigComparison

sigComparison 信号是一种简单而实用的方式,用于比较两个(最好是相关的)量,例如两条移动平均线。通常,sigComparison 信号本身不会直接产生买入或卖出信号(否则几乎每天都会买卖),而是更常用作过滤条件,用来限定何时执行其他买入或卖出规则。

在本练习中,您将使用 sigComparison() 生成一个信号比较,要求 50 日简单移动平均线(SMA)必须高于 200 日简单移动平均线(SMA)。您将把该信号标记为 longfilter,因为它表示短期均线在长期均线之上。

本练习是课程的一部分

R 中的金融交易

查看课程

练习说明

  • 使用 add.signal() 添加一个 sigComparison,指定 SMA50 必须大于 SMA200
  • 将该信号标记为 longfilter

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Add a sigComparison which specifies that SMA50 must be greater than SMA200, call it longfilter
add.signal(strategy.st, name = "sigComparison", 
           
           # We are interested in the relationship between the SMA50 and the SMA200
           arguments = list(columns = c("___", "___"), 
                            
                            # Particularly, we are interested when the SMA50 is greater than the SMA200
                            relationship = "___"),
           
           # Label this signal longfilter
           label = "___")
编辑并运行代码