A Stochastic-MACD Model for Trading Nifty Stocks

Glenda Dowie has an interesting post up on investopedia:

Looking for two popular indicators that work well together resulted in this pairing of the stochastic oscillator and the moving average convergence divergence (MACD). This team works because the stochastic is comparing a stock’s closing price to its price range over a certain period of time, while the MACD is the formation of two moving averages diverging from and converging with each other. This dynamic combination is highly effective if used to its fullest potential.

To derive a buy signal out of these two indicators, first make sure that the MACD is trading over its signal line and then make sure that the %K crossed the %D in the last couple of days.

The problem with any multi-signal approach is that it requires you to track multiple stocks:

Because the stock generally takes a longer time to line up in the best buying position, the actual trading of the stock occurs less frequently, so you may need a larger basket of stocks to watch.

This is where you can use the StockViz API to make life simpler.

The StockViz Technical API for Equities (doc) gives you more that 50 technical stats to play with. The stochastic fields are “STOCH_FAST_D” and “STOCH_FAST_K” and the MACD fields are “MACD” and “MACD_SIGNAL.”

Here’s how it works.

Pseudocode

In order to scan all the Nifty 50 stocks:

  1. grab all the constituents of the index through the SymbolsOfIndex endpoint
  2. iterate through them and get the technicals
  3. check if the MACD is over the signal line. If it is, then check if the stochastic cross-over occurred over the last couple of days
  4. If both the conditions are met, then place the trade

Code

You can find the code on GitHub. We have extracted some shared code out into a “common” module. The main file reads much cleaner this way.

The code should be run at the beginning of the day and you can track the progress of this system through your StockViz account.

Stocks picked up today

stochastic-macd portfolio 20.02.2014

Note: You have to link your Mashape and StockViz accounts for the Accounts API to work (doc.)

Previously

 

Comments are closed, but trackbacks and pingbacks are open.