[R-SIG-Finance] addATR() and addTA(ATR()) generate different plots

Joshua Ulrich josh.m.ulrich at gmail.com
Thu Nov 28 16:38:00 CET 2013


On Thu, Nov 28, 2013 at 9:33 AM,  <manojit_roy at comcast.net> wrote:
> I get different plots for ATR() when adding this indicator to my chart in two different ways (see last 2 lines of the code below):
>
>> require(quantmod)
>> getSymbols('GTAT')
>> ticker <- last(GTAT,'5 years')
>> barChart(ticker,TA=NULL,theme='white',major.ticks='months',minor.ticks=FALSE,show.grid=FALSE)
>> plot(addATR(n=20))
>> plot(addTA(ATR(ticker,n=20)$atr,col='blue',lwd=2))
>
> Can someone help me understand what I am doing wrong, and which ATR values I should use?
>
ATR requires a HLC object.  You're passing an OHLCV object to it.  Try:
plot(addTA(ATR(HLC(ticker),n=20)$atr,col='blue',lwd=2))

TTR can't use the HLC function because HLC is in quantmod and quantmod
depends on TTR.  So, for the time being, you have to be thoughtful
about the columns in the object you pass to TTR functions.

Best,
--
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com



More information about the R-SIG-Finance mailing list