title: How to use R packages MACD functions?
body: <p>I am learning to use R. I have an interest in pulling stock data and calculating various technical indicators on the stock data. My test benchmark is Google Finance. That is, I check my results with GF's results.</p>
  
  <p>While trying to implement some sort of MACD analysis, I have noticed a couple of things. These are probably my misinterpretation of the documentation. I have tried many variations and I cannot get agreement with Google Finance's numbers in some cases.</p>
  
  <p><code>library(quantmod)</code> gives me <code>MACD()</code>, which returns columns <code>macd</code> and <code>signal</code>.</p>
  
  <p><code>library(fTrading)</code> gives me <code>cdsTA()</code> and <code>cdoTA()</code>, which return <code>cdsTA</code> and <code>cdoTA</code> respectively.</p>
  
  <p>My test stock is IBM, and hopefully this link will pull up a chart with prices, volume, slow stochastics and MACD with histogram.</p>
  
  <p><a href="http://www.google.com//finance?chdnp=1&amp;chdd=1&amp;chds=1&amp;chdv=1&amp;chvs=Linear&amp;chdeh=0&amp;chfdeh=0&amp;chdet=1298224745682&amp;chddm=46920&amp;chddi=86400&amp;chls=CandleStick&amp;q=NYSE:IBM&amp;ntsp=0" rel="nofollow">http://www.google.com//finance?chdnp=1&amp;chdd=1&amp;chds=1&amp;chdv=1&amp;chvs=Linear&amp;chdeh=0&amp;chfdeh=0&amp;chdet=1298224745682&amp;chddm=46920&amp;chddi=86400&amp;chls=CandleStick&amp;q=NYSE:IBM&amp;ntsp=0</a></p>
  
  <p>Loading up IBM's price data into R and generating the values of the 3 functions above for the values 8, 17, 9 and for <code>MACD()</code> I set <code>percent=FALSE</code> gives me the following output.</p>
  
  <pre><code>MACD(close, 8, 17, 9, maType="EMA", percent=FALSE)
  cdsTA(close, lag1 = 8, lag2 = 17, lag3 = 9)
  cdoTA(close, lag1 = 8, lag2 = 17, lag3 = 9)
  
        date     close     macd   signal      cdsTA      cdoTA
  2011-02-07    164.17 3.187365 3.208984   3.208984 -0.7673435
  2011-02-08    166.05 3.246812 3.216549   3.216549 -0.7996041
  2011-02-09    164.65 3.052187 3.183677   3.183677 -1.0496306
  2011-02-10    164.09 2.780047 3.102951   3.102951 -1.3332292
  2011-02-11    163.85 2.496591 2.981679   2.981679 -1.5867962
  2011-02-14    163.22 2.168977 2.819138   2.819138 -1.8408138
  2011-02-15    162.84 1.846701 2.624651   2.624651 -2.0507546
  2011-02-16    163.40 1.640518 2.427824   2.427824 -2.1262626
  2011-02-17    164.24 1.550798 2.252419   2.252419 -2.0854783
  2011-02-18    164.84 1.517145 2.105364   2.105364 -1.9968608
  </code></pre>
  
  <p>If you refer to the google finance chart above, the columns cdsTA and macd are identical and agree closely with Google's EMA figures. <code>MACD()</code>'s value for macd al also pretty close to GF's. And so I get</p>
  
  <p>macd - signal = divergence.</p>
  
  <p>However, cdoTA is way off. What am I doing wrong?</p>