开始使用免费开始使用

Specifying sigcol in add.rule()

Great job! Although the add.rule() command looks complex, each argument is quite simple. To understand this command, you will explore each argument individually.

First, add.rule() takes the argument sigcol, which specifies the signal column in your strategy. Like signals and indicators, all rules reference a column already present in your strategy. Rules relies on signals, and must therefore reference the signal columns in your strategy.

In this exercise, you will supply the add.rule() call with the sigcol value, which will be set to filterexit (to reference the filterexit signal you created in the previous chapter). Specifically, the filterexit signal refers to the condition that the 50 day SMA has crossed under the 200 day SMA in your strategy. By creating a rule for this signal, you will be indicating that you wish to exit in this condition, as the market environment is no longer conducive to your position.

As before, strategy.st is preloaded in your workspace.

本练习是课程的一部分

Financial Trading in R

查看课程

练习说明

  • Once again, take a look at the add.rule() command in your workspace.
  • Create an exit rule based on filterexit by specifying sigcol.

交互式实操练习

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

# Fill in the sigcol argument in add.rule()
add.rule(strategy.st, name = "ruleSignal", 
         arguments = list(sigcol = "___", sigval = TRUE, orderqty = "all", 
                        ordertype = "market", orderside = "long", 
                        replace = FALSE, prefer = "Open"), 
         type = "exit")
编辑并运行代码