Get startedGet started for free

Indicator structure review

1. Indicator structure review

Congratulations on implementing your first indicators. That wasn't so bad. As you saw, there is a method to the madness.

2. Review: using add.indicator()

Again, to review: the add.indicator function requires five steps. The add.indicator function, the strategy name, the function name that generates your output, the arguments to that function, and a label for your output.

3. Naming indicators

In regards to naming indicators, while quantstrat may or may not provide some default names for indicators, it is a good practice to put more description in your labels. This will help quantstrat know exactly which columns to search for. For instance, a good label for an SMA 200 indicator call isn't just "SMA" but "SMA200". Strive to be descriptive with your names, but keep them simple to cut down on necessary typing and longer name maintenance.

4. applyIndicators()

There is one other thing you can do as an intermediate step to see whether or not your indicator applied correctly. The applyIndicators function allows you to take some data, and see if the indicator applied correctly. Using the applyIndicators command will create a market dataset with the indicators applied, which can be worked with as a regular time series.

5. applyIndicators() cont.

Indicator column names take the form of the original name from the function, a dot, and then your label. If your labels are unique (and they should be), you only need to refer to them by their label later on.

6. Further indicator mechanics

Furthermore, for the next exercise, know that the HLC command subsets a time series dataset with open, high, low, and close to only include the high, low, and close.

7. Further indicator mechanics

Also, you will need to know how to subset dates. By including a bracket after the time series object, and separating two dates with a slash, one can narrow down this time series to inspect certain values.

8. Let's practice!

Now, it's time for some practice.