1. sigComparison and sigCrossover
2. Trend indicators
The first two types of signals I'd like to discuss are what I like to call the trend signals. They are sigCrossover and sigComparison. Both of these compare two variable quantities against one another. The easiest and most intuitive example that comes to mind is comparing two moving averages. In a classical trend-following strategy, a buy signal may be sent out when a moving average with a shorter lookback crosses above a longer lookback moving average, such as a 50-day simple moving average crossing above a 200-day simple moving average. A classical trend-following strategy may choose to buy in such a situation.
3. Structure
The mechanics of these two signal functions are in fact, identical, outside from the function name. They both take in arguments of two columns, and the relationship between them. Use gt for greater than, lt for less than, eq for equal to, lte for less than or equal to.
4. Structure
So if you wanted to specify a crossover of the 50 and 200 day simple moving averages, you would use the sigCrossover function, and you would enter SMA50 and SMA200 as the columns, with gt as the relationship.
However, if you simply wanted all trading to take place while the 50-day simple moving average was above the 200-day simple moving average, you would use the exact same arguments, but simply use the sigComparison function instead of the sigCrossover function.
In both cases, just as with indicators, signals you add to your strategy require a label so that added rules, which we will see next chapter, can find them.
In this pair of examples, the first example creates a signal called longFilter when the 50-day simple moving average is above the 200-day moving simple average, and the second example creates a signal called filterExit when the 50-day simple moving average crosses under the 200.
5. Examples
Here's the picture you saw before to demonstrate what a sigCrossover and sigComparison signal aim to do. A sigCrossover is concerned about when a relationship between two variable quantities (such as two moving averages) first changes, while a sigComparison is concerned about the relationship as a whole. A sigCrossover is usually the signal desired for a transaction, while a sigComparison is the signal desired to denote a market condition favorable for other trading signals.
6. Let's practice!
For now, you'll practice using both types of signal functions. Good luck.