Session Ready
Exercise

Combining signals - II

In the previous exercise, you approximated a sigFormula signal by comparing the value of two other signals. In this final exercise, you will take this one step futher by using the sigFormula() function to generate a sigFormula signal.

The goal of this exercise is simple. You want to enter into a position when both longfilter and longthreshold become true at the same time. The idea is this: You don't want to keep entering into a position for as long as conditions hold true, but you do want to hold a position when there's a pullback in an uptrending environment.

Writing a sigFormula function is as simple as writing the argument of an "if statement" in base R inside the formula() function. In this case, you want to create a signal labeled longentry, which is true when both longfilter and longthreshold cross over to true at the same time.

Once you complete this exercise, you will have a complete survey of how signals work in quantstrat!

Instructions
100 XP
  • Use add.signal() to create a sigFormula signal is true when both longfilter and longthreshold are true.
  • Set cross equal to TRUE.
  • Label this new signal as longentry.