Get startedGet started for free

Specifying orderside in add.rule()

The next critical argument to specify in your order is orderside, which can take two values: either long or short. In quantstrat, long and short side trades are siloed off separately so that quantstrat knows whether a trade is a long trade or a short trade. A long trade is one that profits by buying an asset in the hopes that the asset's price will rise. A short trade is one that sells an asset before owning it, hoping to buy it back later at a lower price.

For your strategy, you will want to take only long orders.

This exercise is part of the course

Financial Trading in R

View Course

Exercise instructions

  • The add.rule() command from the previous exercise has been loaded into your workspace.
  • Define your order side as long by specifying the orderside argument.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Fill in the orderside argument in add.rule()
add.rule(strategy.st, name = "ruleSignal", 
         arguments = list(sigcol = "filterexit", sigval = TRUE, orderqty = "all", 
                        ordertype = "market", orderside = "___", 
                        replace = FALSE, prefer = "Open"), 
         type = "exit")
Edit and Run Code