ComenzarEmpieza gratis

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.

Este ejercicio forma parte del curso

Financial Trading in R

Ver curso

Instrucciones del ejercicio

  • Use add.indicator() on your existing strategy strategy.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 period n of 50 days. Don't forget to use the quote function!
  • Label your new indicator "SMA50".

Ejercicio interactivo práctico

Prueba este ejercicio y completa el código de muestra.

# 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 = ___)
Editar y ejecutar código