Indicator mechanics
1. Indicator mechanics
This video will be about the structure of adding an indicator to a strategy. The function that adds an indicator, unsurprisingly, is called add dot indicator. It has five parts.2. Five steps to calling indicators
To start off, one starts off the function with an add-DOT-indicator call. The first argument is the name of your strategy, which should be saved as a variable, as you'll be using it ubiquitously. So far, we've been using strategy dot ST (that is, strategy dot string), and will continue to use it throughout implementing our strategy. Next, you need the name of the function that your indicator will call. The functions found inside the TTR package, such as SMA (the function call for computing moving average), RSI (the function call for computing the relative strength index) and so on, are little different than standard R functions aside from the fact that since all of quantstrat rests on a foundation of a time series package, that these functions produced ordered output and use other subroutines that depend on their inputs being a time series. In addition to the name of the function, one needs to parameterize the function in the arguments input into the add-DOT-indicator call. This is a list object, and will be different for every function. Lastly, one needs to label the function. This label is what quantstrat will use to find your indicator when you write other functions that look for it later.3. Using add.indicator()
This is what the code looks like. Essentially, it's a five step process. One: call the add-dot-indicator function. Two: let it know which strategy to add the indicator to. Three: specify which function will be used to generate the indicator. Four: add the inputs to the indicator function. Five: add a label to name the output column.4. Another way to think about indicators
Another way to think of adding, or rather, applying, indicators is like this: indicators are similar to R's apply family of functions. Just as R's apply functions call the apply function, specify a dataset, specify a function, and add arguments to the function, so too does the add-dot-indicator command call the add-dot-indicator function, specify a strategy, specify a function, add arguments to the function, and then label it. The only difference is that while you might use the assignment arrow to define the output of an apply statement, with the add-dot-indicator command, you define the result with a label, that is, the last argument of add-dot-indicator.5. Let's practice!
In the following exercises, you will practice implementing some pre-existing indicators from the TTR package.Create Your Free Account
or
By continuing, you accept our Terms of Use, our Privacy Policy and that your data is stored in the USA.