Using sigThreshold - I
In the next two exercises, you will focus on the sigThreshold
signal. The sigThreshold signal is mainly used for comparing an indicator to a fixed number, which usually has applications for bounded oscillators, or perhaps rolling statistical scores (for example, for a trading strategy that might choose to go long when a ratio of mean to standard deviation is at -2, or vice versa). Whereas sigComparison and sigCrossover deal with quantities that are usually based off of an indicator that takes values in the same general area as prices, sigThreshold exists specifically to cover those situations outside the bounds of indicators that take values similar to prices.
Furthermore, the sigThreshold() function takes the cross
argument, which specifies whether it will function similarly to sigComparison (cross = FALSE
) or sigCrossover (cross = TRUE
), respectively. In this exercise, you will implement a variant of sigThreshold that functions similarly to sigComparison.
Your job will be to implement a sigThreshold that checks whether or not DVO_2_126
is under 20. This signal will serve as one of the two switches that need to be "on" in order to enter into a long position in the strategy.
This exercise is part of the course
Financial Trading in R
Exercise instructions
- Use
add.signal()
to add asigThreshold
signal specifying that theDVO_2_126
must be under 20. - Set
cross
equal toFALSE
. - Label this signal
longthreshold
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Implement a sigThreshold which specifies that DVO_2_126 must be less than 20, label it longthreshold
add.signal(strategy.st, name = "___",
# Use the DVO_2_126 column
arguments = list(column = "___",
# The threshold is 20
threshold = ___,
# We want the oscillator to be under this value
relationship = "___",
# We're interested in every instance that the oscillator is less than 20
cross = ___),
# Label it longthreshold
label = "___")