Get startedGet started for free

Adding indicators to financial data

1. Adding indicators to financial data

2. Trading indicators

It is possible to plot filters on top of plotted financial data. R's TTR library, written by Josh Ulrich, contians a toolbox of classical trading indicators, such as the simple moving average, more colloquially known as a moving average, and sometimes referred to as an SMA. In TTR, the SMA function stands for simple moving average, as you might have guessed. A simple moving average is a calculation that takes a basic average over some past period, such as two hundred days, for which there were prices. As time moves forward, the last price falls off of the calculation, and the newest one enters, hence the average "moves". Many commodity trading advisers have made a great deal trading using the 200-day moving average. Some ETFs still use this very filter to activate defensive positions. While the 200-day moving average is not a particularly magic number, it's a line that displays where the price has been over the past ten months, as there are about two hundred business days (that is, days that aren't weekends or holidays) in ten months.

3. Using SMA()

Here is the code on how to compute the 200-day moving average. When plotting financial data, a trendline can be added using the lines command after plotting, as the slide displays.

4. The trend line

If the current price (or a faster moving average) is above this line, then the general thought is that the price will continue to increase in the future. Similarly, when the price is below this line, usually some very bad things happen. The gray area is when the price action is around the 200-day moving average, which can often cause lots of losses from false signals.

5. Let's practice!

For your next exercise, you will be tasked to do the same thing with a different asset.