CommencerCommencer gratuitement

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.

Cet exercice fait partie du cours

Financial Trading in R

Afficher le cours

Instructions

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

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# 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")
Modifier et exécuter le code