1. sigThreshold
2. About sigThreshold
A third signal function in quantstrat is called the sigThreshold function. Unlike sigComparison and sigCrossover, sigThreshold exists for the purpose of dealing with bounded indicators interacting with critical (and most likely, fixed) values. For instance, when using oscillating types of indicators such as an RSI, or with our strategy, the DVO, these indicators will take a bounded value. In our case, this is between 0 and 100, but in other cases, you may be dealing with a running probability value (between 0 and 1), rolling ratios that center on 0 (for instance, the Z score is a ratio of mean to standard deviation), a ratio-adjusted price difference between two instruments, and so on.
In all such cases, rather than compare the value of an indicator to one long vector with one quantity (for instance, imagine a vector spanning 15 years whose sole value is 20 every single day), you simply use the sigThreshold function, and specify that particular threshold as an argument.
3. Structure
The sigThreshold function is very similar to the sigCrossover and sigComparison signals in that both need the strategy name, the signal function, some arguments, and a label.
Unlike the sigCrossover and sigComparison functions, however, sigThreshold wraps the comparison vs. crossover functionality into one new argument called the, aptly named, cross argument. Specifying cross equal to TRUE mimics the sigCrossover signal function in that the signal only occurs on the event of a threshold crossover, while cross set to FALSE mimics the sigComparison signal function. Furthermore, sigThreshold only takes in one column from your strategy, and a static threshold against which to compare it, using the same relationship syntaxes as sigCrossover and sigComparison.
4. Examples
Here are some examples of syntax using sigThreshold. In the first example, sigThreshold is used to mimic a sigComparison signal, and in the second, it is used to mimic sigCrossover.
5. Examples
For a visual example, one can use a cross equals TRUE argument to generate a signal for a transaction, while a cross equals FALSE argument allows a strategy to use the sigThreshold signal to specify a favorable environment for making a trade. As you can see, the sigThreshold function can cover when the indicator first crosses under the green line, or when it stays under. Both of these types of nuances will eventually matter.
6. Let's practice!