Implementing an indicator - III
In financial markets, the goal is to buy low and sell high. The RSI can predict when a price has sufficiently pulled back, especially with a short period such as 2 or 3.
Here, you'll create a 3-period RSI, or RSI 3, to give you more practice in implementing pre-coded indicators. The quantstrat
and quantmod
packages are 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 from previous exercises. - Provide the RSI function as the
name
argument. - Specify the desired arguments of RSI, using the closing price of
mktdata
and a lookback periodn
of 3 days. Don't forget to use thequote()
function! - Label your new indicator
"RSI_3"
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Add an RSI 3 indicator to strategy.st
add.indicator(strategy = strategy.st,
# Add the RSI 3 function
name = ___,
# Create a lookback period
arguments = list(___),
# Label your indicator RSI_3
label = ___)