Using sigComparison
A sigComparison signal is a simple and useful way to compare two (hopefully related) quantities, such as two moving averages. Often, a sigComparison signal does not create a buy or sell signal by itself (as such a signal would involve buying or selling on every such day), but is most often useful as a filter for when another buy or sell rule should be followed.
In this exercise, you will use sigComparison() to generate a signal comparison that specifies that the 50-day simple moving average (SMA) must be above the 200-day simple moving average (SMA). You will label this signal longfilter
, because it signals that the short-term average is above the long-term average.
This exercise is part of the course
Financial Trading in R
Exercise instructions
- Use add.signal() to add a
sigComparison
specifying thatSMA50
must be greater thanSMA200
. - Label this signal
longfilter
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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 = "___")