December 21, 2016

MACD

For many stock market traders, knowing when to buy and sell equities is essential to making a profit. Thare are many strategies used in timing the markets, and these often include so called technical indicators. One of the most popular technical indicators is called Moving Average Convergence Divergence (MACD).

The MACD is a trend-following momentum indicator that shows the relationship between two moving averages of prices. The MACD is calculated by subtracting a slow exponential moving average (EMA) of the price from a fast EMA. Another EMA of the MACD, called the signal line, is then plotted on top of the MACD, functioning as a trigger for buy and sell signals. from Investopedia

The application can be found here: MACD Shiny App

The MACD Application Updates Equity Prices Daily

The daily closing price of the equity is obtained real time using the "quantmod" package in R.

data <- new.env()
        tickers = ('SPY')
        getSymbols(tickers, src = 'yahoo', from = '2015-01-01', env = data, auto.assign = T)    
## [1] "SPY"
head(data$SPY)
##            SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
## 2015-01-02   206.38   206.88  204.18    205.43  121465900     197.0452
## 2015-01-05   204.17   204.37  201.35    201.72  169632600     193.4866
## 2015-01-06   202.09   202.72  198.86    199.82  209151400     191.6642
## 2015-01-07   201.42   202.72  200.88    202.31  125346700     194.0525
## 2015-01-08   204.01   206.16  203.99    205.90  147217800     197.4960
## 2015-01-09   206.40   206.42  203.51    204.25  158567300     195.9134

The MACD Application Generates Buy Signals on Historical Data

When the MACD crosses the signal line, a change in direction and strength of the price of the underlying equity has taken place.

The simplest trading rule for MACD is to buy when the MACD line (the thin line) crosses above the Signal Line (the thick line), and to sell when the MACD line crosses below the Signal Line. The chart of coffee on the left highlights these very basic buy-and-sell signals. The chart on the right was produced by the MACD app, indicating the Buy signals for gold.

Slow

The MACD Application Allows the User to Tailor the MACD Calculations

Use the dropdown box to select an equity and and adjust the sliders to change the length of the moving averages. The black dots in the images indicate the "BUY" signals generated by the MACD crossover points

SlowFast

Slow MACD. Fast MACD.

Using the app, the user can select from several different equities, adjust the length of the EMA's, and use the resulting "buy" signals as consideration in making a trading decision.