Implementing an indicator - II
Great job implementing your first indicator! Now, you'll make your strategy even more robust by adding a 50-day SMA. A fast moving average with a slower moving average is a simple and standard way to predict when prices in an asset are expected to rise in the future. While a single indicator can provide a lot of information, a truly robust trading system requires multiple indicators to operate effectively.
In this exercise, you'll also add this 50-day SMA to strategy.st
. The quantstrat
and quantmod
packages are also loaded for you.
This exercise is part of the course
Financial Trading in R
Exercise instructions
- Use
add.indicator()
on your existing strategystrategy.st
. Follow the example code in the previous exercise. - Provide the SMA function as the
name
argument. - Specify the desired arguments of SMA, using the closing price of
mktdata
and a lookback periodn
of 50 days. Don't forget to use thequote
function! - Label your new indicator
"SMA50"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add a 50-day SMA indicator to strategy.st
add.indicator(strategy = ___,
# Add the SMA function
name = "__",
# Create a lookback period
arguments = list(___),
# Label your indicator SMA50
label = ___)